struct directory_entry: Document the charset and mem_free.
[elinks.git] / src / util / file.h
blob32121337f4174dacb91f687d64cc0515ee4cf59f
2 #ifndef EL__UTIL_FILE_H
3 #define EL__UTIL_FILE_H
5 #include <stdio.h>
7 struct directory_entry {
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. */
11 /* The various attribute info collected with the stat_* functions. */
12 unsigned char *attrib;
14 /* The full path of the dir entry. */
15 unsigned char *name;
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 @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 /* Generate a unique file name by trial and error based on the @fileprefix by
36 * adding suffix counter (e.g. '.42'). */
37 /* The returned file name is allocated if @fileprefix is not unique. */
38 unsigned char *get_unique_name(unsigned char *fileprefix);
40 /* Checks various environment variables to get the name of the temp dir.
41 * Returns a filename by concatenating "<tmpdir>/<name>". */
42 unsigned char *get_tempdir_filename(unsigned char *name);
44 /* Read a line from @file into the dynamically allocated @line, increasing
45 * @line if necessary. Ending whitespace is trimmed. If a line ends
46 * with "\" the next line is read too. */
47 /* If @line is NULL the returned line is allocated and if file reading fails
48 * @line is free()d. */
49 unsigned char *file_read_line(unsigned char *line, size_t *linesize,
50 FILE *file, int *linenumber);
52 /* Safe wrapper for mkstemp().
53 * It enforces permissions by calling umask(0177), call mkstemp(), then
54 * restore previous umask(). */
55 int safe_mkstemp(unsigned char *template);
57 /* Recursively create directories in a path. The last element in the path is
58 * taken to be a filename, and simply ignored */
59 int mkalldirs(const unsigned char *path);
61 #endif