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