bool makeDir(char* dirName) { if (dirExists(dirName)) { return true; } mkdir(dirName,0777); return dirExists(dirName); }
void screenshot(s_screen *vscreen, unsigned char *pal, int ingame) { #ifndef DC int shotnum = 0; char shotname[128] = {""}; char modname[128] = {""}; getPakName(modname, 99); #ifdef PSP if(dirExists("ms0:/PICTURE/", 1) && dirExists("ms0:/PICTURE/Beats Of Rage/", 1)) { #endif do { #if PSP sprintf(shotname, "ms0:/PICTURE/Beats Of Rage/%s - ScreenShot - %02u.png", modname, shotnum); #elif DOS sprintf(shotname, "./SShots/s%04u.png", shotnum); #elif XBOX sprintf(shotname, "d:\\ScreenShots\\%s - %04u.png", modname, shotnum); #elif SDL || WII sprintf(shotname, "%s/%s - %04u.png", screenShotsDir, modname, shotnum); #else sprintf(shotname, "./ScreenShots/%s - %04u.png", modname, shotnum); #endif ++shotnum; } while(fileExists(shotname) && shotnum < 10000); #ifdef PSP if(shotnum < 10000) { saveImage(shotname); } #else if(shotnum < 10000) { savepng(shotname, vscreen, pal); } #endif if(ingame) { debug_printf("Saved %s", shotname); } #ifdef PSP } #endif #endif }
bool win::createDirectory(char *path) { path=strdup(path); if(text::indexOf(path,"/")!=pos_notFound) path=text::replace(path,"/","\\"); std::vector<char*> parts=text::split(path,"\\"); fs_t bufferSize=strlen(path)+1; fs_t pos=0; char *temp=(char*)calloc(bufferSize,1); for(uint32_t i=0;i<parts.size()-1;i++) { char *part=parts.at(i); char *append=text::concat(i>0?"\\":"",part); io::writeRawDataToBuffer(temp,append,strlen(append),pos,bufferSize); if(!dirExists(temp)) createDirectory(temp); free(append); free(part); } free(temp); wchar_t *longPath=getLongString(path); bool result=CreateDirectory(longPath,NULL); free(path); free(longPath); return result; }
int main(int argc, char *argv[]) { initialize(argc, argv); installSignalHandlers(); maybeDaemonize(); maybeWritePidfile(); while (1) { if (dirExists(dir)) { touchDir(dir); if (!doSleep(1800)) { break; } } else { break; } } maybeDeletePidFile(); if (shouldCleanup) { performCleanup(dir); } return 0; }
/* * Creates a directory. We can ignore mode since we're not dealing with * permissions, as long as getattr returns appropriate ones for us. */ static int cs1550_mkdir(const char *path, mode_t mode) { (void) mode; char dir[MAX_FILENAME + 1]; char fileName[MAX_FILENAME + 1]; char ext[MAX_EXTENSION + 1]; getPath(path, dir, fileName, ext); int pathType = getPathType(path, dir, fileName, ext); if (strlen(dir) >= MAX_FILENAME) { return -ENAMETOOLONG; } else if (dirExists(dir) == 1){ return -EEXIST; } else if (pathType != 1){ return -EPERM; } else { cs1550_root_directory r; getRoot(&r); if (r.nDirectories < MAX_DIRS_IN_ROOT) { createDir(dir); } } return 0; }
int tempDirToucherMain(int argc, char *argv[]) { initialize(argc, argv, 2); installSignalHandlers(); maybeDaemonize(); maybeWritePidfile(); while (1) { if (dirExists(dir)) { DEBUG("Touching directory"); touchDir(dir); if (!doSleep(sleepInterval)) { break; } } else { DEBUG("Directory no longer exists, exiting"); break; } } maybeDeletePidFile(); if (shouldCleanup) { DEBUG("Cleaning up directory"); performCleanup(dir); } return 0; }
// Windows paths void setPaths() { // handle Windows-specific path options if (getenv("APPDATA") != NULL) { PATH_CONF = PATH_USER = (std::string)getenv("APPDATA") + "\\flare"; createDir(PATH_CONF); createDir(PATH_USER); PATH_CONF += "\\config"; PATH_USER += "\\userdata"; createDir(PATH_CONF); createDir(PATH_USER); } else { PATH_CONF = "config"; PATH_USER = "******"; createDir(PATH_CONF); createDir(PATH_USER); } createDir(PATH_USER + "\\mods"); createDir(PATH_USER + "\\saves"); PATH_DATA = ""; if (dirExists(CUSTOM_PATH_DATA)) PATH_DATA = CUSTOM_PATH_DATA; else if (!CUSTOM_PATH_DATA.empty()) logError("Settings: Could not find specified game data directory."); PATH_CONF = PATH_CONF + "/"; PATH_USER = PATH_USER + "/"; }
static int dbRemoveColumn(tableInfo *tbl, char *columnName, response *res, error *err) { char *tableName = tbl->name; char currentPath[BUFSIZE]; columnPath(currentPath, tableName, columnName); if (!dirExists(currentPath)) { ERROR(err, E_NOCOL); goto exit; } if (removeDir(currentPath, err)) { goto exit; } printf("Removed column %s\n", columnName); RESPONSE_SUCCESS(res); return 0; exit: return 1; }
static int dbCreateTable(char *tableName, response *res, error *err) { char currentPath[BUFSIZE]; tablePath(currentPath, tableName); if (dirExists(currentPath)) { ERROR(err, E_DUPTBL); return 1; } // Create directory for new table if (mkdir(currentPath, S_IRWXU | S_IRWXG) == -1) { ERROR(err, E_MKDIR); return 1; } tablePathColumns(currentPath, tableName); // Create directory for new table's columns if (mkdir(currentPath, S_IRWXU | S_IRWXG) == -1) { ERROR(err, E_MKDIR); return 1; } tablePathHeader(currentPath, tableName); // Open the new table info file for writing FILE *fp = fopen(currentPath, "wb"); if (fp == NULL) { ERROR(err, E_FOP); return 1; } // Initialize new table info with proper values tableInfo tempTbl; tempTbl.isValid = 1; strcpy(tempTbl.name, tableName); tempTbl.numColumns = 0; // Write table info to beginning of file if (fwrite(&tempTbl, sizeof(tableInfo), 1, fp) <= 0) { ERROR(err, E_FWR); fclose(fp); return 1; } // Cleanup fclose(fp); printf("Created new table '%s'\n", tableName); RESPONSE_SUCCESS(res); return 0; }
void manejadorArchivos::checkingArch() { stringstream ss; ss << "\\bin\\examenes.edta"; if(!dirExists("bin\\")) { _mkdir("bin\\"); } if(!dirExists("bin\\examenes\\")) { _mkdir("bin\\examenes\\"); } if(!dirExists("bin\\Examenes Complejos")) { _mkdir("bin\\Examenes Complejos"); } }
int main(int argc, char ** argv) { /* OpenArchive roa; SetCallback rsc; ProcessFile rpf; CloseArchive rca;*/ std::vector<std::string> monitor_dirs; std::string extract_dir; std::vector<std::string> files_to_unpack; std::vector<std::string> dest_dirs; std::vector<std::string> passwords; bool recurseMonitor; if (parseOpts(argc, argv, files_to_unpack, dest_dirs, passwords, monitor_dirs, recurseMonitor, extract_dir)) { fprintf(stderr, "Usage: stream_unrar [%s <rar file> %s <dest_dir> [%s <password>]] [%s <monitor_dir> %s <extract_dir> [%s]]\n", add_flag.c_str(), dir_flag.c_str(), pass_flag.c_str(), monitor_flag.c_str(), extract_flag.c_str(), recurse_flag.c_str()); fprintf(stderr, "Multiple archives or monitor directories can be specified.\n"); fprintf(stderr, "Archives are processed first, then monitoring begins\n"); fprintf(stderr, "Monitoring is stopped when a file %s is created in one of the directories\n", abort_monitor.c_str()); return -1; } assert(files_to_unpack.size() == dest_dirs.size()); assert(files_to_unpack.size() == passwords.size()); for(std::vector<std::string>::iterator file = files_to_unpack.begin(), dir = dest_dirs.begin(), pass = passwords.begin(); // we're guaranteed that all 3 iterators are the same size by parseOpts file != files_to_unpack.end(); ++file, ++dir, ++pass) { extract(*file, *dir, *pass); } if (monitor_dirs.size() == 0) return 0; setPriority(low); fprintf(stdout, "Beginning to monitor watch directories\n"); bool stopMonitoring = false; bool valid_monitor_dir = true; while (!stopMonitoring && valid_monitor_dir) { valid_monitor_dir = false; for (std::vector<std::string>::iterator dir = monitor_dirs.begin(); dir != monitor_dirs.end(); ++ dir) { if (!dirExists(*dir)) continue; valid_monitor_dir = true; if (process(*dir, recurseMonitor, extract_dir)) return 0; } thread_sleep(1); } return -1; }
int CreateOutputDir() { string outdir, toutdir; int addnum = 0; char dateid[21]; char addnumstr[4]; outdir = "/media/doas/DATA/"; // lock mutex for gps variables pthread_mutex_lock(&gpslock); sprintf(dateid, "%04d-%02d-%02dT%02d-%02d-%02dZ", Year, Month, Day, Hour, Minute, int(round(Second))); // unlock mutex for gps variables pthread_mutex_unlock(&gpslock); outdir += dateid; //printf("dir to make: %s\n", outdir.c_str()); // check for unique file name, append addnum if already exists if (dirExists(outdir.c_str()) == 1) { while (1) { sprintf(addnumstr, "%04d", addnum); toutdir = outdir + addnumstr; if (dirExists(toutdir.c_str()) == 0) { outdir = toutdir; break; } addnum++; } } mkdir(outdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (dirExists(outdir.c_str())) printf("Successfully made output directory: %s\n", outdir.c_str()); else { printf("Error occured while making output directory!\n"); exit(1); } OutputDir = outdir + "/"; return 0; }
int man(int argc, char **argv, Target &target) { std::string SDKPath; if (!target.getSDKPath(SDKPath)) return 1; std::vector<std::string> manpaths; manpaths.push_back(SDKPath + "/usr/share/man"); manpaths.push_back(std::string(target.execpath) + "/../share/man"); unsetenv("MANPATH"); for (const std::string &manpath : manpaths) if (dirExists(manpath)) concatEnvVariable("MANPATH", manpath); if (!getenv("MANPATH")) { err << "cannot find man pages!" << err.endl(); return 1; } std::vector<char *> args; // All the const violation here doesn't matter, // the arguments won't be modified args.push_back(const_cast<char *>("man")); for (int i = 1; i < argc; ++i) { char *arg = argv[i]; // Rewrite gcc to <triple>-gcc for compatibility // with other man pages constexpr const char *GCCManPages[] = { "gcc", "g++", "cpp", "gcov" }; for (const char *mp : GCCManPages) { if (!strcmp(mp, arg)) { std::string *str = new std::string; // Intentionally "leaked" target.getDefaultTriple(*str); str->append("-"); str->append(arg); arg = const_cast<char *>(str->c_str()); break; } } args.push_back(arg); } args.push_back(nullptr); execvp(args[0], args.data()); err << "cannot execute '" << args[0] << "'" << err.endl(); return 1; }
// Android paths void setPaths() { PATH_CONF = std::string(SDL_AndroidGetInternalStoragePath()) + "/config"; PATH_USER = std::string(SDL_AndroidGetInternalStoragePath()) + "/userdata"; createDir(PATH_CONF); createDir(PATH_USER); createDir(PATH_USER + "/mods"); createDir(PATH_USER + "/saves"); std::string mods_folder = "data/org.flare.app/files"; if (SDL_AndroidGetExternalStorageState() != 0) { PATH_DATA = std::string(SDL_AndroidGetExternalStoragePath()); } else if (dirExists("/sdcard/Android")) { PATH_DATA = "/sdcard/Android/" + mods_folder; } else if (dirExists("/mnt/sdcard/Android")) { PATH_DATA = "/mnt/sdcard/Android/" + mods_folder; } else if (dirExists("storage/sdcard0/Android")) { PATH_DATA = "/storage/sdcard0/Android/" + mods_folder; } else if (dirExists("/storage/emulated/0/Android")) { PATH_DATA = "/storage/emulated/0/Android/" + mods_folder; } else if (dirExists("/storage/emulated/legacy/Android")) { PATH_DATA = "/storage/emulated/legacy/Android/" + mods_folder; } else { logError("Settings: Android external storage unavailable: %s", SDL_GetError()); } PATH_CONF = PATH_CONF + "/"; PATH_USER = PATH_USER + "/"; PATH_DATA = PATH_DATA + "/"; }
bool smartMakeDir(char* dirName) { char *tag; for(tag = dirName; *tag; tag++) { if (*tag == '\\') { char buf[1000], path[1000]; strcpy(buf, dirName); buf[strlen(dirName) - strlen(tag) + 1] = NULL; strcpy(path, buf); if (! dirExists(path)) { makeDir(path); } } } return dirExists(dirName); }
/* * Called whenever the contents of a directory are desired. Could be from an 'ls' * or could even be when a user hits TAB to do autocompletion */ static int cs1550_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { //Since we're building with -Wall (all warnings reported) we need //to "use" every parameter, so let's just cast them to void to //satisfy the compiler (void) offset; (void) fi; char dir[MAX_FILENAME + 1]; char fileName[MAX_FILENAME + 1]; char ext[MAX_EXTENSION + 1]; getPath(path, dir, fileName, ext); int pathType = getPathType(path, dir, fileName, ext); if (pathType == 0) { filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); cs1550_root_directory r; getRoot(&r); int i = 0; for(i = 0; i < r.nDirectories; i++) { filler(buf, r.directories[i].dname, NULL, 0); } } else if (pathType == 1) { int dir_exists = dirExists(dir); if ( dir_exists == 1) { filler(buf, ".", NULL,0); filler(buf, "..", NULL, 0); cs1550_directory_entry curDir; getDir(&curDir, dir); int i =0; for (i = 0; i < curDir.nFiles; i++) { if ((strcmp(curDir.files[i].fext, "\0") == 0)) { filler(buf, curDir.files[i].fname, NULL, 0); } else { char *fileNameExt = (char *) malloc(2 + MAX_FILENAME + MAX_EXTENSION); strcpy(fileNameExt, curDir.files[i].fname); strcat(fileNameExt, "."); strcat(fileNameExt, curDir.files[i].fext); filler(buf, fileNameExt, NULL, 0); } } } else { return -ENOENT; } } else { return -ENOENT; } return 0; }
bool FileCache::dirExists(const char *name, bool isRelative /* = true */) const { if (isRelative) { if (name && *name) { FileMap::const_iterator iter = m_files.find(name); if (iter != m_files.end() && iter->second.len == -2) { return true; } } return false; } return dirExists(GetRelativePath(name).c_str()); }
std::vector<std::string> Mhwd::checkEnvironment() const { std::vector<std::string> missingDirs; if (!dirExists(MHWD_USB_CONFIG_DIR)) { missingDirs.emplace_back(MHWD_USB_CONFIG_DIR); } if (!dirExists(MHWD_PCI_CONFIG_DIR)) { missingDirs.emplace_back(MHWD_PCI_CONFIG_DIR); } if (!dirExists(MHWD_USB_DATABASE_DIR)) { missingDirs.emplace_back(MHWD_USB_DATABASE_DIR); } if (!dirExists(MHWD_PCI_DATABASE_DIR)) { missingDirs.emplace_back(MHWD_PCI_DATABASE_DIR); } return missingDirs; }
bool validate() { if (!dirExists(configSchemaDir)) { std::cout << "Schema directory " << configSchemaDir << " does not exist" << std::endl; return false; } if (!dirExists(configSchemaPluginsDir)) { std::cout << "Schema plugins directory " << configSchemaPluginsDir << " does not exist" << std::endl; return false; } if (!fileExists(configSchemaDir + masterSchemaFile)) { std::cout << "The master config file " << masterSchemaFile << " does not exist" << std::endl; return false; } if (!fileExists(modTemplateFile)) { std::cout << "The modification template " << modTemplateFile << " does not exist" << std::endl; return false; } if (!envFile.empty()) { if (!fileExists(envFile)) { std::cout << "The environment file " << envFile << " does not exist" << std::endl; return false; } } return true; }
/* * Called whenever the system wants to know the file attributes, including * simply whether the file exists or not. * * man -s 2 stat will show the fields of a stat structure */ static int cs1550_getattr(const char *path, struct stat *stbuf) { memset(stbuf, 0, sizeof(struct stat)); char dir[MAX_FILENAME + 1]; char fileName[MAX_FILENAME + 1]; char ext[MAX_EXTENSION + 1]; getPath(path, dir, fileName, ext); int pathType = getPathType(path, dir, fileName, ext); if (pathType == 0) { //Root stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else if (pathType == 1) { //Directory if (dirExists(dir) == 1) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else { return -ENOENT; } } else if (pathType == 2 || pathType == 3) { //File int size = getFileSize(dir, fileName, ext, pathType); if (size != -1) { stbuf->st_mode = S_IFREG | 0666; stbuf->st_nlink = 1; //file links stbuf->st_size = (size_t)size; } else { return -ENOENT; } } else { return -ENOENT; } return 0; }
bool createDir(const char *dir) { bool success = false; #if defined(_WIN32) || defined(__WIN32__) success = _mkdir(dir) == 0; #else success = mkdir(dir, 0755) == 0; #endif if (!success && !dirExists(dir)) printf("Couldn't create the directory: %s\n", dir); return success; }
bool Path::remove( bool dirRecursive, QString * error ) { if( dirExists() ) { if( !dirRecursive ) { LOG_5( "Path::remove: Called with a directory: " + mPath + " with dirRecursive=false" ); return false; } return recursiveRemove( mPath, error ); } else if( fileExists() ) { bool res = QFile::remove( mPath ); if( !res && error ) *error = "QFile::remove failed to remove file: " + mPath; return res; } else LOG_5( "Path::remove: Couldn't find " + mPath + " to remove" ); return true; }
void Server::loadConfig() { if (!dirExists("Config")) { SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, false }; CreateDirectory("Config", &sa); } FILE * file; char configName[] = "Config\\Server Settings.ini"; //file = fopen(configName, "r"); fopen_s(&file, configName, "r"); if (file == NULL) { //fclose(file); return; } //no file found, just use defaults fclose(file); ifstream fileStream(configName); string s; string var, val; while (fileStream.peek() != -1) { s = var = val = ""; getline(fileStream, s); bool eq = false; int i = 0; while (i < (int)s.size()) { if (s[i] == '=') eq = true; else if (eq) val += s[i]; else var += s[i]; i++; } if (var == "tickRate") updateRate = atoi(val.c_str()); else if (var == "windowWidth") Settings::setWindowWidth(atoi(val.c_str())); else if (var == "windowHeight") Settings::setWindowHeight(atoi(val.c_str())); else if (var == "serverPortTCP") Settings::setPortTCP(atoi(val.c_str())); else if (var == "serverPortUDP") Settings::setPortUDP(atoi(val.c_str())); } fileStream.close(); }
const char* sutilSamplesDir(void) { const char* dir; static char s[512]; // Allow for overrides. dir = getenv( "OPTIX_SAMPLES_DIR" ); if( dir ) { strcpy( s, dir ); return s; } // Return hardcoded path if it exists. if( dirExists(SAMPLES_DIR) ) return SAMPLES_DIR; // Last resort. return "."; }
int fssConfigSmb::addDir(std::string newDir, bool ro=true) { int ret = 1; fssShareSmb* newShare = new fssShareSmb( newDir ); newShare->setReadOnly( ro ); if( ! dirExists( newDir ) ) { std::string cleanLabel = tidyLabel( newDir ); if( ! cleanLabel.empty() ) { newShare->setSmbLabel( cleanLabel ); shareList.push_back( newShare ); } else { ret = 0; } } else { ret = 0; } return ret; }
bool win::deleteDir(char *path) { if(!dirExists(path)) return false; wchar_t *longPath=getLongString(path); std::vector<char*> *files=listFilesOnly(path); std::vector<char*> *dirs=listDirsOnly(path); uint32_t fileCount=files->size(); uint32_t dirCount=dirs->size(); if(fileCount+dirCount==0) { bool result=RemoveDirectory(longPath); free(longPath); return result; } for(uint32_t i=0;i<fileCount;i++) { char *elementPath=text::concatPaths(path,files->at(i)); bool del=deleteFile(elementPath); free(elementPath); if(!del) { free(longPath); return false; } } for(uint32_t i=0;i<dirCount;i++) { char *elementPath=text::concatPaths(path,dirs->at(i)); bool del=deleteDir(elementPath); free(elementPath); if(!del) { free(longPath); return false; } } bool result=RemoveDirectory(longPath); free(longPath); return result; }
static int dbRemoveTable(char *tableName, response *res, error *err) { printf("Attempting to remove table '%s'\n", tableName); char pathToTableDir[BUFSIZE]; tablePath(pathToTableDir, tableName); // sprintf(pathToTableDir, "%s/%s/%s", DB_PTH, TBL_DIR, tableName); if (!dirExists(pathToTableDir)) { ERROR(err, E_NOTBL); return 1; } if (removeDir(pathToTableDir, err)) { return 1; } printf("Removed table %s\n", tableName); RESPONSE_SUCCESS(res); return 0; }
//gets the size of the file specificed, if it exists, if not returns -1 static int getFileSize(char *dir, char *fileName, char *ext, int path_type) { int ret = -1; if (dirExists(dir) == 0) { return -1; } else { cs1550_directory_entry parent_dir; getDir(&parent_dir, dir); int i; for (i = 0; i < parent_dir.nFiles; i++) { if (path_type == 2 && strcmp(fileName, parent_dir.files[i].fname) == 0) { ret = (int)parent_dir.files[i].fsize; } else if (path_type == 3 && strcmp(fileName, parent_dir.files[i].fname) == 0 && strcmp(ext, parent_dir.files[i].fext) == 0 ) { ret = (int)parent_dir.files[i].fsize; } } } return ret; }
/** * InitRelativePaths is a preparation step allowing files referred to relative to the executable to be referred to relative to the working dir AND the executable * * @param argc from main * @param argv from main * * @return NOTHING */ void InitRelativePaths( int argc, char** argv ) { char *binloc = argv[0]; std::vector< std::string > slapchop = split( std::string( binloc ), '/' ); //slapchop[0..length-2] == path without executable name if ( slapchop.size() > 1 ) { for (size_t last = slapchop.size() - 1; last > 0; last=last-1) { gprint( PRINT_DEBUG, "last = %lu\n", last); std::stringstream cat; for ( size_t i = 0; i < last; i++ ) cat << slapchop[i] << "/"; if (dirExists(cat.str(), "shaders")) { dondeestanlosshaders = cat.str(); break; } } } }
bool FilesDownload::downloadList() { string base = "http://" + host + "/" + path; // On parcours la liste for (size_t i = 0; i < filesToDownload.size(); i++) { string file = filesToDownload[i]; size_t pos; string link; while( (pos = file.find("/")) != string::npos ) { link += file.substr(0, pos); if (!dirExists(link)) CreateDirectoryA(link.c_str(), NULL); link += "/"; file.erase(0, pos + 1); } link += file; // On télécharge le fichier if (!Download::download(base + link, link)) { printf("Erreur download: %s", link.c_str()); return false; } } return true; }