This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.
The "standard" ANSI C file functions are less than well suited for
the Macintosh way of doing things. However, if you are doing a port for
your own enjoyment and benefit (or maybe for in-house work) you can use
the following function: (see below about converting a wdRefNum into a
vRefNum/parID pair)
*code*
FILE *
fopen_mac ( short vRefNum , long parID , char * fileName , char * mode ) {
short oldVol ;
short aVol ;
long aDir , aProc ;
FILE * ret = NULL ;
if ( GetVol ( NULL , & oldVol ) ) {
return NULL ;
}
if ( GetWDInfo ( oldVol , & aVol , & aDir , & aProc ) ) {
return NULL ;
}
if ( HSetVol ( NULL , vRefNum , parID ) ) {
return NULL ;
}
ret = fopen ( fileName , mode ) ;
if ( HSetVol ( NULL, aVol , aDir ) ) {
/* an error we can't currently handle */
}
if ( SetVol ( NULL, oldVol ) ) {
/* an error we can't currently handle */
}
return ret ;
}
*end*
 
Continue to: