pascal OSErr HCreateMinimum(short vRefNum, long dirID, ConstStr255Param fileName) { HParamBlockRec pb; pb.fileParam.ioNamePtr = (StringPtr)fileName; pb.fileParam.ioVRefNum = vRefNum; pb.ioParam.ioVersNum = 0; pb.fileParam.ioDirID = dirID; return ( PBHCreateSync(&pb) ); }
pascal OSErr FSpCreateCompat(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag) { #if !__MACOSSEVENFIVEONEORLATER OSErr result; UniversalFMPB pb; if ( #if !__MACOSSEVENORLATER (!FSHasFSSpecCalls() && !QTHasFSSpecCalls()) || #endif /* !__MACOSSEVENORLATER */ !HasFSpCreateScriptSupportFix() ) { /* If FSpCreate isn't called, this code will be executed */ pb.hPB.fileParam.ioVRefNum = spec->vRefNum; pb.hPB.fileParam.ioDirID = spec->parID; pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name); pb.hPB.fileParam.ioFVersNum = 0; result = PBHCreateSync(&(pb.hPB)); if ( result == noErr ) { /* get info on created item */ pb.ciPB.hFileInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&(pb.ciPB)); if ( result == noErr ) { /* Set fdScript in FXInfo */ /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */ /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */ /* (smRoman is 0). fdScript is valid if high bit is set (see IM-6, page 9-38) */ pb.ciPB.hFileInfo.ioFlXFndrInfo.fdScript = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); /* Set creator/fileType */ pb.ciPB.hFileInfo.ioFlFndrInfo.fdCreator = creator; pb.ciPB.hFileInfo.ioFlFndrInfo.fdType = fileType; /* Restore ioDirID field in pb which was changed by PBGetCatInfo */ pb.ciPB.hFileInfo.ioDirID = spec->parID; result = PBSetCatInfoSync(&(pb.ciPB)); } } return ( result ); } else #endif /* !__MACOSSEVENFIVEONEORLATER */ { return ( FSpCreate(spec, creator, fileType, scriptTag) ); } }
int __open_file(const char * name, __file_modes mode, __file_handle * handle) { FSSpec spec; OSErr ioResult; HParamBlockRec pb; ioResult = __path2fss(name, &spec); if (ioResult) gSqueakFileLastError = ioResult; if (__system7present()) /* mm 980424 */ { /* mm 980424 */ Boolean targetIsFolder, wasAliased; /* mm 980424 */ ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); /* mm 980424 */ } /* mm 980424 */ if (ioResult && (ioResult != fnfErr || mode.open_mode == __must_exist)) return(__io_error); #if TARGET_API_MAC_CARBON if (ioResult) { CFStringRef filePath; CFURLRef sillyThing, sillyThing2; FSRef parentFSRef; short int fileRefNum; OSErr err; UniChar buffer[1024]; long tokenLength; filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)name,strlen(name),gCurrentVMEncoding,false); if (filePath == nil) return __io_error; sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); CFRelease(filePath); sillyThing2 = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault,sillyThing); err = CFURLGetFSRef(sillyThing2,&parentFSRef); if (err == 0) { CFRelease(sillyThing); CFRelease(sillyThing2); return fnfErr; } filePath = CFURLCopyLastPathComponent(sillyThing); tokenLength = CFStringGetLength(filePath); if (tokenLength > 1024) { CFRelease(filePath); CFRelease(sillyThing); CFRelease(sillyThing2); return(__io_error); } CFStringGetCharacters(filePath,CFRangeMake(0,tokenLength),buffer); CFRelease(filePath); CFRelease(sillyThing); CFRelease(sillyThing2); ioResult = FSCreateFileUnicode(&parentFSRef,tokenLength,buffer,kFSCatInfoNone,NULL,NULL,&spec); if (ioResult) gSqueakFileLastError = ioResult; if (ioResult) return(__io_error); pb.ioParam.ioNamePtr = spec.name; pb.ioParam.ioVRefNum = spec.vRefNum; pb.ioParam.ioPermssn = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm; pb.ioParam.ioMisc = 0; pb.fileParam.ioFVersNum = 0; pb.fileParam.ioDirID = spec.parID; set_file_type(&spec, mode.binary_io); ioResult = PBHOpenDFSync(&pb); /* HH 10/25/97 was PBHOpenSync */ if (ioResult) return(__io_error); *handle = pb.ioParam.ioRefNum; return(__no_io_error); } #endif pb.ioParam.ioNamePtr = spec.name; pb.ioParam.ioVRefNum = spec.vRefNum; pb.ioParam.ioPermssn = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm; pb.ioParam.ioMisc = 0; pb.fileParam.ioFVersNum = 0; pb.fileParam.ioDirID = spec.parID; if (ioResult) { if (!(ioResult = PBHCreateSync(&pb))) { if (ioResult) gSqueakFileLastError = ioResult; set_file_type(&spec, mode.binary_io); ioResult = PBHOpenDFSync(&pb); /* HH 10/25/97 was PBHOpenSync */ if (ioResult) gSqueakFileLastError = ioResult; } } else { if (!(ioResult = PBHOpenDFSync(&pb)) && mode.open_mode == __create_or_truncate) /* HH 10/25/97 was PBHOpenSync */ { pb.ioParam.ioMisc = 0; ioResult = PBSetEOFSync((ParmBlkPtr) &pb); if (ioResult) gSqueakFileLastError = ioResult; if (ioResult) PBCloseSync((ParmBlkPtr) &pb); } else { if (ioResult) gSqueakFileLastError = ioResult; } } if (ioResult) return(__io_error); *handle = pb.ioParam.ioRefNum; return(__no_io_error); }
/* * int open(const char *path, int oflag) * * Opens a file stream. */ int my_open(char *path, int oflag) { FSSpec spec; char permission; HParamBlockRec hpb; OSErr err, errno; Boolean targetIsFolder, wasAliased; AssertStr(path,path) /* Setup permission */ if ((oflag & 0x03) == O_RDWR) permission = fsRdWrPerm; else permission = (oflag & O_RDONLY) ? fsRdPerm : 0 + (oflag & O_WRONLY) ? fsWrPerm : 0; FSpLocationFromFullPath(strlen(path),path, &spec); if ((oflag & (O_ALIAS | O_NRESOLVE)) == 0) ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); hpb.fileParam.ioNamePtr = spec.name; hpb.fileParam.ioVRefNum = spec.vRefNum; hpb.fileParam.ioDirID = spec.parID; hpb.ioParam.ioPermssn = permission; if (oflag & O_RSRC) /* open the resource fork of the file */ err = PBHOpenRFSync(&hpb); else /* open the data fork of the file */ err = PBHOpenDFSync(&hpb); if ((err == fnfErr) && (oflag & O_CREAT)) { hpb.fileParam.ioFlVersNum = 0; err = PBHCreateSync(&hpb); if (err == noErr) { /* Set the finder info */ unsigned long secs; unsigned long isbinary = oflag & O_BINARY; hpb.fileParam.ioFlFndrInfo.fdType = '\?\?\?\?'; hpb.fileParam.ioFlFndrInfo.fdCreator = '\?\?\?\?'; hpb.fileParam.ioFlFndrInfo.fdFlags = 0; if (oflag & O_ALIAS) /* set the alias bit */ hpb.fileParam.ioFlFndrInfo.fdFlags = kIsAlias; else /* clear all flags */ hpb.fileParam.ioFlFndrInfo.fdFlags = 0; GetDateTime(&secs); hpb.fileParam.ioFlCrDat = hpb.fileParam.ioFlMdDat = secs; PBHSetFInfoSync(&hpb); } if (err && (err != dupFNErr)) { errno = err; return -1; } if (oflag & O_RSRC) /* open the resource fork of the file */ err = PBHOpenRFSync(&hpb); else /* open the data fork of the file */ err = PBHOpenDFSync(&hpb); } if (err && (err != dupFNErr) && (err != opWrErr)) { errno = err; return -1; } if (oflag & O_TRUNC) { IOParam pb; pb.ioRefNum = hpb.ioParam.ioRefNum; pb.ioMisc = 0L; err = PBSetEOFSync((ParmBlkPtr)&pb); if (err != noErr) { errno = err; return -1; } } if (oflag & O_APPEND) lseek(hpb.ioParam.ioRefNum,0,SEEK_END); return (hpb.ioParam.ioRefNum); }