grafthistory: support curl
[elinks/elinks-j605.git] / src / util / file.h
blobc28218aed7da8386b34e1f002823251444f8f0cd
2 #ifndef EL__UTIL_FILE_H
3 #define EL__UTIL_FILE_H
5 #include <stdio.h>
7 struct directory_entry {
8 /* The various attribute info collected with the stat_* functions. */
9 unsigned char *attrib;
11 /* The full path of the dir entry. */
12 unsigned char *name;
15 /* First information such as permissions is gathered for each directory entry.
16 * All entries are then sorted. */
17 struct directory_entry *
18 get_directory_entries(unsigned char *dirname, int get_hidden_files);
20 int file_exists(const unsigned char *filename);
21 int file_can_read(const unsigned char *filename);
22 int file_is_dir(const unsigned char *filename);
24 /* Strips all directory stuff from @filename and returns the
25 * position of where the actual filename starts */
26 unsigned char *get_filename_position(unsigned char *filename);
28 /* Tilde is only expanded for the current users homedir (~/). */
29 /* The returned file name is allocated. */
30 unsigned char *expand_tilde(unsigned char *filename);
32 /* Generate a unique file name by trial and error based on the @fileprefix by
33 * adding suffix counter (e.g. '.42'). */
34 /* The returned file name is allocated if @fileprefix is not unique. */
35 unsigned char *get_unique_name(unsigned char *fileprefix);
37 /* Checks various environment variables to get the name of the temp dir.
38 * Returns a filename by concatenating "<tmpdir>/<name>". */
39 unsigned char *get_tempdir_filename(unsigned char *name);
41 /* Read a line from @file into the dynamically allocated @line, increasing
42 * @line if necessary. Ending whitespace is trimmed. If a line ends
43 * with "\" the next line is read too. */
44 /* If @line is NULL the returned line is allocated and if file reading fails
45 * @line is free()d. */
46 unsigned char *file_read_line(unsigned char *line, size_t *linesize,
47 FILE *file, int *linenumber);
49 /* Safe wrapper for mkstemp().
50 * It enforces permissions by calling umask(0177), call mkstemp(), then
51 * restore previous umask(). */
52 int safe_mkstemp(unsigned char *template);
54 #endif