Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 1 - Introduction to File Management / Using Files

Testing for File Management Routines

To determine the availability of the routines that operate on FSSpec records, you can call the Gestalt function with the gestaltFSAttr selector code, as illustrated in Listing 1-2.

Listing 1-2 Testing for the availability of routines that operate on FSSpec records

FUNCTION FSSpecRoutinesAvail: Boolean;
   myErr:         OSErr;      {Gestalt result code}
   myFeature:     LongInt;    {Gestalt response}
   FSSpecRoutinesAvail := FALSE;
   IF gHasGestalt THEN        {if Gestalt is available}
         myErr := Gestalt(gestaltFSAttr, myFeature);
         IF myErr = noErr THEN
            IF BTst(myFeature, gestaltHasFSSpecCalls) THEN
               FSSpecRoutinesAvail := TRUE;
To use the procedures defined in the following sections to open and save files, you
also need to make sure that the routines StandardGetFile and StandardPutFile are available. You can do this by passing Gestalt the gestaltStandardFileAttr selector and verifying that the bit gestaltStandardFile58 is set in the response value. Also, before using the FindFolder function (as shown, for example, in
Listing 1-10 on page 1-25), you should call the Gestalt function with the gestaltFindFolderAttr selector and verify that the gestaltFindFolderPresent bit is set; this indicates that the FindFolder function is available.

If the routines that operate on FSSpec records are not available, you can use corresponding File Manager and Standard File Package routines. For example, if
you cannot call FSpOpenDF, you can call HOpenDF. That is, instead of writing

myErr := FSpOpenDF(mySpec, fsCurPerm, myFile);
you can write something like

myErr := HOpenDF(myVol, myDirID, myName, fsCurPerm, myFile);
The only difference is that the mySpec parameter is replaced by three parameters specifying the volume reference number, the parent directory ID, and the filename. With only a few exceptions, all of the techniques presented in this chapter can be easily adapted to work with high-level HFS routines in place of the routines that work with FSSpec records.

One notable exception concerns the Standard File Package procedures SFGetFile and SFPutFile. The vRefNum field of the reply
record passed to both these functions contains a working directory reference number, which encodes both the directory ID and the
volume reference number. In general, you should avoid using this number; instead you can turn it into the corresponding directory ID and volume reference number by calling the GetWDInfo function. See the
chapter "File Manager" in this book for details on working directory reference numbers.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996