[comp.sys.mac.programmer] Using StdFilePkg to get file for stdio functions?

bernard@boulder.colorado.edu (Bernie Bernstein) (06/22/89)

Using Think's Lightspeed C.

I am porting some code from another system which uses the standard
C library for I/O.  I would like continue to use them, but would also
like to change the function which asks for the pathnames by 
using the SFGetFile and SFPutFile functions.

I have had no problem getting the vol ref number and
filename, but in order to fopen the file, it requires a pathname.
I read an article recently which said one way of getting the full
pathname, but that seems cumbersome.

Is there a better way to access mac files using the stdio functions
in Lightspeed C using vRefNum and fName?

Any Ideas will be helpful.

Thanks,



Bernie Bernstein                        bernard@boulder.colorado.edu
                                                   -or-
University of Colorado, Boulder         ..!{hao|nbires}!boulder!bernard

beard@ux1.lbl.gov (Patrick C Beard) (06/23/89)

In article <9622@boulder.Colorado.EDU> bernard@tigger.colorado.edu (Bernie Bernstein) writes:
>I am porting some code from another system which uses the standard
>C library for I/O.  I would like continue to use them, but would also
>like to change the function which asks for the pathnames by 
>using the SFGetFile and SFPutFile functions.
>
>I have had no problem getting the vol ref number and
>filename, but in order to fopen the file, it requires a pathname.
>
>Is there a better way to access mac files using the stdio functions
>in Lightspeed C using vRefNum and fName?

Yes.  The stdio functions (Think C's) assume that the file is in the
default directory.  The vol ref returned by the Standard File Package
is actually a working directory number, in fact for the directory that
the user chooses the file in.  So, to open the file, just use:

FILE*
open_file(fName, vRefNum, mode)
StringPtr fName;	/* pascal string name of file */
short vRefNum;		/* working directory number */
char* mode;			/* mode, i.e. "r", or "w", or "wb" ... */
{
	FILE* theFile;

	SetVol(nil, vRefNum);	/* set directory to specified working directory */
	theFile=fopen(PtoCstr(fName), mode);
	CtoPstr(fName);			/* keep it a pascal string if you want to. */

	return theFile;
}

I am pretty sure this will work, I've done similar things before.  I just
wrote this from memory.

Good luck,
__________________

   Patrick Beard
  PCBeard@lbl.gov
 BSI, Berkeley, CA
___________________