Line data Source code
1 : #ifndef HEADER_fd_src_app_shared_fd_file_util_h 2 : #define HEADER_fd_src_app_shared_fd_file_util_h 3 : 4 : #include "../../util/fd_util.h" 5 : 6 : /* Read a uint from the provided file path. On success, returns zero 7 : and writes the value to the provided pointer. On failure, -1 is 8 : returned and errno is set appropriately. 9 : 10 : If the file does not start with a single line, with a uint followed 11 : by EOF or a newline character, it is an error and the errno will 12 : be ERANGE. */ 13 : 14 : int 15 : fd_file_util_read_ulong( char const * path, 16 : ulong * value ); 17 : 18 : int 19 : fd_file_util_read_uint( char const * path, 20 : uint * value ); 21 : 22 : /* Write a uint to the provided file path. On success, returns zero. 23 : On failure, -1 is returned and errno is set appropriately. */ 24 : 25 : int 26 : fd_file_util_write_ulong( char const * path, 27 : ulong value ); 28 : 29 : static inline int 30 : fd_file_util_write_uint( char const * path, 31 0 : uint value ) { 32 0 : return fd_file_util_write_ulong( path, value ); 33 0 : } 34 : 35 : /* fd_file_util_mkdir_all() recursively creates directories such that 36 : the full path provided can exist. Directories that already exist are 37 : left as they are, and new directories that are created will be owned 38 : by the given uid and gid and have mode 0700 (rwx for the owner only). 39 : 40 : On success, returns zero. On failure, returns -1 and errno is set 41 : appropriately. Reasons for failure include all of the reasons from 42 : mkdir(2), chown(2) and chmod(2). 43 : 44 : On failure, it is possible for a partial directory structure to have 45 : been created, and this will not be cleaned up. A directory might 46 : have been created, but failed to be chown() or chmod() in which case 47 : it will be left with a different owner. */ 48 : 49 : int 50 : fd_file_util_mkdir_all( const char * path, 51 : uint uid, 52 : uint gid ); 53 : 54 : /* fd_file_util_rmtree() recursively removes all the contents of a 55 : directory, and then (if remove_root is non-zero) also removes the 56 : directory itself. If remove_root is zero, the directory is left 57 : empty but not removed. 58 : 59 : On success, returns zero. On failure, returns -1 and errno is set 60 : appropriately. 61 : 62 : On failure, the directory may be in any state, with some files and 63 : directories being deleted, and some not. */ 64 : 65 : int 66 : fd_file_util_rmtree( char const * path, 67 : int remove_root ); 68 : 69 : /* fd_file_util_self_exe() retrieves the full path of the current 70 : executable into the path provided. Path should be a buffer with at 71 : least PATH_MAX elements. 72 : 73 : On success, the path is written to the provided buffer and zero is 74 : returned. On failure, -1 is returned and errno is set appropriately. */ 75 : 76 : int 77 : fd_file_util_self_exe( char path[ PATH_MAX ] ); 78 : 79 : #endif /* HEADER_fd_src_app_shared_fd_file_util_h */