PathType pathType(const UnicodeString& path) { struct _stat s; if (statPath(path, &s)) { return _S_ISREG(s.st_mode) ? PATHTYPE_FILE : (_S_ISDIR(s.st_mode) ? PATHTYPE_DIR : PATHTYPE_NONE); } else { return PATHTYPE_NONE; } }
bool dirExists(const UnicodeString& path) { struct _stat s; if (statPath(path, &s)) { return _S_ISDIR(s.st_mode); } else { return false; } }
Directory *open_dir(const char *dir_name) { struct stat status; if(_stat(dir_name, &status) == -1) return nullptr; if(_S_ISDIR(status.st_mode) == 0) { errno = ENOTDIR; return nullptr; } unique_ptr<Directory> dir(new Directory()); dir->file_spec = string(dir_name) + "\\*"; dir->handle = -1; if(!reinitialize_dir(dir.get())) return nullptr; return dir.release(); }
char *locate_data_file(const char *const name) { for(int i = 0; i < 256; i++) pathstring[i] = 0; if(name == 0) return 0; if(*name == '/') return strdup(name); // Guillaume Cottenceau (2001-03-15) replace "return 0;" by "strdup(name);" // En effet, nous sommes dans le cas ou le programme recherche dans /usr/share/games/powermanga for(const char **p = data_directories;; p++) { char *pathname; if(*p == 0) { const char *subdir = "/share/games/powermanga/"; pathname = &pathstring[0]; /*pathname=(char *)malloc(strlen(nomprefix) + strlen(subdir) + strlen(name) + 1); if(pathname == 0) { fflush(stdout); fprintf(stderr, "powermanga: not enough memory\n"); return 0; }*/ strcpy(pathname, nomprefix); strcat(pathname, subdir); strcat(pathname, name); } else if(**p == '~') // Not used anymore { static const char bogus = '\0'; static const char *home_dir = &bogus; if(home_dir == &bogus) home_dir = getenv("HOME"); if(home_dir == 0) continue; // $HOME not set. Skip this directory. pathname = &pathstring[0]; /*pathname = (char *)malloc(strlen(home_dir) + 1 + strlen(*p + 1) + 1 + strlen(name) + 1); if(pathname == 0) { fflush(stdout); fprintf(stderr, "powermanga: not enough memory\n"); return 0; }*/ strcpy(pathname, home_dir); strcat(pathname, *p + 1); strcat(pathname, "/"); strcat(pathname, name); } else { pathname = &pathstring[0]; /*pathname = (char *)malloc(strlen(*p) + 1 + strlen(name) + 1); if(pathname == 0) { fflush(stdout); fprintf(stderr, "powermanga: not enough memory\n"); return 0; }*/ strcpy(pathname, *p); strcat(pathname, "/"); strcat(pathname, name); } //puts(pathname); // DEBUG #ifdef WIN32 struct _stat s; if(_stat(pathname, &s) == 0 && !_S_ISDIR(s.st_mode)) return pathname; #else struct stat s; if(stat(pathname, &s) == 0 && !S_ISDIR(s.st_mode)) return pathname; #endif //free(pathname); if(*p == 0) break; } return 0; // Not found. }