Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 1 | /* 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 Jansen | 23ebeba | 1995-07-28 11:44:29 +0000 | [diff] [blame] | 7 | #ifdef __MWERKS__ |
| 8 | /* XXXX All compilers should use this, really */ |
| 9 | #include <LowMem.h> |
| 10 | #else |
Guido van Rossum | bcf3b56 | 1995-02-20 23:41:35 +0000 | [diff] [blame] | 11 | /* Last directory used by Standard File */ |
| 12 | #define SFSaveDisk (*(short *)0x214) |
| 13 | #define CurDirStore (*(long *)0x398) |
Jack Jansen | 23ebeba | 1995-07-28 11:44:29 +0000 | [diff] [blame] | 14 | #endif |
Guido van Rossum | bcf3b56 | 1995-02-20 23:41:35 +0000 | [diff] [blame] | 15 | |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 16 | /* Change current directory. */ |
| 17 | |
| 18 | int |
| 19 | chdir(path) |
| 20 | char *path; |
| 21 | { |
| 22 | WDPBRec pb; |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 23 | |
Jack Jansen | 67132b3 | 1995-01-18 13:55:41 +0000 | [diff] [blame] | 24 | pb.ioNamePtr= (StringPtr) Pstring(path); |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 25 | pb.ioVRefNum= 0; |
| 26 | pb.ioWDDirID= 0; |
| 27 | if (PBHSetVol(&pb, FALSE) != noErr) { |
| 28 | errno= ENOENT; |
| 29 | return -1; |
| 30 | } |
Guido van Rossum | bcf3b56 | 1995-02-20 23:41:35 +0000 | [diff] [blame] | 31 | if (PBHGetVol(&pb, FALSE) == noErr) { |
| 32 | /* Set the Standard File directory */ |
Jack Jansen | 23ebeba | 1995-07-28 11:44:29 +0000 | [diff] [blame] | 33 | #ifdef __MWERKS__ |
| 34 | LMSetSFSaveDisk(-pb.ioWDVRefNum); |
| 35 | LMSetCurDirStore(pb.ioWDDirID); |
| 36 | #else |
Guido van Rossum | bcf3b56 | 1995-02-20 23:41:35 +0000 | [diff] [blame] | 37 | SFSaveDisk= -pb.ioWDVRefNum; |
| 38 | CurDirStore= pb.ioWDDirID; |
Jack Jansen | 23ebeba | 1995-07-28 11:44:29 +0000 | [diff] [blame] | 39 | #endif |
Guido van Rossum | bcf3b56 | 1995-02-20 23:41:35 +0000 | [diff] [blame] | 40 | } |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 41 | return 0; |
| 42 | } |