#include "myfs_tools.h" /* ---------------------------------------------------------------------------- */ char* myfs_dir_get_fuse_home_path() { struct passwd *pw = getpwuid(getuid()); char* result; if(pw == NULL) return NULL; result = (char*)malloc(sizeof(char)*(strlen(pw->pw_dir))+1+5); strcpy(result, pw->pw_dir); strcat(result, "/fuse"); return result; } /* ---------------------------------------------------------------------------- */ char* myfs_file_full_path(const char* fusepath) { char* dirname = myfs_dir_get_fuse_home_path(); char* fullpath = (char*)malloc(sizeof(char)*(strlen(dirname) + strlen(fusepath) + 1)); strcpy(fullpath, dirname); strcat(fullpath, fusepath); free(dirname); return fullpath; } /* ---------------------------------------------------------------------------- */ int myfs_file_exists(const char* fusepath) { char* fullpath = myfs_file_full_path(fusepath); int result = (access(fullpath, F_OK) != -1) ? 1 : 0; free(fullpath); return result; } /* ---------------------------------------------------------------------------- */ DIR* myfs_dir_open(char* dir_name) { return opendir(dir_name); } /* ---------------------------------------------------------------------------- */ struct dirent* myfs_dir_read(DIR* d) { return readdir(d); } /* ---------------------------------------------------------------------------- */ int myfs_dir_close(DIR* d) { return closedir(d) == 0; } /* ---------------------------------------------------------------------------- */