pascal OSErr FSpCatMoveCompat(const FSSpec *source, const FSSpec *dest) { #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { CMovePBRec pb; /* source and destination volume must be the same */ if ( source->vRefNum != dest->vRefNum ) return ( paramErr ); pb.ioNamePtr = (StringPtr) &(source->name); pb.ioVRefNum = source->vRefNum; pb.ioDirID = source->parID; pb.ioNewDirID = dest->parID; pb.ioNewName = (StringPtr) &(dest->name); return ( PBCatMoveSync(&pb) ); } else #endif /* !__MACOSSEVENORLATER */ { return ( FSpCatMove(source, dest) ); } }
extern int nr_RenameFile(char *from, char *to) { OSErr err = -1; FSSpec fromSpec; FSSpec toSpec; FSSpec destDirSpec; FSSpec beforeRenameSpec; #ifdef STANDALONE_REGISTRY errno = 0; /* reset errno (only if we're using stdio) */ #endif if (from && to) { err = FSpLocationFromFullPath(XP_STRLEN(from), from, &fromSpec); if (err != noErr) goto exit; err = FSpLocationFromFullPath(XP_STRLEN(to), to, &toSpec); if (err != noErr && err != fnfErr) goto exit; /* make an FSSpec for the destination directory */ err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, nil, &destDirSpec); if (err != noErr) goto exit; /* parent directory must exist */ /* move it to the directory specified */ err = FSpCatMove(&fromSpec, &destDirSpec); if (err != noErr) goto exit; /* make a new FSSpec for the file or directory in its new location */ err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, fromSpec.name, &beforeRenameSpec); if (err != noErr) goto exit; /* rename the file or directory */ err = FSpRename(&beforeRenameSpec, toSpec.name); } exit: #ifdef STANDALONE_REGISTRY if (err != noErr) errno = err; #endif return (err == noErr ? 0 : -1); }