|
myMPD
Internal API documentation
|
File handling. More...
#include "compile_time.h"#include "src/lib/filehandler.h"#include "src/lib/log.h"#include "src/lib/sds_extras.h"#include <dirent.h>#include <errno.h>#include <fcntl.h>#include <pwd.h>#include <stdlib.h>#include <sys/stat.h>#include <time.h>#include <unistd.h>#include <utime.h>
Functions | |
| bool | update_mtime (const char *filename) |
| time_t | get_mtime (const char *filepath) |
| sds | sds_getline (sds s, FILE *fp, size_t max, int *nread) |
| sds | sds_getfile (sds s, const char *file_path, size_t max, bool remove_newline, bool warn, int *nread) |
| sds | sds_getfile_from_fp (sds s, FILE *fp, size_t max, bool remove_newline, int *nread) |
| bool | testfile_read (const char *filename) |
| int | testdir (const char *desc, const char *dir_name, bool create, bool silent) |
| bool | is_dir (const char *dir_name) |
| bool | create_tmp_file (const char *filepath) |
| FILE * | open_tmp_file (sds filepath) |
| bool | rename_tmp_file (FILE *fp, sds tmp_file, bool write_rc) |
| bool | rename_file (const char *src, const char *dst) |
| bool | rm_file (const char *filepath) |
| int | try_rm_file (const char *filepath) |
| bool | write_data_to_file (const char *filepath, const char *data, size_t data_len) |
| bool | clean_directory (const char *dir_name) |
| bool | rm_directory (const char *dir_name) |
| bool | clean_rm_directory (const char *dir_name) |
File handling.
| bool clean_directory | ( | const char * | dir_name | ) |
Removes all regular files from a directory
| dir_name | directory to cleanup |
| bool clean_rm_directory | ( | const char * | dir_name | ) |
Shortcut for clean_directory and rm_directory
| dir_name | directory to cleanup and remove |
| bool create_tmp_file | ( | const char * | filepath | ) |
Creates a file in specified path if it does not exists.
| filepath | filepath to create |
| time_t get_mtime | ( | const char * | filepath | ) |
Returns the modification time of a file
| filepath | filepath |
| bool is_dir | ( | const char * | dir_name | ) |
Checks if dir_name is really a directory entry
| dir_name | directory path to check |
| FILE * open_tmp_file | ( | sds | filepath | ) |
Opens a temporary file for write using mkstemp
| filepath | filepath to open, e.g. /tmp/test.XXXXXX XXXXXX is replaced with a random string |
| bool rename_file | ( | const char * | src, |
| const char * | dst | ||
| ) |
Renames a file. src and dst must be in the same filesystem.
| src | source filename |
| dst | destination filename |
| bool rename_tmp_file | ( | FILE * | fp, |
| sds | tmp_file, | ||
| bool | write_rc | ||
| ) |
Closes the tmp file and moves it to its destination name This is done by removing the last 7 characters from the tmp_file. See open_tmp_file for corresponding open function.
| fp | FILE pointer |
| tmp_file | tmp file to close and move |
| write_rc | if false tmp file will be removed |
| bool rm_directory | ( | const char * | dir_name | ) |
Removes a directory and reports errors
| dir_name | directory to remove |
| bool rm_file | ( | const char * | filepath | ) |
Removes a file and reports all errors
| filepath | filepath to remove |
| sds sds_getfile | ( | sds | s, |
| const char * | file_path, | ||
| size_t | max, | ||
| bool | remove_newline, | ||
| bool | warn, | ||
| int * | nread | ||
| ) |
Reads a whole file in the sds string s from *fp Removes whitespace characters from start and end
| s | an already allocated sds string that should hold the file content |
| file_path | filename to read |
| max | maximum bytes to read |
| remove_newline | removes CR/LF if true |
| warn | log an error if file does not exist |
| nread | Number of bytes read, -1 error reading file, -2 file is too big |
| sds sds_getfile_from_fp | ( | sds | s, |
| FILE * | fp, | ||
| size_t | max, | ||
| bool | remove_newline, | ||
| int * | nread | ||
| ) |
Reads a whole file in the sds string s from *fp Removes whitespace characters from start and end
| s | an already allocated sds string that should hold the file content |
| fp | FILE pointer to read |
| max | maximum bytes to read |
| remove_newline | removes CR/LF if true |
| nread | Number of bytes read, -2 if file is too big |
| sds sds_getline | ( | sds | s, |
| FILE * | fp, | ||
| size_t | max, | ||
| int * | nread | ||
| ) |
Getline function that trims whitespace characters
| s | an already allocated sds string |
| fp | a file descriptor to read from |
| max | max line length to read |
| nread | Number of bytes read, -1 on EOF |
| int testdir | ( | const char * | desc, |
| const char * | dir_name, | ||
| bool | create, | ||
| bool | silent | ||
| ) |
Checks if dir exists
| desc | descriptive name |
| dir_name | directory path to check |
| create | true creates the directory |
| silent | true to report only errors |
| bool testfile_read | ( | const char * | filename | ) |
Checks if a filename can be opened read-only
| filename | filename to check |
| int try_rm_file | ( | const char * | filepath | ) |
Removes a file and ignores none existing error
| filepath | filepath to remove |
| bool update_mtime | ( | const char * | filename | ) |
Updates the timestamp of a file
| filename | file to update the timestamp |
| bool write_data_to_file | ( | const char * | filepath, |
| const char * | data, | ||
| size_t | data_len | ||
| ) |
Writes data to a file
| filepath | filepath to write to |
| data | data to write |
| data_len | data length to write |