Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Writing to Resource Forks


UpdateResFile

You can use the UpdateResFile procedure to update the resource map and resource data for a resource fork without closing it.

PROCEDURE UpdateResFile (refNum: Integer);
refNum
A file reference number for a resource fork.
DESCRIPTION
Given the reference number of a file whose resource fork is open, UpdateResFile performs three tasks. The first task is to change, add, or remove resource data in the
file's resource fork to match the resource map in memory. Changed resource data for each resource is written only if that resource's resChanged bit has been set by a successful call to ChangedResource or AddResource. The UpdateResFile procedure calls the WriteResource procedure to write changed or added resources to the resource fork.

The second task is to compact the resource fork, closing up any empty space created when a resource was removed, made smaller, or made larger. If a resource is made larger, the Resource Manager writes it at the end of the resource fork rather than at its original location. It then compacts the space occupied by the original resource data. The actual size of the resource fork is adjusted when a resource is removed or made larger, but not when a resource is made smaller.

The third task is to write the resource map in memory to the resource fork if your application has called the ChangedResource procedure for any resource listed in the resource map or if it has added or removed a resource. All changes to resource information in the resource map become permanent at this time; if you want any of these changes to be temporary, you must restore the original information before calling UpdateResFile.

If there's no open resource fork with the given reference number, UpdateResFile
does nothing, and the ResError function returns the result code resNotFound. If the value of the refNum parameter is 0, it represents the System file's resource fork. If you call UpdateResFile but the mapReadOnly attribute of the resource fork is set, UpdateResFile does nothing, and the ResError function returns the result code resAttrErr.

Because the CloseResFile procedure calls UpdateResFile before it closes the resource fork, you need to call UpdateResFile directly only if you want to update the file without closing it.

RESULT CODES
noErr0No error
resNotFound-192Resource not found
resAttrErr-198Attribute inconsistent with operation
SEE ALSO
To check for errors, call the ResError function as described on page 1-47.

For an example of the use of UpdateResFile, see Listing 1-11 on page 1-32. For descriptions of the ChangedResource, AddResource, and CloseResFile procedures, see page 1-83, page 1-85, and page 1-104, respectively. The
WriteResource procedure is described next.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996