|
| int | tor_open_cloexec (const char *path, int flags, unsigned mode) |
| |
| FILE * | tor_fopen_cloexec (const char *path, const char *mode) |
| |
| int | tor_rename (const char *path_old, const char *path_new) |
| |
| int | replace_file (const char *from, const char *to) |
| |
| int | touch_file (const char *fname) |
| |
| int | tor_unlink (const char *pathname) |
| |
| file_status_t | file_status (const char *filename) |
| |
| bool | is_file (file_status_t file_type) |
| |
| bool | is_dir (file_status_t file_type) |
| |
| int64_t | tor_get_avail_disk_space (const char *path) |
| |
| ssize_t | write_all_to_fd (int fd, const char *buf, size_t count) |
| |
| ssize_t | read_all_from_fd (int fd, char *buf, size_t count) |
| |
| int | start_writing_to_file (const char *fname, int open_flags, int mode, open_file_t **data_out) |
| |
| FILE * | start_writing_to_stdio_file (const char *fname, int open_flags, int mode, open_file_t **data_out) |
| |
| FILE * | fdopen_file (open_file_t *file_data) |
| |
| int | finish_writing_to_file (open_file_t *file_data) |
| |
| int | abort_writing_to_file (open_file_t *file_data) |
| |
| int | write_str_to_file (const char *fname, const char *str, int bin) |
| |
| int | write_bytes_to_file (const char *fname, const char *str, size_t len, int bin) |
| |
|
int | write_chunks_to_file (const char *fname, const struct smartlist_t *chunks, int bin, int no_tempfile) |
| |
| int | append_bytes_to_file (const char *fname, const char *str, size_t len, int bin) |
| |
| int | write_bytes_to_new_file (const char *fname, const char *str, size_t len, int bin) |
| |
| int | write_str_to_file_if_not_equal (const char *fname, const char *str) |
| |
|
| MOCK_DECL_ATTR (char *, read_file_to_str,(const char *filename, int flags, struct stat *stat_out), ATTR_MALLOC) |
| |
| char * | read_file_to_str_until_eof (int fd, size_t max_bytes_to_read, size_t *sz_out) ATTR_MALLOC |
| |
| ssize_t | compat_getdelim_ (char **lineptr, size_t *n, int delim, FILE *stream) |
| |
Wrappers for reading and writing data to files on disk.
Header for files.c.
Definition in file files.h.
Return: FN_ERROR if filename can't be read, is NULL, or is zero-length, FN_NOENT if it doesn't exist, FN_FILE if it is a non-empty regular file, or a FIFO on unix-like systems, FN_EMPTY for zero-byte regular files, FN_DIR if it's a directory, and FN_ERROR for any other file type. On FN_ERROR and FN_NOENT, sets errno. (errno is not set when FN_ERROR is returned due to an unhandled file type.)
Definition at line 213 of file files.c.
| int start_writing_to_file |
( |
const char * |
fname, |
|
|
int |
open_flags, |
|
|
int |
mode, |
|
|
open_file_t ** |
data_out |
|
) |
| |
Try to start writing to the file in fname, passing the flags open_flags to the open() syscall, creating the file (if needed) with access value mode. If the O_APPEND flag is set, we append to the original file. Otherwise, we open a new temporary file in the same directory, and either replace the original or remove the temporary file when we're done.
Return the fd for the newly opened file, and store working data in *data_out. The caller should not close the fd manually: instead, call finish_writing_to_file() or abort_writing_to_file(). Returns -1 on failure.
NOTE: When not appending, the flags O_CREAT and O_TRUNC are treated as true and the flag O_EXCL is treated as false.
NOTE: Ordinarily, O_APPEND means "seek to the end of the file before each
write()". We don't do that.
Definition at line 318 of file files.c.
| int write_str_to_file |
( |
const char * |
fname, |
|
|
const char * |
str, |
|
|
int |
bin |
|
) |
| |
Create a file named fname with the contents str. Overwrite the previous fname if possible. Return 0 on success, -1 on failure.
This function replaces the old file atomically, if possible. This function, and all other functions in util.c that create files, create them with mode 0600.
Definition at line 275 of file files.c.