blob: 056080052f2c44d6d571af16341cd627da0f676f [file] [log] [blame]
Guido van Rossumd4d77281994-08-19 10:51:31 +00001/* Chdir for the Macintosh.
2 Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
3 Pathnames must be Macintosh paths, with colons as separators. */
4
5#include "macdefs.h"
6
Jack Jansen23ebeba1995-07-28 11:44:29 +00007#ifdef __MWERKS__
8/* XXXX All compilers should use this, really */
9#include <LowMem.h>
10#else
Guido van Rossumbcf3b561995-02-20 23:41:35 +000011/* Last directory used by Standard File */
12#define SFSaveDisk (*(short *)0x214)
13#define CurDirStore (*(long *)0x398)
Jack Jansen23ebeba1995-07-28 11:44:29 +000014#endif
Guido van Rossumbcf3b561995-02-20 23:41:35 +000015
Guido van Rossumd4d77281994-08-19 10:51:31 +000016/* Change current directory. */
17
18int
19chdir(path)
20 char *path;
21{
22 WDPBRec pb;
Guido van Rossumd4d77281994-08-19 10:51:31 +000023
Jack Jansen67132b31995-01-18 13:55:41 +000024 pb.ioNamePtr= (StringPtr) Pstring(path);
Guido van Rossumd4d77281994-08-19 10:51:31 +000025 pb.ioVRefNum= 0;
26 pb.ioWDDirID= 0;
27 if (PBHSetVol(&pb, FALSE) != noErr) {
28 errno= ENOENT;
29 return -1;
30 }
Guido van Rossumbcf3b561995-02-20 23:41:35 +000031 if (PBHGetVol(&pb, FALSE) == noErr) {
32 /* Set the Standard File directory */
Jack Jansen23ebeba1995-07-28 11:44:29 +000033#ifdef __MWERKS__
34 LMSetSFSaveDisk(-pb.ioWDVRefNum);
35 LMSetCurDirStore(pb.ioWDDirID);
36#else
Guido van Rossumbcf3b561995-02-20 23:41:35 +000037 SFSaveDisk= -pb.ioWDVRefNum;
38 CurDirStore= pb.ioWDDirID;
Jack Jansen23ebeba1995-07-28 11:44:29 +000039#endif
Guido van Rossumbcf3b561995-02-20 23:41:35 +000040 }
Guido van Rossumd4d77281994-08-19 10:51:31 +000041 return 0;
42}