chdir.c 888 Bytes
Newer Older
1 2 3 4 5 6
/* Chdir for the Macintosh.
   Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
   Pathnames must be Macintosh paths, with colons as separators. */

#include "macdefs.h"

Jack Jansen's avatar
Jack Jansen committed
7 8 9 10
#ifdef __MWERKS__
/* XXXX All compilers should use this, really */
#include <LowMem.h>
#else
11 12 13
/* Last directory used by Standard File */
#define SFSaveDisk	(*(short *)0x214)
#define CurDirStore (*(long *)0x398)
Jack Jansen's avatar
Jack Jansen committed
14
#endif
15

16 17 18 19 20 21 22 23
/* Change current directory. */

int
chdir(path)
	char *path;
{
	WDPBRec pb;
	
24
	pb.ioNamePtr= (StringPtr) Pstring(path);
25 26 27 28 29 30
	pb.ioVRefNum= 0;
	pb.ioWDDirID= 0;
	if (PBHSetVol(&pb, FALSE) != noErr) {
		errno= ENOENT;
		return -1;
	}
31 32
	if (PBHGetVol(&pb, FALSE) == noErr) {
		/* Set the Standard File directory */
Jack Jansen's avatar
Jack Jansen committed
33 34 35 36
#ifdef __MWERKS__
		LMSetSFSaveDisk(-pb.ioWDVRefNum);
		LMSetCurDirStore(pb.ioWDDirID);
#else
37 38
		SFSaveDisk= -pb.ioWDVRefNum;
		CurDirStore= pb.ioWDDirID;
Jack Jansen's avatar
Jack Jansen committed
39
#endif
40
	}
41 42
	return 0;
}