static PGPError sRenameProc( PFLFileSpecRef ref, const char * newName) { PGPError err = kPGPError_NoErr; MyData * myData = GetMyData( ref ); PGPUInt32 nameLength; Str255 pascalName; if ( myData->specIsValid ) { nameLength = strlen( newName ); PGPValidateParam( nameLength <= 31 ); pgpCopyMemory( newName, &pascalName[ 1 ], nameLength ); pascalName[ 0 ] = nameLength; err = FSpRename( &myData->spec, pascalName ); if ( IsntPGPError( err ) ) { err = sSetNameProc( ref, newName ); } else if ( err == fnfErr ) err = kPGPError_FileNotFound; else err = kPGPError_FileOpFailed; } else { err = kPGPError_FileNotFound; } return( err ); }
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); }
pascal OSErr FSpRenameCompat(const FSSpec *spec, ConstStr255Param newName) { #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { HParamBlockRec pb; pb.ioParam.ioVRefNum = spec->vRefNum; pb.fileParam.ioDirID = spec->parID; pb.ioParam.ioNamePtr = (StringPtr) &(spec->name); pb.ioParam.ioVersNum = 0; pb.ioParam.ioMisc = (Ptr) newName; return ( PBHRenameSync(&pb) ); } else #endif /* !__MACOSSEVENORLATER */ { return ( FSpRename(spec, newName) ); } }
P2 (PUBLIC pascal trap, OSErr, FSpExchangeFiles, FSSpecPtr, src, FSSpecPtr, dst) { #if 0 save_fcb_info_t *src_fcb_info, *dst_fcb_info; OSErr retval; src_fcb_info = get_fcb_info (src); dst_fcb_info = get_fcb_info (dst); retval = exchange_forks (src, dst, datafork); if (retval == noErr) { retval = exchange_forks (src, dst, resourcefork); if (retval != noErr) exchange_forks (src, dst, datafork); /* try to put things back together */ } if (retval == noErr) exchange_fcbs (src, src_fcb_info, dst, dst_fcb_info); else { restore_fcb (src_fcb_info); restore_fcb (dst_fcb_info); } release_fcb_info (src_fcb_info); release_fcb_info (dst_fcb_info); return retval; #else OSErr retval; warning_unimplemented ("poorly implemented"); if (src->vRefNum != dst->vRefNum) retval = diffVolErr; else if (ROMlib_creator != TICK("PAUP") || src->parID != dst->parID) retval = wrgVolTypeErr; else { /* Evil hack to get PAUP to work -- doesn't bother adjusting FCBs */ FSSpec tmp_spec; int i; i = 0; tmp_spec = *dst; do { create_temp_name (tmp_spec.name, i++); retval = FSpRename (dst, tmp_spec.name); } while (retval == dupFNErr); if (retval == noErr) { retval = FSpRename (src, dst->name); if (retval != noErr) FSpRename (&tmp_spec, dst->name); else { retval = FSpRename (&tmp_spec, src->name); if (retval != noErr) { FSpRename (dst, src->name); FSpRename (&tmp_spec, dst->name); } } } } return retval; #endif }