extern OSErr get_file_spec( FSSpec *spec, short listid, short item, short pathsid) { Str255 itemstr; Str255 pathstr; int i,n; OSErr err; int itemlen,pathlen; getpstr(itemstr,listid,item); err=FSMakeFSSpec(0,0,itemstr,spec); if (err==noErr) { return err; } itemlen=itemstr[0]; n=countstr(pathsid); for (i=0; i<n; i++) { getpstr(pathstr,pathsid,i); pathlen=pathstr[0]; pathstr[0]=pathlen+itemlen; memcpy(pathstr+pathlen+1,itemstr+1,itemlen); err=FSMakeFSSpec(0,0,itemstr,spec); if (err==noErr) { return err; } } return fnfErr; }
void SetBasePath(void) { OSErr error; FSSpec where; //Handle theString; Str255 name; short vRef; long dirID; long nDirID; error = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRef, &dirID); GetIndString(name, kTransportPath, 1); if (name[0] != '0') { error = FSMakeFSSpec(vRef, dirID, name, &where); // First, check to see if the directory exists if (error != noErr) { // Create it error = FSpDirCreate(&where, smSystemScript, &nDirID); } p2cstr(name); strncat((char *)name, "Serial", 63); // It won't matter if this exists or not; we'll get the parent directory ID this way c2pstr((char *)name); error = FSMakeFSSpec(vRef, dirID, name, &where); gvRef = where.vRefNum; gparID = where.parID; } }
short file_attr(const char *path) { #ifdef TARGET_API_MAC_CARBON Str255 fname; FSSpec fss; FSRef fsr; FSCatalogInfo fsci; short ret; mkstr255(fname, path); if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || (FSpMakeFSRef(&fss, &fsr) != noErr) || (FSGetCatalogInfo(&fsr, kFSCatInfoNodeFlags, &fsci, NULL, NULL, NULL) != noErr)) { return(-1); } if (fsci.nodeFlags & kFSNodeIsDirectoryMask) { ret = FILEATTR_DIRECTORY; } else { ret = FILEATTR_ARCHIVE; } if (fsci.nodeFlags & kFSNodeLockedMask) { ret |= FILEATTR_READONLY; } return(ret); #else Str255 fname; FSSpec fss; CInfoPBRec pb; short ret; mkstr255(fname, path); FSMakeFSSpec(0, 0, fname, &fss); pb.dirInfo.ioNamePtr = fss.name; pb.dirInfo.ioVRefNum = fss.vRefNum; pb.dirInfo.ioDrDirID = fss.parID; if (fss.name[0] == 0) { pb.dirInfo.ioFDirIndex = -1; } else { pb.dirInfo.ioFDirIndex = 0; } if (PBGetCatInfo(&pb, false) != noErr) { return(-1); } if (pb.hFileInfo.ioFlAttrib & ioDirMask) { ret = FILEATTR_DIRECTORY; } else { ret = FILEATTR_ARCHIVE; } if (pb.hFileInfo.ioFlAttrib & 0x01) { ret |= FILEATTR_READONLY; } return(ret); #endif }
void CleanTemp(void) { OSErr err = noErr; short vRefNum; long dirID; FSSpec viewerFSp; XPISpec *xpiList, *currXPI = 0, *nextXPI = 0; #ifdef MIW_DEBUG Boolean isDir = false; #endif #ifndef MIW_DEBUG /* get "viewer" in "Temporary Items" folder */ ERR_CHECK(FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &vRefNum, &dirID)); err = FSMakeFSSpec(vRefNum, dirID, kViewerFolder, &viewerFSp); #else /* for DEBUG builds temp is "<currProcessVolume>:Temp NSInstall:" */ ERR_CHECK(GetCWD(&dirID, &vRefNum)); err = FSMakeFSSpec(vRefNum, 0, kTempFolder, &viewerFSp); if (err == fnfErr) return; /* no debug temp exists */ err = FSpGetDirectoryID(&viewerFSp, &dirID, &isDir); if (err != noErr || !isDir) return; err = FSMakeFSSpec(vRefNum, dirID, kViewerFolder, &viewerFSp); #endif /* whack the viewer folder if it exists */ if (err == noErr) { ERR_CHECK(DeleteDirectory(viewerFSp.vRefNum, viewerFSp.parID, viewerFSp.name)); } /* clean out the zippies (.xpi's) */ xpiList = (XPISpec *) NewPtrClear(sizeof(XPISpec)); if (!xpiList) return; IterateDirectory(vRefNum, dirID, "\p", 1, CheckIfXPI, (void*)&xpiList); if (xpiList) { currXPI = xpiList; while(currXPI) { nextXPI = currXPI->next; /* save nextXPI before we blow away currXPI */ if (currXPI->FSp) { FSpDelete(currXPI->FSp); DisposePtr((Ptr)currXPI->FSp); } DisposePtr((Ptr)currXPI); currXPI = nextXPI; } } }
/* This function is an adaptation of the function FSpLocationFromPath in tclMacUtils.c in the Tcl 8.0 distribution */ OSErr FSMakeFSSpecFromPath(ConstStr255Param fileName, FSSpecPtr spec) { Boolean isDir, wasAlias; int pos, end; OSErr err; Str255 Name; short vRefNum; long dirID; /* get the initial directory information and set up first path component */ CopyNamePart(Name, fileName, 1); if (Name[0] < fileName[0] && Name[1] != ':') { /* absolute path */ Name[0]++; Name[Name[0]] = ':'; if ((err = FSMakeFSSpec(0, 0, Name, spec)) != noErr) return err; if ((err = FSpGetDirectoryID(spec, &dirID, &isDir)) != noErr) return err; if (! isDir) return dirNFErr; vRefNum = spec->vRefNum; pos = Name[0] + 1; CopyNamePart(Name, fileName, pos); } else { dirID = 0; vRefNum = 0; pos = 1; isDir = true; } /* process remaining path parts */ end = fileName[0] + 1; while (true) { if ((err = FSMakeFSSpec(vRefNum, dirID, Name[0] == 0 ? NULL : Name, spec)) != noErr || (err = ResolveAliasFile(spec, true, &isDir, &wasAlias)) != noErr) return err; pos += Name[0]; if (pos < end) { if ((err = FSpGetDirectoryID(spec, &dirID, &isDir)) != noErr) return err; if (! isDir) return dirNFErr; vRefNum = spec->vRefNum; CopyNamePart(Name, fileName, pos); } else return noErr; } }
pascal OSErr FSMakeFSSpecCompat(short vRefNum, long dirID, ConstStr255Param fileName, FSSpec *spec) { OSErr result; #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { Boolean isDirectory; result = GetObjectLocation(vRefNum, dirID, fileName, &(spec->vRefNum), &(spec->parID), spec->name, &isDirectory); } else #endif /* !__MACOSSEVENORLATER */ { /* Let the file system create the FSSpec if it can since it does the job */ /* much more efficiently than I can. */ result = FSMakeFSSpec(vRefNum, dirID, fileName, spec); /* Fix a bug in Macintosh PC Exchange's MakeFSSpec code where 0 is */ /* returned in the parID field when making an FSSpec to the volume's */ /* root directory by passing a full pathname in MakeFSSpec's */ /* fileName parameter. Fixed in Mac OS 8.1 */ if ( (result == noErr) && (spec->parID == 0) ) spec->parID = fsRtParID; } return ( result ); }
const FSSpec* Location_Disk_FSSpec::get_FSSpec( void ) const { // If Location was created by Path, we must CONVERT Path to FSSpec. if( !mSpecExists && mpFullPath ) { // char cFullPath[1024]; // u_FromUnicodeToDefaultCP( mpFullPath->c_str(), mpFullPath->length(), cFullPath, 1024 ); const char* cFullPath = mpFullPath->getBufferA(); OSErr err = gUseCarbon ? Path2Spec_Carbon( cFullPath, &mFSSpec ) : Path2Spec_FSRef ( cFullPath, &mFSSpec ); // IF we get error then // Check that may be this is a simple name of file, without full path? // if yes then user want create file in the current directory. if( err ) { if( strchr( cFullPath, I_Disk_Location::sPathDelimiterA ) == NULL ) { vuint8 pasName[256]; FBL::c2pstrcpy( cFullPath, pasName, 256 ); err = FSMakeFSSpec( 0, 0, pasName, &mFSSpec ); } } if( err && err != fnfErr ) throw xOSFileError( (ERROR_TYPE) err ); mSpecExists = true; } return &mFSSpec; }
/*---------------------------------------------------------------------- Called internally to load a code fragment. ----------------------------------------------------------------------*/ OSErr preloadTransport(StringPtr transportName, CFragConnectionID* connID) { OSErr anErr; FSSpec spec; Ptr mainAddr; Str255 errName; Str255 fragName; CFragSymbolClass symClass; // we need to setup our function pointers for the selected // transport. We do this by looking for a file with a code // fragment and then we load all of the function pointers // from it for later use throughout the application // create a pascal string which is the file name which has the // fragment in it anErr = FSMakeFSSpec(gvRef, gparID, transportName, &spec); if (anErr == noErr) { anErr = GetDiskFragment( &spec, 0, kCFragGoesToEOF, fragName, kLoadCFrag, connID, &mainAddr, errName ); } return anErr; }
int __PHYSFS_platformIsSymLink(const char *fname) { OSErr err; FSSpec spec; Boolean a = 0; Boolean f = 0; CInfoPBRec infoPB; char *ptr; char *dir = alloca(strlen(fname) + 1); BAIL_IF_MACRO(dir == NULL, ERR_OUT_OF_MEMORY, 0); strcpy(dir, fname); ptr = strrchr(dir, ':'); if (ptr == NULL) /* just a volume name? Can't be a symlink. */ return(0); /* resolve aliases up to the actual file... */ *ptr = '\0'; BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, NULL, 0); *ptr = strlen(ptr + 1); /* ptr is now a pascal string. Yikes! */ memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; infoPB.dirInfo.ioVRefNum = spec.vRefNum; infoPB.dirInfo.ioDrDirID = spec.parID; infoPB.dirInfo.ioFDirIndex = 0; BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, 0); err = FSMakeFSSpec(spec.vRefNum, infoPB.dirInfo.ioDrDirID, (const unsigned char *) ptr, &spec); BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0); BAIL_IF_MACRO(oserr(IsAliasFile(&spec, &a, &f)) != noErr, NULL, 0); return(a); } /* __PHYSFS_platformIsSymlink */
void *file_list1st(const char *dir, FLINFO *fli) { FLISTH ret; Str255 fname; FSSpec fss; FSRef fsr; FSIterator fsi; mkstr255(fname, dir); if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || (FSpMakeFSRef(&fss, &fsr) != noErr) || (FSOpenIterator(&fsr, kFSIterateFlat, &fsi) != noErr)) { goto ff1_err1; } ret = _MALLOC(sizeof(_FLHDL), dir); if (ret == NULL) { goto ff1_err2; } ((FLHDL)ret)->eoff = FALSE; ((FLHDL)ret)->fsi = fsi; if (file_listnext(ret, fli) == SUCCESS) { return(ret); } ff1_err2: FSCloseIterator(fsi); ff1_err1: return(NULL); }
/*------------------------------------------------------------------- * XPI Stub Load/Unload *-------------------------------------------------------------------*/ OSErr LoadXPIStub(XPI_InitProc* pfnInit, XPI_InstallProc* pfnInstall, XPI_ExitProc* pfnExit, CFragConnectionID* connID, FSSpec& aTargetDir, Str255 errName) { OSErr err; FSSpec fslib; Str63 fragName = XPISTUB_DLL; Ptr mainAddr, symAddr; CFragSymbolClass symClass; long tgtDirID; Boolean isDir; err = FSpGetDirectoryID( &aTargetDir, &tgtDirID, &isDir ); if (err!=noErr) return err; else if (!isDir) return paramErr; err = FSMakeFSSpec(aTargetDir.vRefNum, tgtDirID, fragName, &fslib); if (err!=noErr) return err; err = GetDiskFragment(&fslib, 0, kCFragGoesToEOF, nil, /*kPrivateCFragCopy*/kReferenceCFrag, connID, &mainAddr, errName); if ( err == noErr && *connID != NULL) { ERR_CHECK_RET( FindSymbol(*connID, "\pXPI_Init", &symAddr, &symClass), err ); *pfnInit = (XPI_InitProc) symAddr; ERR_CHECK_RET( FindSymbol(*connID, "\pXPI_Install", &symAddr, &symClass), err); *pfnInstall = (XPI_InstallProc) symAddr; ERR_CHECK_RET( FindSymbol(*connID, "\pXPI_Exit", &symAddr, &symClass), err); *pfnExit = (XPI_ExitProc) symAddr; }
/*__________________________________________________________________________*/ Boolean SaveDriverState (short refnum, StringPtr file, OSType creator, OSType type) { FSSpec spec; OSErr err; TDriverInfos dInfos; long size, dirID; short vrefNum, ref; Ptr ptr; if (FindMidiShareFolder (true, &vrefNum, &dirID) != noErr) return false; if (!MidiGetDriverInfos (refnum, &dInfos)) return false; size = Get1DriverStateSize (dInfos.slots); if (!size) return true; ptr = NewPtrSys(size); if (!ptr) return false; Get1DriverState (refnum, dInfos.slots, ptr, size); err = FSMakeFSSpec(vrefNum, dirID, file, &spec); if (err == fnfErr) err = FSpCreate (&spec, creator, type, smSystemScript); if (err != noErr) goto err; err = FSpOpenDF (&spec, fsWrPerm, &ref); if (err != noErr) goto err; err = FSWrite (ref, &size, ptr); FSClose (ref); DisposePtr (ptr); return err == noErr; err: DisposePtr (ptr); return false; }
extern char* vr_findVerRegName() { FSSpec regSpec; OSErr err; short foundVRefNum; long foundDirID; int bCreate = 0; /* quick exit if we have the info */ if ( verRegName != NULL ) return verRegName; err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); if (err == noErr) { err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, ®Spec); if (err == -43) /* if file doesn't exist */ { err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); bCreate = 1; } if (err == noErr) { Handle thePath; short pathLen; err = FSpGetFullPath(®Spec, &pathLen, &thePath); if (err == noErr && thePath) { /* we have no idea if this moves memory, so better lock the handle */ #if defined(STANDALONE_REGISTRY) || defined(USE_STDIO_MODES) HLock(thePath); verRegName = (char *)XP_ALLOC(pathLen + 1); XP_STRNCPY(verRegName, *thePath, pathLen); verRegName[pathLen] = '\0'; #else /* Since we're now using NSPR, this HAS to be a unix path! */ const char* src; char* dst; HLock(thePath); verRegName = (char*)XP_ALLOC(pathLen + 2); src = *(char**)thePath; dst = verRegName; *dst++ = '/'; while (pathLen--) { char c = *src++; *dst++ = (c == ':') ? '/' : c; } *dst = '\0'; #endif } DisposeHandle(thePath); } } return verRegName; }
static pascal void GetSharedLibraryFilterProc(const CInfoPBRec* const inCpb, Boolean* inWantQuit, void *inFilterData) { GetSharedLibraryFilterProcData* pFilterData = (GetSharedLibraryFilterProcData*) inFilterData; if ((inCpb->hFileInfo.ioFlAttrib & (1 << ioDirFlg)) == 0) { FSSpec fragSpec; OSErr tempErr; Str255 errName; Boolean crap; UInt32 codeOffset; UInt32 codeLength; // it's a file // ¥ fix-me do we really want to allow all 'APPL's' for in which to find this library? switch (inCpb->hFileInfo.ioFlFndrInfo.fdType) { case kCFragLibraryFileType: case 'APPL': tempErr = FSMakeFSSpec(inCpb->hFileInfo.ioVRefNum, inCpb->hFileInfo.ioFlParID, inCpb->hFileInfo.ioNamePtr, &fragSpec); // this shouldn't fail if (noErr != tempErr) { return; } // resolve an alias if this was one tempErr = ResolveAliasFile(&fragSpec, true, &crap, &crap); // if got here we have a shlb (or app-like shlb) if (noErr != tempErr) { // probably couldn't resolve an alias return; } break; default: return; } // see if this symbol is in this fragment if (LibInPefContainer(&fragSpec, pFilterData->inName, &codeOffset, &codeLength)) tempErr = GetDiskFragment(&fragSpec, codeOffset, codeLength, fragSpec.name, kLoadCFrag, &pFilterData->outID, &pFilterData->outAddress, errName); else return; // stop if we found a library by that name if (noErr == tempErr) { *inWantQuit = true; pFilterData->outFound = true; pFilterData->outError = tempErr; } } // FSpIterateDirectory will automagically call us for subsequent sub-dirs if necessary }
DIR * opendir (const char *name) /* Open a directory stream on NAME. */ /* Return a DIR stream on the directory, or NULL if it could not be opened. */ { CInfoPBRec cat_info; FSSpec spec; Boolean targetIsFolder, wasAliased; if (indx) { // We don't support more than one dir open at a time closedir((DIR *)1); // Fail hard return((DIR *)0); } dir_volume=0; // Default to the application directory dir_ID=0; while (name[0]=='.') ++name; // Don't allow leading '.', avoids device names CToPCpy(fname,name); if (!FSMakeFSSpec(0,0,fname,&spec)) { // Figure out where user is pointing ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); cat_info.dirInfo.ioCompletion=(IOCompletionUPP)0; cat_info.dirInfo.ioNamePtr=spec.name; cat_info.dirInfo.ioVRefNum=spec.vRefNum; cat_info.dirInfo.ioFDirIndex = 0; // Use full spec cat_info.dirInfo.ioDrDirID=spec.parID; cat_info.dirInfo.ioFVersNum=0; if (!PBGetCatInfoSync(&cat_info) && (cat_info.dirInfo.ioFlAttrib&16)) spec.parID=cat_info.dirInfo.ioDrDirID; // Found it, save it's volume and dirID dir_volume=spec.vRefNum; dir_ID=spec.parID; } else return ((DIR *)0); indx=1; return((DIR *)1); }
/* This function extracts a single FSRef from a NavReplyRecord. */ static OSErr ExtractSingleItem(const NavReplyRecord *reply, FSRef *item) { FSSpec fss; SInt32 itemCount; DescType junkType; AEKeyword junkKeyword; Size junkSize; OSErr osErr; osErr = AECountItems(&reply->selection, &itemCount); if( itemCount != 1 ) /* we only work with one object at a time */ osErr = paramErr; if( osErr == noErr ) osErr = AEGetNthPtr(&reply->selection, 1, typeFSS, &junkKeyword, &junkType, &fss, sizeof(fss), &junkSize); if( osErr == noErr ) { mycheck(junkType == typeFSS); mycheck(junkSize == sizeof(FSSpec)); /* We call FSMakeFSSpec because sometimes Nav is braindead */ /* and gives us an invalid FSSpec (where the name is empty). */ /* While FSpMakeFSRef seems to handle that (and the file system */ /* engineers assure me that that will keep working (at least */ /* on traditional Mac OS) because of the potential for breaking */ /* existing applications), I'm still wary of doing this so */ /* I regularise the FSSpec by feeding it through FSMakeFSSpec. */ if( fss.name[0] == 0 ) osErr = FSMakeFSSpec(fss.vRefNum, fss.parID, fss.name, &fss); if( osErr == noErr ) osErr = FSpMakeFSRef(&fss, item); } return osErr; }
// -------------------------------------------------------------------------------------- static OSErr getCurrentResourceFSSpec(FSSpec *curResSpec) { OSErr error; FCBPBPtr fileInfo; // file control block parameter block pointer StrFileName fileName; /* In the age of application packages and bundles, it's less likely that the current resource file is the application file itself. It's more likely to be a flattened resource file in a bundle so we need a generic method instead of the traditional Process Manager method of getting the current application's FSSpec of it's executable file */ fileInfo = (FCBPBPtr)NewPtr(sizeof(FCBPBRec)); fileInfo->ioNamePtr = fileName; // to hold the resource file's name fileInfo->ioVRefNum = 0; // 0 to search through all open files on all volumes fileInfo->ioRefNum = CurResFile(); // get info about the main resource file // by using its reference number fileInfo->ioFCBIndx = 0; // 0 to ignore this parameter and use the // ioRefNum parameter instead error = PBGetFCBInfoSync(fileInfo); // synchronous because we don't have // anything else to do while we're waiting on the filesystem if (error == noErr) // if we got the necessary file info, make an FSSpec out of it FSMakeFSSpec(fileInfo->ioFCBVRefNum, fileInfo->ioFCBParID, fileName, curResSpec); DisposePtr((Ptr)fileInfo); return error; }
short file_attr(const char *path) { Str255 fname; FSSpec fss; FSRef fsr; FSCatalogInfo fsci; short ret; mkstr255(fname, path); if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || (FSpMakeFSRef(&fss, &fsr) != noErr) || (FSGetCatalogInfo(&fsr, kFSCatInfoNodeFlags, &fsci, NULL, NULL, NULL) != noErr)) { return(-1); } if (fsci.nodeFlags & kFSNodeIsDirectoryMask) { ret = FILEATTR_DIRECTORY; } else { ret = FILEATTR_ARCHIVE; } if (fsci.nodeFlags & kFSNodeLockedMask) { ret |= FILEATTR_READONLY; } return(ret); }
void _HYPlatformGraphicPane::_SavePicture (_String prompt) { InitializeQTExporters (); if (graphicsFormats.lLength) { _String filePath; long menuChoice = SaveFileWithPopUp (filePath, savePicPrompt,prompt,savePicAs,graphicsFormats); if (menuChoice>=0) { ComponentInstance grexc = OpenComponent ((Component)qtGrexComponents(menuChoice)); GraphicsExportSetInputGWorld (grexc,thePane); FSSpec fs; Str255 buff; StringToStr255 (filePath,buff); FSMakeFSSpec(0,0,buff,&fs); GraphicsExportSetOutputFile (grexc,&fs); GraphicsExportRequestSettings (grexc,nil,nil); unsigned long dummy; OSType t,c; GraphicsExportGetDefaultFileTypeAndCreator (grexc,&t,&c); GraphicsExportSetOutputFileTypeAndCreator (grexc,t,c); GraphicsExportDoExport (grexc,&dummy); CloseComponent (grexc); } } }
OSErr FindPrefs(FSSpec* where) { OSErr error = noErr; Str255 theString; Str255 name; FSSpec spec; short foundVRefNum; long foundDirID; // Look for the prefs in the folder GetIndString(theString, kTransportPath, 1); p2cstr(theString); strncpy(name, theString, 63); strncat(name, "Modem prefs", 63); c2pstr(name); error = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &foundVRefNum, &foundDirID); if (error == noErr) { error = FSMakeFSSpec(foundVRefNum, foundDirID, name, where); if (error == fnfErr) { // May need to create the file FSpCreateResFile(where, 'mwNT', 'pref', smSystemScript); error = ResError(); } } return error; }
string& Configuration::GetExecutablePath() { string& path = new string(""); ProcessSerialNumber PSN; ProcessInfoRec pinfo; FSSpec pspec; FSRef fsr; OSStatus err; // set up process serial number. PSN.highLongOfPSN = 0; PSN.lowLongOfPSN = kCurrentProcess; // set up info block. pinfo.processInfoLength = sizeof(pinfo); pinfo.processName = NULL; pinfo.processAppSpec = &pspec; // grab the vrefnum and directory. err = GetProcessInformation(&PSN, &pinfo); if (! err ) { char c_path[2048]; FSSpec fss2; int tocopy; err = FSMakeFSSpec(pspec.vRefNum, pspec.parID, 0, &fss2); if ( ! err ) { err = FSpMakeFSRef(&fss2, &fsr); if ( ! err ) { char c_path[2049]; err = (OSErr)FSRefMakePath(&fsr, (UInt8*)c_path, 2048); if (! err ) { path += c_path; } } } } return path; }
//path2fss makes an FSSpec from a path with or without a filename int path2fss( FSSpec *fss, char *path ) { char buf[1024]; char *p = &buf[1]; strcpy( p, path ); buf[0] = strlen( p ); return ( FSMakeFSSpec( 0, 0, (unsigned char *)buf, fss ) ); }
static OSStatus strcpyFileSystemRepresentationFromClassicPath(char *nativePath, char * classicPath, long nativePathMaxLength ) { CFURLRef fileAsCFURLRef = 0; Boolean resolveAgainstBase = true; FSRef fileAsFSRef; Boolean gotPath; char pathPStr[256]; FSSpec spec; OSStatus err = 0; strcpy(pathPStr,classicPath); my_c2pstr(pathPStr); err = FSMakeFSSpec(0, 0, (StringPtr)pathPStr,&spec); if(err == fnfErr) { // just means the file does not exist yet err = FSpCreate (&spec,'MPW ','TEXT',smSystemScript); // we should be able to use any creator and type here } if(err) return err; err = FSpMakeFSRef(&spec,&fileAsFSRef); if(err) return err; // Convert the reference to the file to a CFURL fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef); if(fileAsCFURLRef) { gotPath = CFURLGetFileSystemRepresentation(fileAsCFURLRef,resolveAgainstBase,(UInt8 *)nativePath,nativePathMaxLength); CFRelease(fileAsCFURLRef); fileAsCFURLRef = 0; } if(gotPath) return noErr; return -1; // did not get the path }
/* ボリューム番号とディレクトリIDからフルパスを取得する */ static OSErr GetFullPath(short vRefNum, long dirID, UInt8 *pathname) { OSErr err; FSSpec spec; char tmp[257]; int i = 0; UInt8 nullstr[2] = { 0, 0 }; pathname[0] = pathname[1] = 0; spec.vRefNum = vRefNum; spec.parID = dirID; do { err = FSMakeFSSpec(spec.vRefNum, spec.parID, nullstr, &spec); if (noErr == err) { memcpy(tmp, &spec.name[1], spec.name[0]); tmp[spec.name[0]] = 0; if (i > 0) strcat((char*)tmp, ":"); strcat(tmp, (char*)&pathname[1]); pathname[0] = strlen(tmp); strcpy((char*)&pathname[1], tmp); } i++; } while (spec.parID != 1 && noErr == err); return err; }
static void ctl_pass_playing_list(int init_number_of_files, char * /*init_list_of_files*/ []) { EventRecord event; if( init_number_of_files!=0 ){ cmsg(CMSG_FATAL, VERB_NORMAL, "ctl_pass_playing_list: Sorry. Fatal error."); } #ifdef MAC_USE_OMS mac_oms_setup(); #endif { FSSpec spec; OSErr err; err=FSMakeFSSpec(0, 0, MAC_STARTUP_FOLDER_NAME, &spec); if( err==noErr ){ mac_add_fsspec( &spec ); } } gQuit=false; while(!gQuit) { WaitNextEvent(everyEvent, &event, 1,0); mac_HandleEvent(&event); } DoQuit(); }
/* * We don't bother with the usual FSpExchangeFiles dance here because * it doesn't really matter if the old random seed gets lost. */ void write_random_seed(void *data, int len) { short puttyVRefNum; long puttyDirID; OSErr error; FSSpec dstfile; short refnum; long count = len; if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) return; error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", &dstfile); if (error == fnfErr) { /* Set up standard resources */ FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman); refnum = FSpOpenResFile(&dstfile, fsWrPerm); if (ResError() == noErr) { copy_resource('STR ', -16397); CloseResFile(refnum); } } else if (error != noErr) return; if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return; FSWrite(refnum, &count, data); FSClose(refnum); return; }
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { short tmpRef, vRefNum; long dirID; FInfo finderInfo; FSSpec theSpec; Str255 fName; OSErr osErr; long gestaltResponse = 0; /* Check that FSSpec calls are available. */ osErr = Gestalt( gestaltFSAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required"); /* TO DO: add a proper error message to jerror.h. */ /* Check that FindFolder is available. */ osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required."); /* TO DO: add a proper error message to jerror.h. */ osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &vRefNum, &dirID ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable"); /* TO DO: Try putting the temp files somewhere else. */ /* Keep generating file names till we find one that's not in use */ for (;;) { next_file_num++; /* advance counter */ sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num); strcpy ( (Ptr)fName+1, info->temp_name ); *fName = strlen (info->temp_name); osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec ); if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr ) break; } osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); info->tempSpec = theSpec; info->read_backing_store = read_backing_store; info->write_backing_store = write_backing_store; info->close_backing_store = close_backing_store; TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); }
char *__PHYSFS_platformCalcBaseDir(const char *argv0) { FSSpec spec; /* Get the name of the binary's parent directory. */ FSMakeFSSpec(procfsspec.vRefNum, procfsspec.parID, procfsspec.name, &spec); return(convFSSpecToPath(&spec, 0)); } /* __PHYSFS_platformCalcBaseDir */
ImportFileHandle *QTImportPlugin::Open(wxString Filename) { FSSpec inFile; FInfo fileInfo; Movie theMovie = 0; Media theMedia; // Make sure QuickTime is initialized //::EnterMovies(); #ifdef WIN32 char* specFilename = strdup(Filename.GetData()); if (FSMakeFSSpec(0,0,c2pstr(specFilename), &inFile) != noErr) { free(specFilename); return false; } free(specFilename); #else wxMacFilename2FSSpec(Filename, &inFile); #endif OSErr err = FSpGetFInfo(&inFile, &fileInfo); if(err != noErr) return NULL; if (kQTFileTypeSystemSevenSound == fileInfo.fdType) { // TODO: handle this case. it is special because system seven sounds cannot // be opened in place } else { short theRefNum; short theResID = 0; // we want the first movie Boolean wasChanged; // open the movie file err = OpenMovieFile(&inFile, &theRefNum, fsRdPerm); if(err != noErr) return NULL; // instantiate the movie err = NewMovieFromFile(&theMovie, theRefNum, &theResID, NULL, newMovieActive, &wasChanged); CloseMovieFile(theRefNum); if(err != noErr) return NULL; } // get and return the sound track media theMedia = GetMediaFromMovie(theMovie); if(theMedia == NULL) return NULL; return new QTImportFileHandle(theMovie, theMedia); }
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks) { LinkedStringList *ret = NULL, *p = NULL; UInt16 i; UInt16 max; FSSpec spec; CInfoPBRec infoPB; Str255 str255; long dirID; BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, NULL, 0); /* get the dir ID of what we want to enumerate... */ memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; /* name of dir to enum. */ infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of file's volume. */ infoPB.dirInfo.ioDrDirID = spec.parID; /* ID of dir. */ infoPB.dirInfo.ioFDirIndex = 0; /* file (not parent) info. */ BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, NULL); if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) == 0) BAIL_MACRO(ERR_NOT_A_DIR, NULL); dirID = infoPB.dirInfo.ioDrDirID; max = infoPB.dirInfo.ioDrNmFls; for (i = 1; i <= max; i++) { FSSpec aliasspec; Boolean alias = 0; Boolean folder = 0; memset(&infoPB, '\0', sizeof (CInfoPBRec)); str255[0] = 0; infoPB.dirInfo.ioNamePtr = str255; /* store name in here. */ infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of dir's volume. */ infoPB.dirInfo.ioDrDirID = dirID; /* ID of dir. */ infoPB.dirInfo.ioFDirIndex = i; /* next file's info. */ if (PBGetCatInfoSync(&infoPB) != noErr) continue; /* skip this file. Oh well. */ if (FSMakeFSSpec(spec.vRefNum, dirID, str255, &aliasspec) != noErr) continue; /* skip it. */ if (IsAliasFile(&aliasspec, &alias, &folder) != noErr) continue; /* skip it. */ if ((alias) && (omitSymLinks)) continue; /* still here? Add it to the list. */ ret = __PHYSFS_addToLinkedStringList(ret, &p, (const char *) &str255[1], str255[0]); } /* for */ return(ret); } /* __PHYSFS_platformEnumerateFiles */