#ifndef _SK_UTIL_FS_H #define _SK_UTIL_FS_H #include #include #include #include #include #include #if HAVE_STDBOOL_H #include #endif /** * exists: * Check if a given pathname exists. * * @param pathname: the path to check * @return true if @pathname exists, false otherwise. */ #define exists(pathname) (0 == access(pathname, F_OK)) /** * is_dir: * Check if a given pathname is a directory. * * @param pathname: the path to check * @return true if @pathname exists and is a directory, false otherwise. */ bool is_dir(const char *restrict pathname); /** * myhome: * Returns a pointer to a string containing the current user’s home * directory. * The returned pointer points to a static location (don’t free() it) and * may be changed on future invocations. * * This function makes sure that the returned string is null-terminated and * truncates the result to fit within PATH_MAX if necessary. * * @returns home dir */ const char *myhome(); /** * creatfile: * create a file on the file system. * * @param path: pathname for the file to create * @param mode: desired file mode (cf. creat(3p)) * @return 0 on success, -1 otherwise (errno set) */ int creatfile(const char *path, mode_t mode); /** * mktempdir: * creates a temporary directory in a suitable location. * * @param dest: must be a pointer to a buffer of a least PATH_MAX+1 length. * @return dest if a directory was created successfully, NULL otherwise. */ char *mktempdir(char *dest); /** * rmtree: * delete a directory on the file system and all its descendants. * * @param dir: the path to the directory to delete. * @return 0 on success, -1 otherwise. */ int rmtree(const char *dir); #endif