📄 ncbi_os_mac.cpp
字号:
pb.hFileInfo.ioNamePtr = (StringPtr) &items->name; pb.hFileInfo.ioDirID = theDirID; pb.hFileInfo.ioFDirIndex = *itemIndex; error = PBGetCatInfoSync(&pb); if ( error == noErr ) { items->parID = pb.hFileInfo.ioFlParID; /* return item's parID */ items->vRefNum = pb.hFileInfo.ioVRefNum; /* return item's vRefNum */ ++*itemIndex; /* prepare to get next item in directory */ if ( (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 ) { if ( getDirectories ) { ++*actItemCount; /* keep this item */ ++items; /* point to next item */ } } else { if ( getFiles ) { ++*actItemCount; /* keep this item */ ++items; /* point to next item */ } } } } } else { /* it wasn't a directory */ error = dirNFErr; } } } } else { /* bad itemIndex */ error = paramErr; } return ( error );}static OSErr FSpGetFullPath(const FSSpec *spec, short *fullPathLength, Handle *fullPath){ OSErr result; OSErr realResult; FSSpec tempSpec; CInfoPBRec pb; *fullPathLength = 0; *fullPath = NULL; /* Default to noErr */ realResult = result = noErr; /* work around Nav Services "bug" (it returns invalid FSSpecs with empty names) */ if ( spec->name[0] == 0 ) { result = FSMakeFSSpec(spec->vRefNum, spec->parID, spec->name, &tempSpec); } else { /* Make a copy of the input FSSpec that can be modified */ BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); } if ( result == noErr ) { if ( tempSpec.parID == fsRtParID ) { /* The object is a volume */ /* Add a colon to make it a full pathname */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* We're done */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); } else { /* The object isn't a volume */ /* Is the object a file or a directory? */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrDirID = tempSpec.parID; pb.dirInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&pb); // Allow file/directory name at end of path to not exist. realResult = result; if ( (result == noErr) || (result == fnfErr) ) { /* if the object is a directory, append a colon so full pathname ends with colon */ if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 ) { ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; } /* Put the object name in first */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); if ( result == noErr ) { /* Get the ancestor directory names */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrParID = tempSpec.parID; do /* loop until we have an error or find the root directory */ { pb.dirInfo.ioFDirIndex = -1; pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; result = PBGetCatInfoSync(&pb); if ( result == noErr ) { /* Append colon to directory name */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* Add directory name to beginning of fullPath */ (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], tempSpec.name[0]); result = MemError(); } } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) ); } } } } if ( result == noErr ) { /* Return the length */ *fullPathLength = GetHandleSize(*fullPath); result = realResult; // return realResult in case it was fnfErr } else { /* Dispose of the handle and return NULL and zero length */ if ( *fullPath != NULL ) { DisposeHandle(*fullPath); } *fullPath = NULL; *fullPathLength = 0; } return ( result );}extern OSErr MacPathname2FSSpec(const char *inPathname, FSSpec *outFSS){ OSErr err; size_t len; char *p; short vRefNum; long dirID; FSSpec fss; if (inPathname == NULL || outFSS == NULL) { return paramErr; } err = HGetVol(NULL, &vRefNum, &dirID); // default volume and directory if (err != noErr) return err; len = strlen(inPathname); p = strchr(inPathname, ':'); if (p == inPathname && len == 1) { err = FSMakeFSSpec(vRefNum, dirID, "\p", outFSS); return err; } if (p == NULL) { // Partial pathname -- filename only Str31 filename; assert(len <= 31); Pstrcpy(filename, inPathname); err = FSMakeFSSpec(vRefNum, dirID, filename, outFSS); } else { Str31 name; int nameLen; if (inPathname[0] == ':') { // Relative pathname including directory path } else { // Absolute pathname //Str31 volName; // We would use Str28 if it was defined -- 27, plus 1 for ':'. nameLen = p - inPathname; assert(nameLen <= 27); name[0] = nameLen + 1; memcpy(name + 1, inPathname, nameLen + 1); // Copy the volume name and the colon. err = DetermineVRefNum(name, 0, &vRefNum); if (err != noErr) return err; dirID = 2; } // vRefNum and dirID now specify the directory in which we should descend // the path pointed to by p (pointing to the first colon). p++; while (p != NULL && *p != '\0') { char *q = strchr(p, ':'); if (q != NULL) { Boolean isDir; nameLen = q - p; assert(nameLen <= 31); name[0] = nameLen; memcpy(name + 1, p, nameLen); err = FSMakeFSSpec(vRefNum, dirID, name, &fss); if (err != noErr) return err; if (q[1] == '\0') { p = NULL; *outFSS = fss; } else { err = FSpGetDirectoryID(&fss, &dirID, &isDir); assert(isDir == true); if (err != noErr) return err; p = q + 1; } } else { q = strchr(p, '\0'); // go to end of string nameLen = q - p; assert(nameLen > 0); assert(nameLen <= 31); Pstrcpy(name, p); p = NULL; err = FSMakeFSSpec(vRefNum, dirID, name, outFSS); } } } return err;}extern OSErr MacFSSpec2FullPathname(const FSSpec *inFSS, char **outPathname){ OSErr err; Handle h; short fullPathLength; static char *fullPath = NULL; if (fullPath != NULL) { delete [] fullPath; fullPath = NULL; } err = FSpGetFullPath(inFSS, &fullPathLength, &h); if (err != noErr) return err; assert(fullPathLength >= 2); // An absolute pathname must be at least two chars long fullPath = new char [fullPathLength + 1]; if (fullPath == NULL) { err = memFullErr; } else { memmove(fullPath, *h, fullPathLength); fullPath[fullPathLength] = '\0'; } DisposeHandle(h); *outPathname = fullPath; return err;}END_NCBI_SCOPE/* -------------------------------------------------------------------------- * $Log: ncbi_os_mac.cpp,v $ * Revision 1000.1 2004/06/01 19:08:33 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * * Revision 1.8 2004/05/14 13:59:26 gorelenk * Added include of ncbi_pch.hpp * * Revision 1.7 2003/05/23 20:34:14 lavr * Show permitting Apple's notice about changes in original "MoreFiles" code * * Revision 1.6 2003/05/23 20:22:59 ucko * Correct author list; include Jim Luther, who wrote the MoreFiles code. * * Revision 1.4 2003/02/27 22:03:59 lebedev * COSErrException_Mac changed from runtime_error to exception * * Revision 1.3 2001/12/18 21:40:39 juran * Copy in MoreFiles fucntions that we need. * * Revision 1.2 2001/12/03 22:00:55 juran * Add g_Mac_SpecialEnvironment global. * * Revision 1.1 2001/11/19 18:11:08 juran * Implements Mac OS-specific header. * Inital check-in. * * ========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -