2 #ifndef EL__UTIL_FILE_H
3 #define EL__UTIL_FILE_H
7 /** Data read about an entry in a directory.
8 * The strings pointed to by this structure are in the system
9 * charset (i.e. LC_CTYPE) and must be freed with mem_free(). */
10 struct directory_entry
{
11 /** The various attribute info collected with the @c stat_* functions. */
12 unsigned char *attrib
;
14 /** The full path of the dir entry. */
18 /** First information such as permissions is gathered for each directory entry.
19 * All entries are then sorted. */
20 struct directory_entry
*
21 get_directory_entries(unsigned char *dirname
, int get_hidden_files
);
23 int file_exists(const unsigned char *filename
);
24 int file_can_read(const unsigned char *filename
);
25 int file_is_dir(const unsigned char *filename
);
27 /** Strips all directory stuff from @a filename and returns the
28 * position of where the actual filename starts */
29 unsigned char *get_filename_position(unsigned char *filename
);
31 /** Tilde is only expanded for the current users homedir (~/).
32 * The returned file name is allocated. */
33 unsigned char *expand_tilde(unsigned char *filename
);
35 /*! @brief Generate a unique file name by trial and error based on the
36 * @a fileprefix by adding suffix counter (e.g. '.42').
38 * The returned file name is allocated if @a fileprefix is not unique. */
39 unsigned char *get_unique_name(unsigned char *fileprefix
);
41 /** Checks various environment variables to get the name of the temp dir.
42 * Returns a filename by concatenating "<tmpdir>/<name>". */
43 unsigned char *get_tempdir_filename(unsigned char *name
);
45 /** Read a line from @a file into the dynamically allocated @a line,
46 * increasing @a line if necessary. Ending whitespace is trimmed.
47 * If a line ends with "\" the next line is read too.
48 * If @a line is NULL the returned line is allocated and if file
49 * reading fails @a line is free()d. */
50 unsigned char *file_read_line(unsigned char *line
, size_t *linesize
,
51 FILE *file
, int *linenumber
);
53 /** Safe wrapper for mkstemp().
54 * It enforces permissions by calling umask(0177), call mkstemp(), then
55 * restore previous umask(). */
56 int safe_mkstemp(unsigned char *template);
58 /** Recursively create directories in @a path. The last element in the path is
59 * taken to be a filename, and simply ignored */
60 int mkalldirs(const unsigned char *path
);