Important: The information in this document is obsolete and should not be used for new development.
SetResourceSize
You can use theSetResourceSizeprocedure to change the size of a resource on disk. This procedure is normally used only withReadPartialResourceandWritePartialResource.
PROCEDURE SetResourceSize (theResource: Handle; newSize: LongInt);
theResource- A handle to a resource.
newSize- The size, in bytes, that you want the resource to occupy on disk.
DESCRIPTION
Given a handle to a resource,SetResourceSizesets the size field of the specified resource on disk without writing the resource data. You can change the size of
any resource, regardless of the amount of memory you have available.If the specified size is smaller than the resource's current size on disk, you lose any data from the cutoff point to the end of the resource. If the specified size is larger than the resource's current size on disk, all data is preserved, but the additional area is uninitialized (arbitrary data).
If you read a partial resource into memory and then change its size, you must use
SetResourceSizeto change the entire resource's size on disk as necessary. For example, suppose the entire resource occupies 1 MB and you useReadPartialResourceto read in a 200 KB portion of the resource. If you then increase the size of this partial resource to 250 KB, you must callSetResourceSizeto set the size of the resource on disk to 1.05 MB. Note that in this case you must also keep track of the resource data on disk and move any data that follows the original partial resource on disk. Otherwise, there will be no space for the additional 50 KB when you callWritePartialResourceto write the modified partial resource to disk.Under certain circumstances, the Resource Manager overrides the size you set with a call to
SetResourceSize. For instance, suppose you read an entire resource into memory by callingGetResourceor related routines, then useSetResourceSizesuccessfully to set the resource size on disk, and finally attempt to write the resource to disk usingUpdateResFileorWriteResource. In this case, the Resource Manager adjusts the resource size on disk to conform with the size of the resource in memory.If the disk is locked or full, or the file is locked, the
SetResourceSizeprocedure does nothing, and theResErrorfunction returns an appropriate File Manager result code. If the resource is in memory, the Resource Manager tries to set the size of the resource on disk. If the attempt succeeds,ResErrorreturns the result coderesourceInMemory, and the Resource Manager does not update the copy in memory. If the attempt fails,ResErrorreturns an appropriate File Manager result code.SPECIAL CONSIDERATIONS
TheSetResourceSizeprocedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector forSetResourceSizeare
Trap macro Selector _ResourceDispatch $7003 RESULT CODES
noErr 0 No error resourceInMemory -188 Resource already in memory writingPastEnd -189 Writing past end of file SEE ALSO
To check for errors, call theResErrorfunction as described on page 1-47.