#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); /** * which: * find an executable in a PATH. * * this function searches @search_path (or the "PATH" environment variable if * @search_path is NULL) for an executable with @name. * The full path of the resolved executable will be stored in @resolved_path. * If no match could be found, the content of @resolved_path will be the empty * string. * * @param name: name of the executable to search for. * @param resolved_path: a pointer to a buffer of at least PATH_MAX+1 length. * @param search_path: PATH to search in (defaults to the "PATH" env variable). */ void which( const char *restrict name, char *restrict resolved_path, const char *restrict search_path); #endif