This is a wrapper for the POSIX file handling stuff. It mainly does some things for convenience and is not a real abstraction layer. More...
Functions | |
int | fu_check_path (const char *path) |
Check path. More... | |
int | fu_create_path (const char *path, posix_mode_t perm) |
Create path. More... | |
int | fu_check_file (const char *pathname, struct_posix_stat *state) |
Check whether file exist. More... | |
int | fu_open_file (const char *pathname, int *filedesc, int mode, posix_mode_t perm) |
Open file. More... | |
void | fu_close_file (int *filedesc, FILE **stream) |
Close file (and potentially associated I/O stream) More... | |
int | fu_lock_file (int filedesc) |
Lock file for writing. More... | |
int | fu_unlink_file (const char *pathname) |
Unlink file. More... | |
int | fu_assign_stream (int filedesc, FILE **stream, const char *mode) |
Assign I/O stream to open file. More... | |
int | fu_sync (int filedesc, FILE *stream) |
Flush buffers of file. More... | |
int | fu_read_whole_file (int filedesc, char **buffer, size_t *len) |
Read text file content and store it into memory buffer. More... | |
int | fu_read_from_filedesc (int filedesc, char *buffer, size_t *len) |
Read data block to filedescriptor. More... | |
int | fu_write_to_filedesc (int filedesc, const char *buffer, size_t len) |
Write data block to filedescriptor. More... | |
int | fu_delete_tree (const char *dir) |
Delete directory tree. More... | |
This is a wrapper for the POSIX file handling stuff. It mainly does some things for convenience and is not a real abstraction layer.
int fu_assign_stream | ( | int | filedesc, |
FILE ** | stream, | ||
const char * | mode | ||
) |
Assign I/O stream to open file.
[in] | filedesc | Filedescriptor to which the stream should be assigned |
[out] | stream | File stream that was assigned to file descriptor |
[in] | mode | Access mode of the new stream |
Definition at line 373 of file fileutils.c.
References PRINT_ERROR.
Referenced by core_save_to_file(), and log_open_logfile().
int fu_check_file | ( | const char * | pathname, |
struct_posix_stat * | state | ||
) |
Check whether file exist.
[in] | pathname | Pathname of file to open |
[out] | state | Pointer to status buffer |
This is a wrapper for the POSIX stat()
system call.
This function check for a file from pathname and try to get its status. If stat is NULL
the status is thrown away.
On success, status is written to location pointed to by stat
Definition at line 211 of file fileutils.c.
Referenced by core_check_file_exist(), core_get_signature(), ext_inews(), ext_pp_filter(), and secure_cl_secret().
int fu_check_path | ( | const char * | path | ) |
Check path.
[in] | path | String with path or pathname to verify |
Accept only characters from the POSIX portable filename character set and '/' for security reasons. Especially accept no space and '' in the path.
Definition at line 73 of file fileutils.c.
References PRINT_ERROR.
Referenced by core_get_homedir(), core_get_signature(), and xdg_get_confdir().
void fu_close_file | ( | int * | filedesc, |
FILE ** | stream | ||
) |
Close file (and potentially associated I/O stream)
[in] | filedesc | Pointer to filedescriptor of file to close |
[in] | stream | Pointer to stream associated with filedesc |
This function first close the stream pointed to by stream and then the filedescriptor pointed to by filedesc.
NULL
and are ignored in this case. If filedesc points to a location with value -1
it is ignored. If stream points to a location containing a NULL
pointer, it is ignored. Definition at line 290 of file fileutils.c.
Referenced by core_get_cancel_key(), core_get_signature(), core_save_to_file(), log_close_logfile(), log_open_logfile(), and secure_cl_secret().
int fu_create_path | ( | const char * | path, |
posix_mode_t | perm | ||
) |
Create path.
[in] | path | String with path to create |
[in] | perm | Permissions for directories to create |
NULL
and must be an absolute path.mkdir()
is called for every component of the path. If path does not end with a slash, the last component is not treated as a directory to create.
Definition at line 119 of file fileutils.c.
References PRINT_ERROR.
Referenced by core_get_cancel_key(), log_get_logpathname(), and xdg_get_confdir().
int fu_delete_tree | ( | const char * | dir | ) |
Delete directory tree.
[in] | dir | Pathname of toplevel directory (to delete with all content) |
The parameter dir must point to a string with the absolute path. A trailing slash is allowed and ignored.
Definition at line 578 of file fileutils.c.
References PRINT_ERROR.
int fu_lock_file | ( | int | filedesc | ) |
Lock file for writing.
[in] | filedesc | Descriptor of file to lock |
The file must be open for writing for this function to work.
Definition at line 328 of file fileutils.c.
References PRINT_ERROR.
int fu_open_file | ( | const char * | pathname, |
int * | filedesc, | ||
int | mode, | ||
posix_mode_t | perm | ||
) |
Open file.
[in] | pathname | Pathname of file to open |
[out] | filedesc | Pointer to file descriptor |
[in] | mode | Mode for file to open |
[in] | perm | Permissions for file to open (if it must be created) |
This is a wrapper for the POSIX open()
system call that automatically retry if the system call was interrupted by a signal.
This function opens a file from pathname with the mode mode . If a new file is created, the permissions from perm are used, otherwise perm is ignored.
Definition at line 243 of file fileutils.c.
References PRINT_ERROR.
Referenced by core_get_cancel_key(), core_get_signature(), core_save_to_file(), log_open_logfile(), and secure_cl_secret().
int fu_read_from_filedesc | ( | int | filedesc, |
char * | buffer, | ||
size_t * | len | ||
) |
Read data block to filedescriptor.
[in] | filedesc | Filedescriptor of file |
[out] | buffer | Pointer to data buffer |
[in,out] | len | Pointer to data length in octets |
The filedescriptor filedesc must be valid.
Definition at line 504 of file fileutils.c.
References PRINT_ERROR.
Referenced by core_get_cancel_key().
int fu_read_whole_file | ( | int | filedesc, |
char ** | buffer, | ||
size_t * | len | ||
) |
Read text file content and store it into memory buffer.
[in] | filedesc | Filedescriptor of file |
[out] | buffer | Pointer to data buffer |
[out] | len | Pointer to buffer size |
The filedescriptor filedesc must be valid. The data is terminated with a NUL
character, therefore the file must be a text file without NUL characters in the content.
On success that caller is responsible to free the allocated buffer.
Definition at line 445 of file fileutils.c.
Referenced by core_get_signature().
int fu_sync | ( | int | filedesc, |
FILE * | stream | ||
) |
Flush buffers of file.
[in] | filedesc | Filedescriptor of file |
[out] | stream | File stream assigned to file descriptor |
The filedescriptor filedesc must be valid, stream may be NULL if there is no stream assigned to the filedescriptor.
Definition at line 402 of file fileutils.c.
int fu_unlink_file | ( | const char * | pathname | ) |
Unlink file.
[in] | pathname | Pathname of file to unlink |
Definition at line 355 of file fileutils.c.
Referenced by core_tmpfile_delete(), log_delete_logfile(), and secure_cl_secret().
int fu_write_to_filedesc | ( | int | filedesc, |
const char * | buffer, | ||
size_t | len | ||
) |
Write data block to filedescriptor.
[in] | filedesc | Filedescriptor of file |
[in] | buffer | Pointer to data buffer |
[in] | len | Data length in octets |
The filedescriptor filedesc must be valid.
Definition at line 542 of file fileutils.c.
References PRINT_ERROR.
Referenced by secure_cl_secret().