blob: ca027c889666c8f9dc4dafd592aaf6f8380ca169 [file] [log] [blame]
Jack Jansen84fa5ec1995-01-18 14:04:40 +00001/* GET FULL PATHNAME OF A FILE.
2** Original by Guido, modified by Jack to handle FSSpecs
Jack Jansen84fa5ec1995-01-18 14:04:40 +00003*/
4
Guido van Rossuma42960c1995-01-19 00:03:47 +00005#include <string.h>
6
Jack Jansen84fa5ec1995-01-18 14:04:40 +00007#include <Files.h>
Jack Jansen84fa5ec1995-01-18 14:04:40 +00008
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 Jansen84fa5ec1995-01-18 14:04:40 +000014
15/* Macro to find out whether we can do HFS-only calls: */
16#define FSFCBLen (* (short *) 0x3f6)
17#define hfsrunning() (FSFCBLen > 0)
18
19int
20nfullpath(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 Rossumf74c36c1995-02-21 00:44:14 +000030 char cwd[2*MAXPATH];
Jack Jansen84fa5ec1995-01-18 14:04:40 +000031 unsigned char namebuf[MAXPATH];
32 short err;
33 int dir;
34 long dirid;
Guido van Rossumf74c36c1995-02-21 00:44:14 +000035 char *next = cwd + sizeof cwd - 1;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000036 int len;
Guido van Rossumf74c36c1995-02-21 00:44:14 +000037 int need_sep = 1;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000038
39 if (!hfsrunning())
40 return -1;
41
Guido van Rossumf74c36c1995-02-21 00:44:14 +000042 dir = fsp->vRefNum;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000043 dirid = fsp->parID;
44 /* Stuff the filename into the buffer */
45 len = fsp->name[0];
46 *next = '\0';
Guido van Rossumf74c36c1995-02-21 00:44:14 +000047 next -= len;
48 memcpy(next, fsp->name+1, len);
Jack Jansen84fa5ec1995-01-18 14:04:40 +000049
Guido van Rossumf74c36c1995-02-21 00:44:14 +000050 while (dirid != fsRtParID) {
51 pb.d.ioNamePtr = namebuf;
52 pb.d.ioVRefNum = dir;
53 pb.d.ioFDirIndex = -1;
54 pb.d.ioDrDirID = dirid;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000055 err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
Guido van Rossumf74c36c1995-02-21 00:44:14 +000056 if (err != noErr)
Jack Jansen84fa5ec1995-01-18 14:04:40 +000057 return err;
Guido van Rossumf74c36c1995-02-21 00:44:14 +000058 *--next = SEP;
59 len = namebuf[0];
Jack Jansen84fa5ec1995-01-18 14:04:40 +000060 if ( len + strlen(next) >= MAXPATH )
61 return -1;
62 next -= len;
63 memcpy(next, (char *)namebuf+1, len);
Guido van Rossumf74c36c1995-02-21 00:44:14 +000064 dirid = pb.d.ioDrParID;
65 need_sep = 0;
Jack Jansen84fa5ec1995-01-18 14:04:40 +000066 }
Guido van Rossumf74c36c1995-02-21 00:44:14 +000067
Jack Jansen84fa5ec1995-01-18 14:04:40 +000068 strcpy(retbuf, next);
Guido van Rossumf74c36c1995-02-21 00:44:14 +000069 if (need_sep) {
70 next = strchr(retbuf, '\0');
71 *next++ = SEP;
72 *next++ = '\0';
73 }
Jack Jansen84fa5ec1995-01-18 14:04:40 +000074 return 0;
75}