Important: The information in this document is obsolete and should not be used for new development.
OpenResFile
If theFSpOpenResFile
function is not available, you can use theOpenResFile
function to open a resource fork.
FUNCTION OpenResFile (fileName: Str255): Integer;
fileName
- The name of the file whose resource fork is to be opened.
DESCRIPTION
TheOpenResFile
function opens the resource fork of the file with the name specified by thefileName
parameter in the application's default directory--that is, the directory in which the application is located. It also makes this file the current resource file.Like the
OpenRFPerm
function, theOpenResFile
function takes a filename and opens the resource fork for the file with that name. UnlikeOpenRFPerm
,OpenResFile
does not let you specify the read/write permission of the resource fork the first time it is opened. TheOpenResFile
function is an earlier version of theOpenRFPerm
function.If it finds the specified file in your application's default directory,
OpenResFile
reads the file's resource map into memory and returns a file reference number for the file. It also reads into memory every resource in the resource fork whoseresPreload
attribute is set.You can use the file reference number returned by
OpenResFile
to refer to the file in other Resource Manager routines. If the file's resource fork is already open,OpenResFile
returns the file reference number but does not make that file the current resource file.If the
OpenResFile
function fails to open the specified file's resource fork (for instance, because there's no file with the given name), it returns -1 as the file reference number. Use theResError
function to determine what kind of error occurred.You don't have to call
OpenResFile
to open the System file's resource fork or an application file's resource fork. These resource forks are opened automatically when the system and the application start up, respectively. To get the file reference number for your application, call theCurResFile
function after the application starts up and before you open the resource forks for any other files.The
OpenResFile
function checks that the information in the resource map is internally consistent. If it isn't,ResError
returns the result codemapReadErr
.To open a resource fork just for block-level operations, such as copying files without reading the resource map into memory, use the File Manager function
OpenRF
.SPECIAL CONSIDERATIONS
TheOpenResFile
function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.If you want to open the resource fork for another application (or any resource fork other than your application's that includes
'CODE'
resources), you must bracket your calls toOpenResFile
with calls toSetResLoad
with theload
parameter set toFALSE
and then toTRUE
. You must also avoid making intersegment calls while the other application's resource fork is open. The discussion of this issue in relation toFSpOpenResFile
(page 1-56) also applies toOpenResFile
.ASSEMBLY-LANGUAGE INFORMATION
A handle to the resource map for the most recently opened resource fork is stored in the global variableTopMapHndl
.RESULT CODES
noErr 0 No error nsvErr -35 No such volume ioErr -36 I/O error bdNamErr -37 Bad filename or volume name (perhaps zero length) eofErr -39 End of file tmfoErr -42 Too many files open fnfErr -43 File not found opWrErr -49 File already open with write permission permErr -54 Attempt to open locked file for writing extFSErr -58 Volume belongs to an external file system memFullErr -108 Not enough room in heap zone dirNFErr -120 Directory not found mapReadErr -199 Map inconsistent with operation SEE ALSO
To check for errors, call theResError
function as described on page 1-47.