/** Function to create a given directory. @internalComponent @released @param aSrcPath - path of the directory that needs to be created. @param aDelimiter - delimiter. */ void ImageReader::CreateSpecifiedDir(char* aSrcPath,const char* aDelimiter) { char* currWorkingDir = new char[_MAX_BUFFER_SIZE_]; string origPath; origPath.assign(aSrcPath); // get the current working directory and store in buffer. if( GETCWD(currWorkingDir,_MAX_BUFFER_SIZE_) == NULL ) { // throw an exception if unable to get current working directory information. throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "Failed to get the current working directory"); } else { char* cPtr = strtok(aSrcPath,aDelimiter); // check whether cPtr is a drive or a directory. if(IsDrive(cPtr)) { // if yes, then change the directory to cPtr. string changeToDrive ; changeToDrive.assign(cPtr); changeToDrive.append(aDelimiter); // change the current working directory to the specified directory. if( CHDIR(changeToDrive.c_str()) ) { // throw an exception if unable to change the directory specified. throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "Failed to change to the directory specified"); } } else { // if not,then create a cPtr directory. MKDIR(cPtr); // change the current working directory to cPtr. int r = CHDIR(cPtr); (void)r; } // repeat till cPtr is NULL. while (cPtr!=NULL) { if ((cPtr = strtok(NULL,aDelimiter)) != NULL) { // create the directory. MKDIR(cPtr); // change current working directory. int r = CHDIR(cPtr); (void)r; } } // revert back the working directory. int r = CHDIR(currWorkingDir); (void)r; // replace the source path with the original path information. strcpy(aSrcPath,origPath.c_str()); delete[] currWorkingDir; } }
int process_sub(FILE *data_file, FILE *struct_file) { FIND_T fInfo; FIND_RET_T fret; int filesProcessed = 0; if (processSubs) { /* process subs recursively */ size_t sublen = strlen(curSubdir); size_t freelen = sizeof(curSubdir) - sublen - 1; LWIP_ASSERT("sublen < sizeof(curSubdir)", sublen < sizeof(curSubdir)); fret = FINDFIRST_DIR("*", &fInfo); if (FINDFIRST_SUCCEEDED(fret)) { do { const char *curName = FIND_T_FILENAME(fInfo); if ((curName[0] == '.') || (strcmp(curName, "CVS") == 0)) { continue; } if (!FIND_T_IS_DIR(fInfo)) { continue; } if (freelen > 0) { CHDIR(curName); strncat(curSubdir, "/", freelen); strncat(curSubdir, curName, freelen - 1); curSubdir[sizeof(curSubdir) - 1] = 0; printf("processing subdirectory %s/..." NEWLINE, curSubdir); filesProcessed += process_sub(data_file, struct_file); CHDIR(".."); curSubdir[sublen] = 0; } else { printf("WARNING: cannot process sub due to path length restrictions: \"%s/%s\"\n", curSubdir, curName); } } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo))); } } fret = FINDFIRST_FILE("*.*", &fInfo); if (FINDFIRST_SUCCEEDED(fret)) { /* at least one file in directory */ do { if (FIND_T_IS_FILE(fInfo)) { const char *curName = FIND_T_FILENAME(fInfo); printf("processing %s/%s..." NEWLINE, curSubdir, curName); if (process_file(data_file, struct_file, curName) < 0) { printf(NEWLINE "Error... aborting" NEWLINE); return -1; } filesProcessed++; } } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo))); } return filesProcessed; }
QString QDir::canonicalPath() const { QString r; char cur[PATH_MAX]; char tmp[PATH_MAX]; GETCWD( cur, PATH_MAX ); if ( CHDIR(QFile::encodeName(dPath)) >= 0 ) { GETCWD( tmp, PATH_MAX ); r = QFile::decodeName(tmp); } CHDIR( cur ); slashify( r ); return r; }
int process_sub(FILE *data_file, FILE *struct_file) { FIND_T fInfo; FIND_RET_T fret; int filesProcessed = 0; char oldSubdir[MAX_PATH_LEN]; if (processSubs) { /* process subs recursively */ strcpy(oldSubdir, curSubdir); fret = FINDFIRST_DIR("*", &fInfo); if (FINDFIRST_SUCCEEDED(fret)) { do { const char *curName = FIND_T_FILENAME(fInfo); if (curName == NULL) continue; if (curName[0] == '.') continue; if (strcmp(curName, "CVS") == 0) continue; if (!FIND_T_IS_DIR(fInfo)) continue; CHDIR(curName); strcat(curSubdir, "/"); strcat(curSubdir, curName); printf(NEWLINE "processing subdirectory %s/..." NEWLINE, curSubdir); filesProcessed += process_sub(data_file, struct_file); CHDIR(".."); strcpy(curSubdir, oldSubdir); } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo))); } } fret = FINDFIRST_FILE("*.*", &fInfo); if (FINDFIRST_SUCCEEDED(fret)) { /* at least one file in directory */ do { if (FIND_T_IS_FILE(fInfo)) { const char *curName = FIND_T_FILENAME(fInfo); printf("processing %s/%s..." NEWLINE, curSubdir, curName); if (process_file(data_file, struct_file, curName) < 0) { printf(NEWLINE "Error... aborting" NEWLINE); return -1; } filesProcessed++; } } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo))); } return filesProcessed; }
char * ChangeToDir (const char *Dirname) { STRUCT_STAT st; if (STAT(Dirname, &st)) { // doen't exist; must create it MKDIR (Dirname); } if (S_ISDIR(st.st_mode) == 0) { // it's not a dir, must create a dir MKDIR (Dirname); } char *oldDirname = GetCurrDir (); CHDIR(Dirname); return oldDirname; }
void setzdir(mval *newdir, mval *full_path_of_newdir) { /* newdir is the directory to change to; NULL to set full_path_of_newdir to current working directory. * If full_path_of_newdir is non NULL, return the full path of the new directory in full_path_of_newdir. * NOTE : the full path of directory is stored in a static buffer which might get overwritten by the next call to setzdir. * Callers should save return value if needed. */ char directory[GTM_MAX_DIR_LEN], *getcwd_res, *err_str; uint4 length, status; assert(NULL != newdir || NULL != full_path_of_newdir); if (NULL != newdir) { MV_FORCE_STR(newdir); assert(SIZEOF(directory) > newdir->str.len); memcpy(directory, newdir->str.addr, newdir->str.len); directory[newdir->str.len] = '\0'; if (-1 == CHDIR(directory)) { /* On VMS, chdir(directory, 0) [actually, any non 1 value] is supposed to restore the process startup cwd at * exit (see help cc run). We've noticed that it doesn't behave the way it has been documented in the mumps * executable. Vinaya, 08/22/2001. */ err_str = STRERROR(errno); rts_error(VARLSTCNT(8) ERR_SETZDIR, 2, newdir->str.len, newdir->str.addr, ERR_TEXT, 2, LEN_AND_STR(err_str)); } } /* We need to find the full path of the current working directory because newdir might be a relative path, in which case * $ZDIR will show up as a relative path. */ if (NULL != full_path_of_newdir) { GETCWD(directory_buffer, SIZEOF(directory_buffer), getcwd_res); if (NULL != getcwd_res) { length = USTRLEN(directory_buffer); UNIX_ONLY(directory_buffer[length++] = '/';) } else
// ------------------------------------------------------ // Fill the list with the content of the relevant directory void Read_SMPT(void) { int i; lt_items[Scopish] = 0; list_counter[Scopish] = 0; #if defined(__WIN32__) struct _finddata_t c_file; #endif long hFile; nbr_dirs = 0; switch(Scopish) { case SCOPE_ZONE_MOD_DIR: cur_dir = Dir_Mods; break; case SCOPE_ZONE_INSTR_DIR: cur_dir = Dir_Instrs; break; case SCOPE_ZONE_PRESET_DIR: cur_dir = Dir_Presets; break; case SCOPE_ZONE_REVERB_DIR: cur_dir = Dir_Reverbs; break; case SCOPE_ZONE_PATTERN_DIR: cur_dir = Dir_Patterns; break; case SCOPE_ZONE_SAMPLE_DIR: cur_dir = Dir_Samples; break; case SCOPE_ZONE_MIDICFG_DIR: cur_dir = Dir_MidiCfg; break; } CHDIR(cur_dir); // Find first .c file in current directory strcpy(Dir_Act, cur_dir); #if defined(__WIN32__) strcat(Dir_Act, "\\*.*"); if((hFile = _findfirst(Dir_Act, &c_file)) == -1L) { Add_Entry("No files in current directory.", 0); } else { // The first directory if(c_file.attrib & _A_SUBDIR) { if(strcmp(c_file.name, ".") && strcmp(c_file.name, "..")) { nbr_dirs++; Add_Entry(c_file.name, _A_SUBDIR); } } // Find the rest of the directories while(_findnext(hFile, &c_file) == 0) { if(c_file.attrib & _A_SUBDIR) { if(strcmp(c_file.name, ".") && strcmp(c_file.name, "..")) { nbr_dirs++; Add_Entry(c_file.name, _A_SUBDIR); } } } // End dir _findclose(hFile); if((hFile = _findfirst(Dir_Act, &c_file)) != -1L) { // The first file if(!(c_file.attrib & _A_SUBDIR)) { Add_Entry(c_file.name, 0); } // Find the rest of the files while(_findnext(hFile, &c_file) == 0) { if(!(c_file.attrib & _A_SUBDIR)) { Add_Entry(c_file.name, 0); } } // while _findclose(hFile); if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } Insert_Entry("..", _A_SUBDIR, 0); Insert_Entry(".", _A_SUBDIR, 0); } } // Add the available drives to the bottom of the list char *Ptr_Drives; GetLogicalDriveStrings(1024, List_Drives); Ptr_Drives = List_Drives; i = 0; if(Ptr_Drives[0]) Add_Entry("", _A_SEP); while(Ptr_Drives[0]) { Add_Entry(Ptr_Drives, _A_SUBDIR); Ptr_Drives += strlen(Ptr_Drives) + 1; } #elif defined(__AMIGAOS4__) || defined(__AROS__) #if defined(__AMIGAOS4__) #define LockDosList(f) IDOS->LockDosList(f) #define NextDosEntry(d,f) IDOS->NextDosEntry(d, f) #define CopyStringBSTRToC(bin,sout,len) IDOS->CopyStringBSTRToC(bin, sout, len) #define UnLockDosList(f) IDOS->UnLockDosList(f) #endif if (!strcmp(Dir_Act, "/")) { // Only display volumes struct DosList *dl; const uint32 flags = LDF_VOLUMES | LDF_READ; char BString[1024]; dl = LockDosList(flags); while ((dl = NextDosEntry(dl, flags)) != NULL) { // Convert it first CopyStringBSTRToC(dl->dol_Name, BString, sizeof(BString)); Add_Entry(BString, _A_SUBDIR); } UnLockDosList(flags); } else { DIR *dirp; struct dirent *dp; dirp = opendir(Dir_Act); if (dirp) { // Add the directories first while ((dp = readdir(dirp)) != NULL) { if(dp->d_type == DT_DIR) { nbr_dirs++; Add_Entry(dp->d_name, _A_SUBDIR); } } closedir(dirp); } dirp = opendir(Dir_Act); if (dirp) { // Then add the files while ((dp = readdir(dirp)) != NULL) { if(dp->d_type != DT_DIR) { Add_Entry(dp->d_name, 0); } } closedir(dirp); } if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } // Insert parent directory at the top Insert_Entry("/", _A_SUBDIR, 0); } #else // Enum them nftw(Dir_Act, &list_file, FTW_PHYS, 0); if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } // Always insert them at the top of the list Insert_Entry("../", _A_SUBDIR, 0); Insert_Entry("./", _A_SUBDIR, 0); #endif // Insert a separator between files and directories if(nbr_dirs) { for(i = list_counter[Scopish] - 1; i >= 0; i--) { if(SMPT_LIST[i].Type == _A_FILE) { Insert_Entry("", _A_SEP, i + 1); break; } } } }
void Set_Current_Dir(void) { char filename[MAX_PATH]; #if defined(__AMIGAOS4__) || defined(__AROS__) char *tmp = Dir_Act[0] ? &Dir_Act[strlen(Dir_Act) - 1] : NULL; if (tmp && *tmp == '/') *tmp = 0; if (strrchr(Dir_Act, '/') == Dir_Act && !strcmp(Get_FileName(lt_curr[Scopish]), "..")) { switch(Scopish) { case SCOPE_ZONE_MOD_DIR: strcpy(Dir_Mods, "/"); break; case SCOPE_ZONE_INSTR_DIR: strcpy(Dir_Instrs, "/"); break; case SCOPE_ZONE_PRESET_DIR: strcpy(Dir_Presets, "/"); break; case SCOPE_ZONE_REVERB_DIR: strcpy(Dir_Reverbs, "/"); break; case SCOPE_ZONE_MIDICFG_DIR: strcpy(Dir_MidiCfg, "/"); break; case SCOPE_ZONE_PATTERN_DIR: strcpy(Dir_Patterns, "/"); break; case SCOPE_ZONE_SAMPLE_DIR: strcpy(Dir_Samples, "/"); break; } return; } if (tmp && *tmp == 0) { *tmp = '/'; } if (!strcmp(Dir_Act, "/")) { strcpy(filename, "/"); strcat(filename, Get_FileName(lt_curr[Scopish])); } else { strcpy(filename, Get_FileName(lt_curr[Scopish])); } #else strcpy(filename, Get_FileName(lt_curr[Scopish])); #endif switch(Scopish) { case SCOPE_ZONE_MOD_DIR: CHDIR(filename); GETCWD(Dir_Mods, MAX_PATH); break; case SCOPE_ZONE_INSTR_DIR: CHDIR(filename); GETCWD(Dir_Instrs, MAX_PATH); break; case SCOPE_ZONE_PRESET_DIR: CHDIR(filename); GETCWD(Dir_Presets, MAX_PATH); break; case SCOPE_ZONE_REVERB_DIR: CHDIR(filename); GETCWD(Dir_Reverbs, MAX_PATH); break; case SCOPE_ZONE_MIDICFG_DIR: CHDIR(filename); GETCWD(Dir_MidiCfg, MAX_PATH); break; case SCOPE_ZONE_PATTERN_DIR: CHDIR(filename); GETCWD(Dir_Patterns, MAX_PATH); break; case SCOPE_ZONE_SAMPLE_DIR: CHDIR(filename); GETCWD(Dir_Samples, MAX_PATH); break; } }
int main(int argc, char *argv[]) { char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for (i = 1; i < argc; i++) { if (argv[i] == NULL) { continue; } if (argv[i][0] == '-') { if (strstr(argv[i], "-svr:") == argv[i]) { snprintf(serverIDBuffer, sizeof(serverIDBuffer), "Server: %s\r\n", &argv[i][5]); serverID = serverIDBuffer; printf("Using Server-ID: \"%s\"\n", serverID); } else if (strstr(argv[i], "-s") == argv[i]) { processSubs = 0; } else if (strstr(argv[i], "-e") == argv[i]) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11") == argv[i]) { useHttp11 = 1; } else if (strstr(argv[i], "-nossi") == argv[i]) { supportSsi = 0; } else if (strstr(argv[i], "-c") == argv[i]) { precalcChksum = 1; } else if (strstr(argv[i], "-f:") == argv[i]) { strncpy(targetfile, &argv[i][3], sizeof(targetfile) - 1); targetfile[sizeof(targetfile) - 1] = 0; printf("Writing to file \"%s\"\n", targetfile); } else if (strstr(argv[i], "-m") == argv[i]) { includeLastModified = 1; } else if (strstr(argv[i], "-defl") == argv[i]) { #if MAKEFS_SUPPORT_DEFLATE char* colon = strstr(argv[i], ":"); if (colon) { if (colon[1] != 0) { int defl_level = atoi(&colon[1]); if ((defl_level >= 0) && (defl_level <= 10)) { deflate_level = defl_level; } else { printf("ERROR: deflate level must be [0..10]" NEWLINE); exit(0); } } } deflateNonSsiFiles = 1; printf("Deflating all non-SSI files with level %d (but only if size is reduced)" NEWLINE, deflate_level); #else printf("WARNING: Deflate support is disabled\n"); #endif } else if ((strstr(argv[i], "-?")) || (strstr(argv[i], "-h"))) { print_usage(); exit(0); } } else if ((argv[i][0] == '/') && (argv[i][1] == '?') && (argv[i][2] == 0)) { print_usage(); exit(0); } else { strncpy(path, argv[i], sizeof(path)-1); path[sizeof(path)-1] = 0; } } if (!check_path(path, sizeof(path))) { printf("Invalid path: \"%s\"." NEWLINE, path); exit(-1); } GETCWD(appPath, MAX_PATH_LEN); /* if command line param or subdir named 'fs' not found spout usage verbiage */ if (!CHDIR_SUCCEEDED(CHDIR(path))) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); print_usage(); exit(-1); } CHDIR(appPath); printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); fclose(data_file); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"lwip/apps/fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); /* define FS_FILE_FLAGS_HEADER_INCLUDED to 1 if not defined (compatibility with older httpd/fs) */ fprintf(data_file, "#ifndef FS_FILE_FLAGS_HEADER_INCLUDED" NEWLINE "#define FS_FILE_FLAGS_HEADER_INCLUDED 1" NEWLINE "#endif" NEWLINE); /* define FS_FILE_FLAGS_HEADER_PERSISTENT to 0 if not defined (compatibility with older httpd/fs: wasn't supported back then) */ fprintf(data_file, "#ifndef FS_FILE_FLAGS_HEADER_PERSISTENT" NEWLINE "#define FS_FILE_FLAGS_HEADER_PERSISTENT 0" NEWLINE "#endif" NEWLINE); /* define alignment defines */ #if ALIGN_PAYLOAD fprintf(data_file, "/* FSDATA_FILE_ALIGNMENT: 0=off, 1=by variable, 2=by include */" NEWLINE "#ifndef FSDATA_FILE_ALIGNMENT" NEWLINE "#define FSDATA_FILE_ALIGNMENT 0" NEWLINE "#endif" NEWLINE); #endif fprintf(data_file, "#ifndef FSDATA_ALIGN_PRE" NEWLINE "#define FSDATA_ALIGN_PRE" NEWLINE "#endif" NEWLINE); fprintf(data_file, "#ifndef FSDATA_ALIGN_POST" NEWLINE "#define FSDATA_ALIGN_POST" NEWLINE "#endif" NEWLINE); #if ALIGN_PAYLOAD fprintf(data_file, "#if FSDATA_FILE_ALIGNMENT==2" NEWLINE "#include \"fsdata_alignment.h\"" NEWLINE "#endif" NEWLINE); #endif sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ if (remove("fsdata.tmp") != 0) { printf("Warning: failed to delete fsdata.tmp\n"); } if (remove("fshdr.tmp") != 0) { printf("Warning: failed to delete fshdr.tmp\n"); } printf(NEWLINE "Processed %d files - done." NEWLINE, filesProcessed); #if MAKEFS_SUPPORT_DEFLATE if (deflateNonSsiFiles) { printf("(Deflated total byte reduction: %d bytes -> %d bytes (%.02f%%)" NEWLINE, (int)overallDataBytes, (int)deflatedBytesReduced, (float)((deflatedBytesReduced*100.0)/overallDataBytes)); } #endif printf(NEWLINE); while (first_file != NULL) { struct file_entry* fe = first_file; first_file = fe->next; free(fe); } return 0; }
boolean TxCache::load(const wchar_t *path, const wchar_t *filename, int config) { /* find it on disk */ char cbuf[MAX_PATH]; #ifdef OS_WINDOWS wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(path); #else char curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); wcstombs(cbuf, path, MAX_PATH); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "rb"); DBG_INFO(80, wst("gzfp:%x file:%ls\n"), gzfp, filename); if (gzfp) { /* yep, we have it. load it into memory cache. */ int dataSize; uint64 checksum; int tmpconfig; /* read header to determine config match */ gzread(gzfp, &tmpconfig, 4); if (tmpconfig == config) { do { GHQTexInfo tmpInfo; gzread(gzfp, &checksum, 8); gzread(gzfp, &tmpInfo.width, 4); gzread(gzfp, &tmpInfo.height, 4); gzread(gzfp, &tmpInfo.format, 4); gzread(gzfp, &tmpInfo.texture_format, 2); gzread(gzfp, &tmpInfo.pixel_type, 2); gzread(gzfp, &tmpInfo.is_hires_tex, 1); gzread(gzfp, &dataSize, 4); tmpInfo.data = (uint8*)malloc(dataSize); if (tmpInfo.data) { gzread(gzfp, tmpInfo.data, dataSize); /* add to memory cache */ add(checksum, &tmpInfo, (tmpInfo.format & GL_TEXFMT_GZ) ? dataSize : 0); free(tmpInfo.data); } else { gzseek(gzfp, dataSize, SEEK_CUR); } /* skip in between to prevent the loop from being tied down to vsync */ if (_callback && (!(_cache.size() % 100) || gzeof(gzfp))) (*_callback)(wst("[%d] total mem:%.02fmb - %ls\n"), _cache.size(), (float)_totalSize/1000000, filename); } while (!gzeof(gzfp)); gzclose(gzfp); } } CHDIR(curpath); return !_cache.empty(); }
bool QDir::setCurrent( const QString &path ) { int r; r = CHDIR( QFile::encodeName(path) ); return r >= 0; }
boolean TxCache::load(const wchar_t *path, const wchar_t *filename, int config) { /* find it on disk */ char cbuf[MAX_PATH]; boost::filesystem::wpath cachepath(path); #ifdef BOOST_WINDOWS_API wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(cachepath.wstring().c_str()); #else char curpath[MAX_PATH]; wcstombs(cbuf, cachepath.wstring().c_str(), MAX_PATH); GETCWD(MAX_PATH, curpath); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "rb"); DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); if (gzfp) { /* yep, we have it. load it into memory cache. */ int dataSize; uint64 checksum; GHQTexInfo tmpInfo; int tmpconfig; /* read header to determine config match */ gzread(gzfp, &tmpconfig, 4); if (tmpconfig == config) { do { memset(&tmpInfo, 0, sizeof(GHQTexInfo)); gzread(gzfp, &checksum, 8); gzread(gzfp, &tmpInfo.width, 4); gzread(gzfp, &tmpInfo.height, 4); gzread(gzfp, &tmpInfo.format, 2); gzread(gzfp, &tmpInfo.smallLodLog2, 4); gzread(gzfp, &tmpInfo.largeLodLog2, 4); gzread(gzfp, &tmpInfo.aspectRatioLog2, 4); gzread(gzfp, &tmpInfo.tiles, 4); gzread(gzfp, &tmpInfo.untiled_width, 4); gzread(gzfp, &tmpInfo.untiled_height, 4); gzread(gzfp, &tmpInfo.is_hires_tex, 1); gzread(gzfp, &dataSize, 4); tmpInfo.data = (uint8*)malloc(dataSize); if (tmpInfo.data) { gzread(gzfp, tmpInfo.data, dataSize); /* add to memory cache */ add(checksum, &tmpInfo, (tmpInfo.format & GR_TEXFMT_GZ) ? dataSize : 0); free(tmpInfo.data); } else { gzseek(gzfp, dataSize, SEEK_CUR); } /* skip in between to prevent the loop from being tied down to vsync */ if (_callback && (!(_cache.size() % 100) || gzeof(gzfp))) (*_callback)(L"[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize/1000000, filename); } while (!gzeof(gzfp)); gzclose(gzfp); } else { if ((tmpconfig & HIRESTEXTURES_MASK) != (config & HIRESTEXTURES_MASK)) { const char *conf_str; if ((tmpconfig & HIRESTEXTURES_MASK) == NO_HIRESTEXTURES) conf_str = "0"; else if ((tmpconfig & HIRESTEXTURES_MASK) == RICE_HIRESTEXTURES) conf_str = "1"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs must be %s", conf_str); } if ((tmpconfig & COMPRESS_HIRESTEX) != (config & COMPRESS_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_cmpr must be %s", (tmpconfig & COMPRESS_HIRESTEX) ? "True" : "False"); if ((tmpconfig & COMPRESSION_MASK) != (config & COMPRESSION_MASK) && (tmpconfig & COMPRESS_HIRESTEX)) { const char *conf_str; if ((tmpconfig & COMPRESSION_MASK) == FXT1_COMPRESSION) conf_str = "1"; else if ((tmpconfig & COMPRESSION_MASK) == S3TC_COMPRESSION) conf_str = "0"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_cmpr must be %s", conf_str); } if ((tmpconfig & TILE_HIRESTEX) != (config & TILE_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_tile must be %s", (tmpconfig & TILE_HIRESTEX) ? "True" : "False"); if ((tmpconfig & FORCE16BPP_HIRESTEX) != (config & FORCE16BPP_HIRESTEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_f16bpp must be %s", (tmpconfig & FORCE16BPP_HIRESTEX) ? "True" : "False"); if ((tmpconfig & GZ_HIRESTEXCACHE) != (config & GZ_HIRESTEXCACHE)) WriteLog(M64MSG_WARNING, "ghq_hirs_gz must be %s", (tmpconfig & GZ_HIRESTEXCACHE) ? "True" : "False"); if ((tmpconfig & LET_TEXARTISTS_FLY) != (config & LET_TEXARTISTS_FLY)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_hirs_let_texartists_fly must be %s", (tmpconfig & LET_TEXARTISTS_FLY) ? "True" : "False"); if ((tmpconfig & FILTER_MASK) != (config & FILTER_MASK)) { const char *conf_str; if ((tmpconfig & FILTER_MASK) == NO_FILTER) conf_str = "0"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_1) conf_str = "1"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_2) conf_str = "2"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_3) conf_str = "3"; else if ((tmpconfig & FILTER_MASK) == SMOOTH_FILTER_4) conf_str = "4"; else if ((tmpconfig & FILTER_MASK) == SHARP_FILTER_1) conf_str = "5"; else if ((tmpconfig & FILTER_MASK) == SHARP_FILTER_2) conf_str = "6"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_fltr must be %s", conf_str); } if ((tmpconfig & ENHANCEMENT_MASK) != (config & ENHANCEMENT_MASK)) { const char *conf_str; if ((tmpconfig & ENHANCEMENT_MASK) == NO_ENHANCEMENT) conf_str = "0"; else if ((tmpconfig & ENHANCEMENT_MASK) == X2_ENHANCEMENT) conf_str = "2"; else if ((tmpconfig & ENHANCEMENT_MASK) == X2SAI_ENHANCEMENT) conf_str = "3"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ2X_ENHANCEMENT) conf_str = "4"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ2XS_ENHANCEMENT) conf_str = "5"; else if ((tmpconfig & ENHANCEMENT_MASK) == LQ2X_ENHANCEMENT) conf_str = "6"; else if ((tmpconfig & ENHANCEMENT_MASK) == LQ2XS_ENHANCEMENT) conf_str = "7"; else if ((tmpconfig & ENHANCEMENT_MASK) == HQ4X_ENHANCEMENT) conf_str = "8"; else conf_str = "set to an unsupported format"; WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht must be %s", conf_str); } if ((tmpconfig & COMPRESS_TEX) != (config & COMPRESS_TEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_cmpr must be %s", (tmpconfig & COMPRESS_TEX) ? "True" : "False"); if ((tmpconfig & FORCE16BPP_TEX) != (config & FORCE16BPP_TEX)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_f16bpp must be %s", (tmpconfig & FORCE16BPP_TEX) ? "True" : "False"); if ((tmpconfig & GZ_TEXCACHE) != (config & GZ_TEXCACHE)) WriteLog(M64MSG_WARNING, "Ignored texture cache due to incompatible setting: ghq_enht_gz must be %s", (tmpconfig & GZ_TEXCACHE) ? "True" : "False"); } } CHDIR(curpath); return !_cache.empty(); }
boolean TxCache::save(const wchar_t *path, const wchar_t *filename, int config) { if (!_cache.empty()) { /* dump cache to disk */ char cbuf[MAX_PATH]; boost::filesystem::wpath cachepath(path); boost::filesystem::create_directory(cachepath); /* Ugly hack to enable fopen/gzopen in Win9x */ #ifdef BOOST_WINDOWS_API wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(cachepath.wstring().c_str()); #else char curpath[MAX_PATH]; wcstombs(cbuf, cachepath.wstring().c_str(), MAX_PATH); GETCWD(MAX_PATH, curpath); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "wb1"); DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); if (gzfp) { /* write header to determine config match */ gzwrite(gzfp, &config, 4); std::map<uint64, TXCACHE*>::iterator itMap = _cache.begin(); while (itMap != _cache.end()) { uint8 *dest = (*itMap).second->info.data; uint32 destLen = (*itMap).second->size; uint16 format = (*itMap).second->info.format; /* to keep things simple, we save the texture data in a zlib uncompressed state. */ /* sigh... for those who cannot wait the extra few seconds. changed to keep * texture data in a zlib compressed state. if the GZ_TEXCACHE or GZ_HIRESTEXCACHE * option is toggled, the cache will need to be rebuilt. */ /*if (format & GR_TEXFMT_GZ) { dest = _gzdest0; destLen = _gzdestLen; if (dest && destLen) { if (uncompress(dest, &destLen, (*itMap).second->info.data, (*itMap).second->size) != Z_OK) { dest = NULL; destLen = 0; } format &= ~GR_TEXFMT_GZ; } }*/ if (dest && destLen) { /* texture checksum */ gzwrite(gzfp, &((*itMap).first), 8); /* other texture info */ gzwrite(gzfp, &((*itMap).second->info.width), 4); gzwrite(gzfp, &((*itMap).second->info.height), 4); gzwrite(gzfp, &format, 2); gzwrite(gzfp, &((*itMap).second->info.smallLodLog2), 4); gzwrite(gzfp, &((*itMap).second->info.largeLodLog2), 4); gzwrite(gzfp, &((*itMap).second->info.aspectRatioLog2), 4); gzwrite(gzfp, &((*itMap).second->info.tiles), 4); gzwrite(gzfp, &((*itMap).second->info.untiled_width), 4); gzwrite(gzfp, &((*itMap).second->info.untiled_height), 4); gzwrite(gzfp, &((*itMap).second->info.is_hires_tex), 1); gzwrite(gzfp, &destLen, 4); gzwrite(gzfp, dest, destLen); } itMap++; /* not ready yet */ /*if (_callback) (*_callback)(L"Total textures saved to HDD: %d\n", std::distance(itMap, _cache.begin()));*/ } gzclose(gzfp); } CHDIR(curpath); } return _cache.empty(); }
int main(int argc, char *argv[]) { FIND_T fInfo; FIND_RET_T fret; char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for(i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (strstr(argv[i], "-s")) { processSubs = 0; } else if (strstr(argv[i], "-e")) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11")) { useHttp11 = 1; } else if (strstr(argv[i], "-c")) { precalcChksum = 1; } else if((argv[i][1] == 'f') && (argv[i][2] == ':')) { strcpy(targetfile, &argv[i][3]); printf("Writing to file \"%s\"\n", targetfile); } } else { strcpy(path, argv[i]); } } /* if command line param or subdir named 'fs' not found spout usage verbiage */ fret = FINDFIRST_DIR(path, &fInfo); if (!FINDFIRST_SUCCEEDED(fret)) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); printf(" Usage: htmlgen [targetdir] [-s] [-i] [-f:<filename>]" NEWLINE NEWLINE); printf(" targetdir: relative or absolute path to files to convert" NEWLINE); printf(" switch -s: toggle processing of subdirectories (default is on)" NEWLINE); printf(" switch -e: exclude HTTP header from file (header is created at runtime, default is off)" NEWLINE); printf(" switch -11: include HTTP 1.1 header (1.0 is default)" NEWLINE); printf(" switch -c: precalculate checksums for all pages (default is off)" NEWLINE); printf(" switch -f: target filename (default is \"fsdata.c\")" NEWLINE); printf(" if targetdir not specified, htmlgen will attempt to" NEWLINE); printf(" process files in subdirectory 'fs'" NEWLINE); exit(-1); } printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } GETCWD(appPath, MAX_PATH_LEN); data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ remove("fsdata.tmp"); remove("fshdr.tmp"); printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed); return 0; }
int main(int argc, char *argv[]) { char path[MAX_PATH_LEN]; char appPath[MAX_PATH_LEN]; FILE *data_file; FILE *struct_file; int filesProcessed; int i; char targetfile[MAX_PATH_LEN]; strcpy(targetfile, "fsdata.c"); memset(path, 0, sizeof(path)); memset(appPath, 0, sizeof(appPath)); printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE); printf(" by Jim Pettinato - circa 2003 " NEWLINE); printf(" extended by Simon Goldschmidt - 2009 " NEWLINE NEWLINE); strcpy(path, "fs"); for(i = 1; i < argc; i++) { if (argv[i] == NULL) { continue; } if (argv[i][0] == '-') { if (strstr(argv[i], "-s")) { processSubs = 0; } else if (strstr(argv[i], "-e")) { includeHttpHeader = 0; } else if (strstr(argv[i], "-11")) { useHttp11 = 1; } else if (strstr(argv[i], "-nossi")) { supportSsi = 0; } else if (strstr(argv[i], "-c")) { precalcChksum = 1; } else if((argv[i][1] == 'f') && (argv[i][2] == ':')) { strncpy(targetfile, &argv[i][3], sizeof(targetfile) - 1); targetfile[sizeof(targetfile) - 1] = 0; printf("Writing to file \"%s\"\n", targetfile); } else if ((strstr(argv[i], "-?")) || (strstr(argv[i], "-h"))) { print_usage(); exit(0); } } else if ((argv[i][0] == '/') && (argv[i][1] == '?') && (argv[i][2] == 0)) { print_usage(); exit(0); } else { strncpy(path, argv[i], sizeof(path)-1); path[sizeof(path)-1] = 0; } } if(!check_path(path, sizeof(path))) { printf("Invalid path: \"%s\"." NEWLINE, path); exit(-1); } GETCWD(appPath, MAX_PATH_LEN); /* if command line param or subdir named 'fs' not found spout usage verbiage */ if (!CHDIR_SUCCEEDED(CHDIR(path))) { /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */ printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path); print_usage(); exit(-1); } CHDIR(appPath); printf("HTTP %sheader will %s statically included." NEWLINE, (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""), (includeHttpHeader ? "be" : "not be")); sprintf(curSubdir, ""); /* start off in web page's root directory - relative paths */ printf(" Processing all files in directory %s", path); if (processSubs) { printf(" and subdirectories..." NEWLINE NEWLINE); } else { printf("..." NEWLINE NEWLINE); } data_file = fopen("fsdata.tmp", "wb"); if (data_file == NULL) { printf("Failed to create file \"fsdata.tmp\"\n"); exit(-1); } struct_file = fopen("fshdr.tmp", "wb"); if (struct_file == NULL) { printf("Failed to create file \"fshdr.tmp\"\n"); fclose(data_file); exit(-1); } CHDIR(path); fprintf(data_file, "#include \"lwip/apps/fs.h\"" NEWLINE); fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE); fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE); fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE); sprintf(lastFileVar, "NULL"); filesProcessed = process_sub(data_file, struct_file); /* data_file now contains all of the raw data.. now append linked list of * file header structs to allow embedded app to search for a file name */ fprintf(data_file, NEWLINE NEWLINE); fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar); fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed); fclose(data_file); fclose(struct_file); CHDIR(appPath); /* append struct_file to data_file */ printf(NEWLINE "Creating target file..." NEWLINE NEWLINE); concat_files("fsdata.tmp", "fshdr.tmp", targetfile); /* if succeeded, delete the temporary files */ if (remove("fsdata.tmp") != 0) { printf("Warning: failed to delete fsdata.tmp\n"); } if (remove("fshdr.tmp") != 0) { printf("Warning: failed to delete fshdr.tmp\n"); } printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed); while (first_file != NULL) { struct file_entry* fe = first_file; first_file = fe->next; free(fe); } return 0; }
int main() { int ret, status; char *env_var_ptr; struct stat gtm_secshrdir_stat; struct stat gtm_secshr_stat; char gtm_dist_val[MAX_ENV_VAR_VAL_LEN]; char gtm_tmp_val[MAX_ENV_VAR_VAL_LEN]; char gtm_dbglvl_val[MAX_ENV_VAR_VAL_LEN]; char gtm_secshrdir_path[MAX_ENV_VAR_VAL_LEN]; char gtm_secshrdir_path_display[MAX_ENV_VAR_VAL_LEN]; char gtm_secshr_path[MAX_ENV_VAR_VAL_LEN]; char gtm_secshr_path_display[MAX_ENV_VAR_VAL_LEN]; char gtm_secshr_orig_path[MAX_ENV_VAR_VAL_LEN]; int gtm_tmp_exists = 0; int gtm_dbglvl_exists = 0; sigset_t mask; /* Reset the signal mask (since the one inherited from the invoking process might have signals such as SIGALRM or SIGTERM * blocked) to let gtmsecshr manage its own signals using sig_init. */ sigemptyset(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); OPENLOG("GTMSECSHRINIT", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_USER); ret = 0; /* start positive */ /* get the ones we need */ if (env_var_ptr = getenv(GTM_DIST)) /* Warning - assignment */ { if (MAX_ALLOWABLE_LEN < (strlen(env_var_ptr) + STR_LIT_LEN(SUB_PATH_TO_GTMSECSHRDIR) + STR_LIT_LEN(GTMSECSHR_BASENAME))) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMDIST2LONG); ret = -1; } else { strcpy(gtm_dist_val, env_var_ptr); /* point the path to the real gtmsecshr - for display purposes only */ strcpy(gtm_secshr_path, env_var_ptr); strcat(gtm_secshr_path, SUB_PATH_TO_GTMSECSHRDIR); strcat(gtm_secshr_path, GTMSECSHR_BASENAME); strsanitize(gtm_secshr_path, gtm_secshr_path_display); /* point the path to the real gtmsecshrdir */ strcpy(gtm_secshrdir_path, env_var_ptr); strcat(gtm_secshrdir_path, SUB_PATH_TO_GTMSECSHRDIR); strsanitize(gtm_secshrdir_path, gtm_secshrdir_path_display); } } else { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOGTMDIST); ret = -1; } if (env_var_ptr = getenv(GTM_TMP)) /* Warning - assignment */ { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr)) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMTMP2LONG); ret = -1; } else { gtm_tmp_exists = 1; strcpy(gtm_tmp_val, env_var_ptr); } } if (env_var_ptr = getenv(GTM_DBGLVL)) /* Warning - assignment */ { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr)) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMDBGLVL2LONG); ret = -1; } else { gtm_dbglvl_exists = 1; strcpy(gtm_dbglvl_val, env_var_ptr); } } if (!ret) { /* clear all */ status = gtm_clearenv(); if (status) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRCLEARENVFAILED); ret = -1; } /* add the ones we need */ status = gtm_setenv(GTM_DIST, gtm_dist_val, OVERWRITE); if (status) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETGTMDISTFAILED); ret = -1; } if (gtm_tmp_exists) { status = gtm_setenv(GTM_TMP, gtm_tmp_val, OVERWRITE); if (status) { SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETGTMTMPFAILED); ret = -1; } } } if (!ret) { /* go to root */ if (-1 == CHDIR(gtm_secshrdir_path)) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRCHDIRFAILED, gtm_secshrdir_path_display, errno); else if (-1 == Stat(REL_PATH_TO_CURDIR, >m_secshrdir_stat)) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSTATFAILED, gtm_secshrdir_path_display, errno); else if (ROOTUID != gtm_secshrdir_stat.st_uid) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTOWNEDBYROOT, gtm_secshrdir_path_display); else if (gtm_secshrdir_stat.st_mode & 0277) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRPERMINCRCT, gtm_secshrdir_path_display, gtm_secshrdir_stat.st_mode & 0777); else if (-1 == Stat(REL_PATH_TO_GTMSECSHR, >m_secshr_stat)) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSTATFAILED, gtm_secshr_path_display, errno); else if (ROOTUID != gtm_secshr_stat.st_uid) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTOWNEDBYROOT, gtm_secshr_path_display); else if (gtm_secshr_stat.st_mode & 022) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRWRITABLE, gtm_secshr_path_display); else if (!(gtm_secshr_stat.st_mode & 04000)) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTSETUID, gtm_secshr_path_display); else if (-1 == setuid(ROOTUID)) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETUIDFAILED); else { /* call the real gtmsecshr, but have ps display the original gtmsecshr location */ strcpy(gtm_secshr_orig_path, gtm_dist_val); strcat(gtm_secshr_orig_path, GTMSECSHR_BASENAME); ret = execl(REL_PATH_TO_GTMSECSHR, gtm_secshr_orig_path, NULL); if (-1 == ret) SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHREXECLFAILED, gtm_secshr_path_display); } } CLOSELOG(); return ret; }
int main() { int ret, status; char * env_var_ptr; struct stat gtm_secshrdir_stat; struct stat gtm_secshr_stat; char gtm_dist_val[MAX_ENV_VAR_VAL_LEN]; char gtm_log_val[MAX_ENV_VAR_VAL_LEN]; char gtm_tmp_val[MAX_ENV_VAR_VAL_LEN]; char gtm_dbglvl_val[MAX_ENV_VAR_VAL_LEN]; char gtm_secshrdir_path[MAX_ENV_VAR_VAL_LEN]; char gtm_secshr_path[MAX_ENV_VAR_VAL_LEN]; char gtm_secshr_orig_path[MAX_ENV_VAR_VAL_LEN]; int gtm_log_exists = 0; int gtm_tmp_exists = 0; int gtm_dbglvl_exists = 0; openlog("GTMSECSHRINIT", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_USER); ret = 0; /* start positive */ /* get the ones we need */ if (env_var_ptr = getenv(GTM_DIST)) { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr) + STR_LIT_LEN(SUB_PATH_TO_GTMSECSHRDIR) + STR_LIT_LEN(GTMSECSHR_BASENAME)) { syslog(LOG_USER | LOG_INFO, "gtm_dist env var too long. gtmsecshr will not be started.\n"); ret = -1; } else { strcpy(gtm_dist_val,env_var_ptr); /* point the path to the real gtmsecshr - for display purposes only */ strcpy(gtm_secshr_path, env_var_ptr); strcat(gtm_secshr_path, SUB_PATH_TO_GTMSECSHRDIR); strcat(gtm_secshr_path, GTMSECSHR_BASENAME); /* point the path to the real gtmsecshrdir */ strcpy(gtm_secshrdir_path, env_var_ptr); strcat(gtm_secshrdir_path, SUB_PATH_TO_GTMSECSHRDIR); } } else { syslog(LOG_USER | LOG_INFO, "gtm_dist env var does not exist. gtmsecshr will not be started.\n"); ret = -1; } if (env_var_ptr = getenv(GTM_LOG)) { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr)) { syslog(LOG_USER | LOG_INFO, "gtm_log env var too long. gtmsecshr will not be started.\n"); ret = -1; } else { gtm_log_exists = 1; strcpy(gtm_log_val, env_var_ptr); } } if (env_var_ptr = getenv(GTM_TMP)) { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr)) { syslog(LOG_USER | LOG_INFO, "gtm_tmp env var too long. gtmsecshr will not be started.\n"); ret = -1; } else { gtm_tmp_exists = 1; strcpy(gtm_tmp_val, env_var_ptr); } } if (env_var_ptr = getenv(GTM_DBGLVL)) { if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr)) { syslog(LOG_USER | LOG_INFO, "gtmdbglvl env var too long. gtmsecshr will not be started.\n"); ret = -1; } else { gtm_dbglvl_exists = 1; strcpy(gtm_dbglvl_val, env_var_ptr); } } #ifdef __MVS__ if (!(env_var_ptr = getenv(GTM_ZOS_AUTOCVT))) { syslog(LOG_USER | LOG_INFO, "_BPXK_AUTOCVT is not set, forcing autoconversion\n"); } #endif if (!ret) { /* clear all */ status = gtm_clearenv(); if (status) { syslog(LOG_USER | LOG_INFO, "clearenv failed. gtmsecshr will not be started.\n"); ret = -1; } /* add the ones we need */ status = gtm_setenv(GTM_DIST, gtm_dist_val, OVERWRITE); if (status) { syslog(LOG_USER | LOG_INFO, "setenv for gtm_dist failed. gtmsecshr will not be started.\n"); ret = -1; } if (gtm_log_exists) { status = gtm_setenv(GTM_LOG, gtm_log_val, OVERWRITE); if (status) { syslog(LOG_USER | LOG_INFO, "setenv for gtm_log failed. gtmsecshr will not be started.\n"); ret = -1; } } if (gtm_tmp_exists) { status = gtm_setenv(GTM_TMP, gtm_tmp_val, OVERWRITE); if (status) { syslog(LOG_USER | LOG_INFO, "setenv for gtm_tmp failed. gtmsecshr will not be started.\n"); ret = -1; } } if (gtm_dbglvl_exists) { status = gtm_setenv(GTM_DBGLVL, gtm_dbglvl_val, OVERWRITE); if (status) { syslog(LOG_USER | LOG_INFO, "setenv for gtmdbglvl failed. gtmsecshr will not be started.\n"); ret = -1; } } #ifdef __MVS__ status = gtm_setenv(GTM_ZOS_AUTOCVT, GTM_ZOS_AUTOCVT_ON, OVERWRITE); if (status) { syslog(LOG_USER | LOG_INFO, "setenv for _BPXK_AUTOCVT failed. gtmsecshr logs may contain mixed ASCII and EBCDIC.\n"); } #endif } if (!ret) { /* go to root */ if (-1 == CHDIR(gtm_secshrdir_path)) syslog(LOG_USER | LOG_INFO, "chdir failed on %s, errno %d. gtmsecshr will not be started.\n", gtm_secshrdir_path, errno); else if (-1 == Stat(REL_PATH_TO_CURDIR, >m_secshrdir_stat)) syslog(LOG_USER | LOG_INFO, "stat failed on %s, errno %d. gtmsecshr will not be started.\n", gtm_secshrdir_path, errno); else if (ROOTUID != gtm_secshrdir_stat.st_uid) syslog(LOG_USER | LOG_INFO, "%s not owned by root. gtmsecshr will not be started.\n", gtm_secshrdir_path); else if (gtm_secshrdir_stat.st_mode & 0277) syslog(LOG_USER | LOG_INFO, "%s permissions incorrect (%04o). gtmsecshr will not be started.\n", gtm_secshrdir_path, gtm_secshrdir_stat.st_mode & 0777); else if (-1 == Stat(REL_PATH_TO_GTMSECSHR, >m_secshr_stat)) syslog(LOG_USER | LOG_INFO, "stat failed on %s, errno %d. gtmsecshr will not be started.\n", gtm_secshr_path, errno); else if (ROOTUID != gtm_secshr_stat.st_uid) syslog(LOG_USER | LOG_INFO, "%s not owned by root. gtmsecshr will not be started.\n", gtm_secshr_path); else if (gtm_secshr_stat.st_mode & 022) syslog(LOG_USER | LOG_INFO, "%s writable. gtmsecshr will not be started.\n", gtm_secshr_path); else if (!(gtm_secshr_stat.st_mode & 04000)) syslog(LOG_USER | LOG_INFO, "%s not set-uid. gtmsecshr will not be started.\n", gtm_secshr_path); else if (-1 == setuid(ROOTUID)) syslog(LOG_USER | LOG_INFO, "setuid failed. gtmsecshr will not be started.\n"); else { /* call the real gtmsecshr, but have ps display the original gtmsecshr location */ strcpy(gtm_secshr_orig_path, gtm_dist_val); strcat(gtm_secshr_orig_path, GTMSECSHR_BASENAME); ret = execl(REL_PATH_TO_GTMSECSHR, gtm_secshr_orig_path, NULL); if (-1 == ret) syslog(LOG_USER | LOG_INFO, "execl of %s failed\n", gtm_secshr_path); } } closelog(); return ret; }
int nextdir(int toplev) { #ifdef __OS2__ FILEFINDBUF3 find; ULONG srch_cnt; HDIR dirhandle; APIRET findret; #else struct ffblk find; ULONG srch_cnt; HDIR dirhandle; int findret; #endif int retcode=TRUE, c, rc, nomore; #ifdef DBG printf("entered nextdir %d\n", nextdirdepth++); #endif srch_cnt = 1; dirhandle = HDIR_CREATE; findret = DosFindFirst("*.*", &dirhandle, MUST_HAVE_DIRECTORY, &find, sizeof(find), &srch_cnt, FIL_STANDARD); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); if (!nomore) dirhandle = 1; #endif #ifdef DBG printf("DosFindFirstDir returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); assert(dirhandle != HDIR_CREATE); #endif if (nomore) findret = 0; while (!nomore) { if ((findret == 0) && (FNAME != '.') && (FATTR & FILE_DIRECTORY)) { /* descend next level */ if (toplev) printf("Deleting %s...\n", &FNAME); #ifdef DBG printf("descending to scan %s\n", &FNAME); assert(0 == CHDIR(&FNAME)); retcode &= nextdir(FALSE); /* ascend level and onto next directory */ assert(0 == CHDIR("..")); printf("removing dir %s\n", &FNAME); #else /* descend level */ if (CHDIR(&FNAME)) { /* descent impossible */ retcode = FALSE; } else { /* process next directory */ retcode &= nextdir(FALSE); /* ascend level */ if (CHDIR("..")) { /* Something woefully wrong ... */ if (dirhandle != HDIR_CREATE) { DosFindClose(dirhandle); dirhandle = HDIR_CREATE; } return(FALSE); } else { /* delete empty directory */ retcode &= (0 == DosDeleteDir(&FNAME)); } } #endif } /* Position to next entry */ findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); #endif #ifdef DBG printf("DosFindNextDir returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; /* Process next entry */ continue; } if (dirhandle != HDIR_CREATE) { DosFindClose(dirhandle); dirhandle = HDIR_CREATE; } srch_cnt = 1; /* Now delete the files */ findret = DosFindFirst("*.*",&dirhandle, FILE_ABNORMAL, &find, sizeof(find), &srch_cnt, FIL_STANDARD); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); if (!nomore) dirhandle = 1; #endif #ifdef DBG printf("DosFindFirstFile returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; while (!nomore) { if (findret == 0) { /* Process if file OK */ if (toplev) printf("Deleting %s...\n", &FNAME); #ifdef DBG if (!findret && (FATTR & FILE_ABNORMAL)) printf("making normal and %sdeleting %s\n", dbgdel[forcedel], &FNAME); else printf("%sdeleting %s\n", dbgdel[forcedel], &FNAME); #else if (!findret && (FATTR & FILE_ABNORMAL)) rc = _chmod(&FNAME, 1, 0); if (!rc) { #ifdef __OS2__ if (forcedel) retcode &= (0 == DosForceDelete(&FNAME)); else #endif retcode &= (0 == DosDelete(&FNAME)); } else retcode = FALSE; #endif } /* Advance to next file */ findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); #endif #ifdef DBG printf("DosFindNextFile returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; /* Process next file */ continue; } if (dirhandle != HDIR_CREATE) DosFindClose(dirhandle); #ifdef DBG printf("leaving nextdir %d\n", --nextdirdepth); #endif return(retcode); }
static #endif char* pathreal(const char* apath, register int type, struct stat* st) { char* path = (char*)apath; register char* sp; register char* cp; register char* ip; Table_t* safe; int oerrno = errno; int opaqued = 0; int len; int vir; int safesize; int safe_dir; long visits; char buf[PATH_MAX + 1]; static struct stat stbuf; static struct stat tsbuf; state.path.level = state.path.synthesize = state.path.nlinks = 0; if (!path) { errno = EFAULT; return 0; } initialize(); if (state.in_2d) { if (!st || (!state.level || *path == '/') && !LSTAT(path, st)) return path; if (state.level && streq(path, ".") && !CHDIR(state.pwd)) { state.level = 0; return path; } return 0; } #if FS if (mounted() && (sp = fsreal(state.path.monitor, MSG_stat, state.path.mount))) apath = (char*)(path = sp); #endif /* * handle null path, . and / separately */ if (safe = state.safe ? &state.vsafe : (Table_t*)0) { type |= P_ABSOLUTE; if (!(safesize = state.safe->servicesize)) safesize = strlen(state.safe->service); } else type &= ~P_SAFE; again: if (!*path) { errno = ENOENT; return 0; } cp = sp = path; state.path.synthesize = state.path.linksize = 0; if (!st) st = &stbuf; /* * check if virtual dir has been created by another process * only P_PATHONLY|P_TOP calls (usually create or modify link) and * references to "." are checked for performance */ if (state.level > 0 && state.pwd && ((type & (P_PATHONLY|P_TOP)) && *sp != '/' || *sp == '.' && sp[1] == 0)) { if (!CHDIR(state.pwd)) state.level = 0; else if (!(type & (P_PATHONLY|P_TOP))) { len = 0; state.path.level += (state.path.synthesize = state.level); sp = strcpy(state.path.name, state.pwd); goto skip; } } if (!state.pwd || sp[1] == 0 && (*sp == '.' || *sp == '/' && !safe)) { if (st != &stbuf && LSTAT(sp, st)) return 0; if (*sp == '/' || !state.pwd && (type & P_PATHONLY)) strncpy(state.path.name, sp, PATH_MAX); else if (!state.pwd) { /* * treat the current directory as if were empty */ errno = ENOENT; return 0; } else strncpy(state.path.name, state.pwd, PATH_MAX); errno = oerrno; return state.path.name; } /* * put absolute pathname into state.path */ safe_dir = 0; if (*path != '/') { strcpy(state.path.name, state.pwd); sp = state.path.name + state.pwdsize; *sp++ = '/'; if (safe && state.pwdsize >= safesize && !strncmp(state.pwd, state.safe->service, safesize) && (!state.pwd[safesize] || state.pwd[safesize] == '/')) safe_dir = safesize; } else sp = state.path.name; ip = state.path.name + elementsof(state.path.name); while (sp < ip && (*sp = *cp++)) sp++; if (type & P_DOTDOT) strcpy(sp, "/.."); sp = state.path.name; if (!(ip = pathcanon(sp + safe_dir, sizeof(state.path.name) - safe_dir, 0))) { errno = ENOENT; return 0; } if (type & (P_DOTDOT|P_NOSLASH)) { /* * remove trailing slashes */ while (*--ip == '/'); *++ip = 0; } else if ((type & P_SLASH) && *(ip - 1) != '/') *ip++ = '/'; if (*(ip - 1) == '/' && ip - sp > 1) { /* * trailing slash is equivalent to trailing slash-dot * this forces the common-sense interpretation */ #if DEBUG if (!(state.test & 010)) #endif *ip++ = '.'; *ip = 0; } len = ip - sp; /* * try to use relative path */ if (!(type & (P_LSTAT|P_READLINK))) { for (ip = state.pwd; *ip && *ip == *sp++; ip++); if (*ip != 0 || *sp && *sp != '/' || state.level < 0) sp = state.path.name; else { state.path.level += (state.path.synthesize = state.level); if (state.level && !(type & P_PATHONLY) && st == &stbuf) { sp = state.path.name; len -= state.pwdsize; } else if (type & P_ABSOLUTE) sp = state.path.name; else if (*sp == '/') sp++; } if (*sp == 0) sp = state.dot; } skip: if ((type & P_NOOPAQUE) && !LSTAT(sp, st) && checkopaque(sp, st)) { message((-1, "%s: remove opaque", sp)); UNLINK(sp); opaqued = 1; } if (safe && *sp == '/') { state.path.table = safe; cp = pathnext(sp, NiL, NiL); state.path.table = safe = 0; if (cp) { state.path.level = 0; path = strcpy(buf, sp); message((-5, "pathreal: == safe map %s", path)); type &= ~(P_DOTDOT|P_SAFE); goto again; } if (!*(sp + 1)) { strncpy(sp, state.safe->service, safesize); sp[safesize] = 0; } else if (strncmp(sp, state.safe->service, safesize) || sp[safesize] && sp[safesize] != '/') { if (*path != '/' && safe_dir) { errno = EPERM; return 0; } if (sp[1]) strcpy(buf, sp); else *buf = 0; len = sfsprintf(sp, sizeof(state.path.name), "%-*s%s", safesize, state.safe->service, buf); message((-5, "pathreal: == safe next %s", sp)); if (!pathnext(sp, NiL, NiL)) { errno = EPERM; return 0; } } else type &= ~P_SAFE; } if ((type & P_SAFE) && state.path.level) { errno = EPERM; return 0; } if (type & P_PATHONLY) { errno = oerrno; return sp; } visits = 0; vir = 1; while (LSTAT(sp, st)) { if (vir) { if (apath[0] == '.' && apath[1] == '.' && apath[2] == '.' && !apath[3]) { if (state.level > 0) { message((-1, "pathreal: %s => %s", apath, sp)); LSTAT(".", st); return sp; } errno = ENOENT; return 0; } vir = 0; } if (errno == ENOTDIR) { /* * check for version instance */ cp = ip = sp + strlen(sp); while (ip > sp && *--ip != '/'); if (ip < sp) return 0; while (ip > sp && *--ip == '/'); if (ip < sp) return 0; while (ip > sp && *--ip != '/'); if (*ip == '/') ip++; while (cp >= ip) { cp[4] = *cp; cp--; } memcpy(ip, state.opaque, 4); if (!LSTAT(sp, st)) break; errno = ENOTDIR; return 0; } if (errno != ENOENT || opaqued) return 0; #if FS /* * check user mount */ if (visits) { Mount_t* mp; const char* up; if ((mp = getmount(sp, &up)) && (mp->fs->flags & FS_NAME) && (sp = fsreal(mp, MSG_open, (char*)up)) && !LSTAT(sp, st)) break; } #endif /* * search down the viewpath */ if (type & P_SAFE) { errno = EPERM; return 0; } if (!pathnext(state.path.name, NiL, &visits)) return 0; sp = state.path.name; if (!(type & P_ABSOLUTE)) { /* * try to use relative path */ for (ip = state.pwd; *ip && *ip == *sp++; ip++); if (*ip == 0 && *sp == '/') sp++; else sp = state.path.name; } if (*sp == 0) sp = state.dot; } if (st->st_nlink > 1 && checkopaque(sp, st)) return 0; if ((type & P_TOP) && state.path.level) { int rfd; int wfd; if ((rfd = OPEN(sp, O_RDONLY, 0)) < 0) sp = 0; else { tsbuf = *st; wfd = open(apath, O_WRONLY|O_CREAT|O_TRUNC|O_cloexec, st->st_mode & S_IPERM); *st = tsbuf; if (wfd < 0) sp = 0; else { if (fs3d_copy(rfd, wfd, st)) sp = 0; CLOSE(wfd); } CLOSE(rfd); } if (!sp) { errno = EROFS; return 0; } if (st == &stbuf) st = 0; return pathreal(apath, P_PATHONLY, st); } IVIEW(st, state.path.level); if (state.path.synthesize) { if (state.path.level < state.level) { if (len) { ip = state.path.name + strlen(state.path.name) - len; len = *ip; *ip = 0; } if (!CHDIR(state.path.name)) state.level = state.path.level; message((-1, "chdir=%s level=%d", state.path.name, state.level)); *ip = len; } else if (S_ISDIR(st->st_mode)) { int mask; static int uid = -1; static int gid; umask(mask = umask(0)); st->st_mode = (st->st_mode | (S_IRWXU|S_IRWXG|S_IRWXO)) & ~(mask & (S_IRWXU|S_IRWXG|S_IRWXO)); if (uid == -1) { uid = geteuid(); gid = getegid(); } st->st_uid = uid; st->st_gid = gid; } } ip = sp; /* * symbolic links handled specially * get filename from pathname */ if (S_ISLNK(st->st_mode) && (len = checklink(sp, st, type)) > 1 && !(type & (P_LSTAT|P_READLINK)) && state.path.nlinks++ < MAXSYMLINKS) { path = strcpy(buf, state.path.name); message((-1, "pathreal: == again %s", path)); if (*path != '/') state.path.level = 0; type &= ~(P_DOTDOT|P_SAFE); goto again; } #if VCS && defined(VCS_REAL) VCS_REAL(state.path.name, st); #endif errno = oerrno; return sp; }
void main(int argc,char *argv[]) { char *basedir, *p; FILEFINDBUF3 find; HDIR dirhandle; ULONG srch_cnt; int newdrive, urdrive, rootdir, dotdir, dotdotdir; int asking=TRUE, retcode=TRUE; while (--argc) { ++argv; if ((argv[0][0] == '/') || (argv[0][0] == '-')) { switch(toupper(argv[0][1])) { case 'Y': asking = FALSE; break; #ifdef __OS2__ case 'F': forcedel = 1; break; #endif default : printf("Invalid switch - %c\n", argv[0][1]); abort(); } } else break; } if (!argc) { puts("DELTREE2 v1.0\nRequired parameter missing"); abort(); } urdrive = getdisk(); #ifdef __OS2__ DosError(FERR_DISABLEHARDERR); #endif /* Process each command line parameter */ while (argc--) { basedir = *argv++; if (asking) { printf("Delete directory \"%s\" and all its subdirectories? [yn] ", basedir); if (!getyn()) continue; } setdisk(urdrive); srch_cnt = 1; dirhandle = HDIR_CREATE; findret = DosFindFirst(basedir, &dirhandle, MUST_HAVE_DIRECTORY, &find, sizeof(find), &srch_cnt, FIL_STANDARD); if (findret == 0) { #ifndef __OS2__ dirhandle = 1; #endif DosFindClose(dirhandle); } else continue; /* no such directory, goto next argument */ if (basedir[1] == ':') { /* Need to change drives */ newdrive = toupper(basedir[0])-'A'; if (newdrive != urdrive) { setdisk(newdrive); if (newdrive != getdisk()) continue; /* cannot switch drives, goto next argument */ } basedir+=2; } assert (NULL != (p=getcwd(NULL, MAXPATH))); dotdir = !strcmp(basedir, ".") || !strcmp(basedir, p+2); free(p); dotdotdir = !strcmp(basedir, ".."); rootdir = (!strcmp(basedir,"\\") || !strcmp(basedir,"/")); printf("Deleting %s...\n", basedir); if (rootdir) { CHDIR("\\"); retcode &= nextdir(FALSE); } else if (dotdir) { retcode &= nextdir(FALSE); } else if (dotdotdir) { CHDIR(".."); retcode &= nextdir(FALSE); } else { if (CHDIR(basedir)) continue /* cannot change directory - goto next argument */; retcode &= nextdir(FALSE); CHDIR(".."); #ifndef DBG retcode &= (0 == DosDeleteDir(basedir)); #endif } /* goto next argument */ } setdisk(urdrive); exit(retcode ? 0 : 1); }
void qsubMFT(JKArgs& args) { //"jkparser -qsubMFT -curDir=dir -stepLength=int -nStep=int -dConfig=trainConfig -o=ruleFile [-walltime=time] [-pmem=mem] [-queue=node]" string curDir=""; int stepLength=5000; int nStep=6; string dConfig=""; int sleepTime=5; if(!args.is_set("curDir")||!args.is_set("stepLength")|| !args.is_set("nStep")||!args.is_set("dConfig")||!args.is_set("o")) usage(); curDir=args.value("curDir"); stepLength=atoi(args.value("stepLength").c_str()); nStep=atoi(args.value("nStep").c_str()); dConfig=args.value("dConfig"); string output=args.value("o"); int dlevel=atoi(args.value("debug").c_str()); if(args.is_set("sleepTime"))sleepTime=atoi(args.value("sleepTime").c_str()); JKArgs dArgs; dArgs.init(dConfig.c_str()); string walltime="20:00:00"; string pmem="7g"; string queue="isi"; if(args.is_set("walltime")) walltime=args.value("walltime"); if(args.is_set("pmem")) pmem=args.value("pmem"); if(args.is_set("queue")) queue=args.value("queue"); cerr<<"walltime="<<walltime<<endl; string signal="mftsignal"; if(dArgs.is_set("signal"))signal=dArgs.value("signal"); string logerror=output+"-logerror"; vector<string> v_signal,v_logerror,v_log,v_sh; CHDIR(curDir.c_str()); string cmd=""; cmd="cd "+curDir; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); for(int iter=0;iter<nStep;iter++) { int start=stepLength*iter+1; int stop=start+stepLength-1; string range=intToString(start)+"-"+intToString(stop); string n_signal=signal+"."+range; v_signal.push_back(n_signal); string n_logerror=logerror+"."+range; string n_log=output+"."+range; v_logerror.push_back(n_logerror); v_log.push_back(n_log); string fd_cmd="( ./pbmt -config="+dConfig+" -range="+range+" -signal="+n_signal; fd_cmd+=" > "+n_log+" ) >& "+n_logerror; string fd_sh=curDir+"/mft."+range+".sh"; v_sh.push_back(fd_sh); cmd="echo cd "+curDir+" > "+fd_sh; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); cmd="echo \""+fd_cmd+" \" >> "+fd_sh; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); cmd="qsub -l walltime="+walltime+" -l pmem="+pmem+" -q "+queue+" "+fd_sh; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); } while(true) { bool allDone=true; for(int iter=0;iter<nStep;iter++) { ifstream signalFile(v_signal[iter].c_str()); if(!signalFile.good()) allDone=false; signalFile.close(); } if(allDone) break; #ifndef WIN32 sleep(sleepTime); #else Sleep(sleepTime*100); #endif } cmd="rm "+output+" "+logerror; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); cmd="cat "+vectorToString(v_log)+" > "+output; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); cmd="cat "+vectorToString(v_logerror)+" > "+logerror; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); string debugInfo=output+"-debugInfo"; cmd="mkdir "+debugInfo; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); cmd="mv "+vectorToString(v_log)+" "+vectorToString(v_logerror)+" "+vectorToString(v_sh)+" "+vectorToString(v_signal)\ +" *sh.e* *sh.o* "+debugInfo; if(dlevel)cerr<<cmd<<endl; else system(cmd.c_str()); }
boolean TxCache::save(const wchar_t *path, const wchar_t *filename, int config) { if (_cache.empty()) return true; /* dump cache to disk */ char cbuf[MAX_PATH]; osal_mkdirp(path); /* Ugly hack to enable fopen/gzopen in Win9x */ #ifdef OS_WINDOWS wchar_t curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); CHDIR(path); #else char curpath[MAX_PATH]; GETCWD(MAX_PATH, curpath); wcstombs(cbuf, path, MAX_PATH); CHDIR(cbuf); #endif wcstombs(cbuf, filename, MAX_PATH); gzFile gzfp = gzopen(cbuf, "wb1"); DBG_INFO(80, wst("gzfp:%x file:%ls\n"), gzfp, filename); if (gzfp) { /* write header to determine config match */ gzwrite(gzfp, &config, 4); std::map<uint64, TXCACHE*>::iterator itMap = _cache.begin(); int total = 0; while (itMap != _cache.end()) { uint8 *dest = (*itMap).second->info.data; uint32 destLen = (*itMap).second->size; uint32 format = (*itMap).second->info.format; /* to keep things simple, we save the texture data in a zlib uncompressed state. */ /* sigh... for those who cannot wait the extra few seconds. changed to keep * texture data in a zlib compressed state. if the GZ_TEXCACHE or GZ_HIRESTEXCACHE * option is toggled, the cache will need to be rebuilt. */ /*if (format & GL_TEXFMT_GZ) { dest = _gzdest0; destLen = _gzdestLen; if (dest && destLen) { if (uncompress(dest, &destLen, (*itMap).second->info.data, (*itMap).second->size) != Z_OK) { dest = nullptr; destLen = 0; } format &= ~GL_TEXFMT_GZ; } }*/ if (dest && destLen) { /* texture checksum */ gzwrite(gzfp, &((*itMap).first), 8); /* other texture info */ gzwrite(gzfp, &((*itMap).second->info.width), 4); gzwrite(gzfp, &((*itMap).second->info.height), 4); gzwrite(gzfp, &format, 4); gzwrite(gzfp, &((*itMap).second->info.texture_format), 2); gzwrite(gzfp, &((*itMap).second->info.pixel_type), 2); gzwrite(gzfp, &((*itMap).second->info.is_hires_tex), 1); gzwrite(gzfp, &destLen, 4); gzwrite(gzfp, dest, destLen); } itMap++; if (_callback) (*_callback)(wst("Total textures saved to HDD: %d\n"), ++total); } gzclose(gzfp); } CHDIR(curpath); return _cache.empty(); }