Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 1 | /* GET FULL PATHNAME OF A FILE. |
| 2 | ** Original by Guido, modified by Jack to handle FSSpecs |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 3 | */ |
| 4 | |
Guido van Rossum | a42960c | 1995-01-19 00:03:47 +0000 | [diff] [blame] | 5 | #include <string.h> |
| 6 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 7 | #include <Files.h> |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 8 | |
| 9 | #include "nfullpath.h" |
| 10 | |
| 11 | /* Mac file system parameters */ |
| 12 | #define MAXPATH 256 /* Max path name length+1 */ |
| 13 | #define SEP ':' /* Separator in path names */ |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 14 | |
| 15 | /* Macro to find out whether we can do HFS-only calls: */ |
| 16 | #define FSFCBLen (* (short *) 0x3f6) |
| 17 | #define hfsrunning() (FSFCBLen > 0) |
| 18 | |
| 19 | int |
| 20 | nfullpath(fsp, retbuf) |
| 21 | FSSpec *fsp; |
| 22 | char *retbuf; |
| 23 | { |
| 24 | union { |
| 25 | HFileInfo f; |
| 26 | DirInfo d; |
| 27 | WDPBRec w; |
| 28 | VolumeParam v; |
| 29 | } pb; |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 30 | char cwd[2*MAXPATH]; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 31 | unsigned char namebuf[MAXPATH]; |
| 32 | short err; |
| 33 | int dir; |
| 34 | long dirid; |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 35 | char *next = cwd + sizeof cwd - 1; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 36 | int len; |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 37 | int need_sep = 1; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 38 | |
| 39 | if (!hfsrunning()) |
| 40 | return -1; |
| 41 | |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 42 | dir = fsp->vRefNum; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 43 | dirid = fsp->parID; |
| 44 | /* Stuff the filename into the buffer */ |
| 45 | len = fsp->name[0]; |
| 46 | *next = '\0'; |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 47 | next -= len; |
| 48 | memcpy(next, fsp->name+1, len); |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 50 | while (dirid != fsRtParID) { |
| 51 | pb.d.ioNamePtr = namebuf; |
| 52 | pb.d.ioVRefNum = dir; |
| 53 | pb.d.ioFDirIndex = -1; |
| 54 | pb.d.ioDrDirID = dirid; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 55 | err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0); |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 56 | if (err != noErr) |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 57 | return err; |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 58 | *--next = SEP; |
| 59 | len = namebuf[0]; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 60 | if ( len + strlen(next) >= MAXPATH ) |
| 61 | return -1; |
| 62 | next -= len; |
| 63 | memcpy(next, (char *)namebuf+1, len); |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 64 | dirid = pb.d.ioDrParID; |
| 65 | need_sep = 0; |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 66 | } |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 67 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 68 | strcpy(retbuf, next); |
Guido van Rossum | f74c36c | 1995-02-21 00:44:14 +0000 | [diff] [blame] | 69 | if (need_sep) { |
| 70 | next = strchr(retbuf, '\0'); |
| 71 | *next++ = SEP; |
| 72 | *next++ = '\0'; |
| 73 | } |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 74 | return 0; |
| 75 | } |