ELinks 0.16.1.1
file.c File Reference

File utilities. More...

#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include "elinks.h"
#include "osdep/osdep.h"
#include "util/conv.h"
#include "util/error.h"
#include "util/file.h"
#include "util/memory.h"
Include dependency graph for file.c:

Functions

int file_exists (const char *filename)
int file_can_read (const char *filename)
int file_is_dir (const char *filename)
char * get_filename_position (char *filename)
 Strips all directory stuff from filename and returns the position of where the actual filename starts.
char * expand_tilde (const char *filename)
 Tilde is only expanded for the current users homedir (~/).
char * get_unique_name (char *fileprefix)
 Generate a unique file name by trial and error based on the fileprefix by adding suffix counter (e.g. '.42').
char * get_tempdir_filename (const char *name)
 Checks various environment variables to get the name of the temp dir.
char * file_read_line (char *line, size_t *size, FILE *file, int *lineno)
 Read a line from file into the dynamically allocated line, increasing line if necessary.
int safe_mkstemp (char *template_)
 Safe wrapper for mkstemp().
int compare_dir_entries (const void *v1, const void *v2)
static int file_visible (char *name, int get_hidden_files, int is_root_directory)
 This function decides whether a file should be shown in directory listing or not.
struct directory_entryget_directory_entries (char *dirname, int get_hidden)
 First information such as permissions is gathered for each directory entry.
int mkalldirs (const char *path)
 Recursively create directories in path.

Detailed Description

File utilities.

Function Documentation

◆ compare_dir_entries()

int compare_dir_entries ( const void * v1,
const void * v2 )

◆ expand_tilde()

char * expand_tilde ( const char * filename)

Tilde is only expanded for the current users homedir (~/).

The returned file name is allocated.

◆ file_can_read()

int file_can_read ( const char * filename)

◆ file_exists()

int file_exists ( const char * filename)

◆ file_is_dir()

int file_is_dir ( const char * filename)

◆ file_read_line()

char * file_read_line ( char * line,
size_t * linesize,
FILE * file,
int * linenumber )

Read a line from file into the dynamically allocated line, increasing line if necessary.

Ending whitespace is trimmed. If a line ends with "\" the next line is read too. If line is NULL the returned line is allocated and if file reading fails line is free()d.

◆ file_visible()

int file_visible ( char * name,
int get_hidden_files,
int is_root_directory )
inlinestatic

This function decides whether a file should be shown in directory listing or not.

Returns
according boolean value.

◆ get_directory_entries()

struct directory_entry * get_directory_entries ( char * dirname,
int get_hidden )

First information such as permissions is gathered for each directory entry.

All entries are then sorted.

◆ get_filename_position()

char * get_filename_position ( char * filename)

Strips all directory stuff from filename and returns the position of where the actual filename starts.

◆ get_tempdir_filename()

char * get_tempdir_filename ( const char * name)

Checks various environment variables to get the name of the temp dir.

Returns a filename by concatenating "<tmpdir>/<name>".

◆ get_unique_name()

char * get_unique_name ( char * fileprefix)

Generate a unique file name by trial and error based on the fileprefix by adding suffix counter (e.g. '.42').

The returned file name is allocated if fileprefix is not unique.

◆ mkalldirs()

int mkalldirs ( const char * path)

Recursively create directories in path.

The last element in the path is taken to be a filename, and simply ignored

◆ safe_mkstemp()

int safe_mkstemp ( char * template_)

Safe wrapper for mkstemp().

It enforces permissions by calling umask(0177), call mkstemp(), then restore previous umask().