2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifndef EL__UTIL_FILE_H
|
|
|
|
#define EL__UTIL_FILE_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Data read about an entry in a directory.
|
|
|
|
* The strings pointed to by this structure are in the system
|
|
|
|
* charset (i.e. LC_CTYPE) and must be freed with mem_free(). */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct directory_entry {
|
2007-07-27 05:35:13 -04:00
|
|
|
/** The various attribute info collected with the @c stat_* functions. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *attrib;
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** The full path of the dir entry. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *name;
|
|
|
|
};
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** First information such as permissions is gathered for each directory entry.
|
2005-09-15 09:58:31 -04:00
|
|
|
* All entries are then sorted. */
|
|
|
|
struct directory_entry *
|
|
|
|
get_directory_entries(unsigned char *dirname, int get_hidden_files);
|
|
|
|
|
|
|
|
int file_exists(const unsigned char *filename);
|
|
|
|
int file_can_read(const unsigned char *filename);
|
|
|
|
int file_is_dir(const unsigned char *filename);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Strips all directory stuff from @a filename and returns the
|
2005-09-15 09:58:31 -04:00
|
|
|
* position of where the actual filename starts */
|
|
|
|
unsigned char *get_filename_position(unsigned char *filename);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Tilde is only expanded for the current users homedir (~/).
|
|
|
|
* The returned file name is allocated. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *expand_tilde(unsigned char *filename);
|
|
|
|
|
2007-07-31 06:38:00 -04:00
|
|
|
/*! @brief Generate a unique file name by trial and error based on the
|
2007-07-27 05:35:13 -04:00
|
|
|
* @a fileprefix by adding suffix counter (e.g. '.42').
|
|
|
|
*
|
|
|
|
* The returned file name is allocated if @a fileprefix is not unique. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *get_unique_name(unsigned char *fileprefix);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Checks various environment variables to get the name of the temp dir.
|
2005-09-15 09:58:31 -04:00
|
|
|
* Returns a filename by concatenating "<tmpdir>/<name>". */
|
|
|
|
unsigned char *get_tempdir_filename(unsigned char *name);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Read a line from @a file into the dynamically allocated @a line,
|
|
|
|
* increasing @a line if necessary. Ending whitespace is trimmed.
|
|
|
|
* If a line ends with "\" the next line is read too.
|
|
|
|
* If @a line is NULL the returned line is allocated and if file
|
|
|
|
* reading fails @a line is free()d. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *file_read_line(unsigned char *line, size_t *linesize,
|
|
|
|
FILE *file, int *linenumber);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Safe wrapper for mkstemp().
|
2005-09-15 09:58:31 -04:00
|
|
|
* It enforces permissions by calling umask(0177), call mkstemp(), then
|
|
|
|
* restore previous umask(). */
|
|
|
|
int safe_mkstemp(unsigned char *template);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Recursively create directories in @a path. The last element in the path is
|
2006-01-05 04:49:05 -05:00
|
|
|
* taken to be a filename, and simply ignored */
|
2006-01-04 15:43:42 -05:00
|
|
|
int mkalldirs(const unsigned char *path);
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|