cpython/Mac/Compat/nfullpath.c

76 lines
1.4 KiB
C
Raw Normal View History

/* GET FULL PATHNAME OF A FILE.
** Original by Guido, modified by Jack to handle FSSpecs
*/
1995-01-19 00:03:47 +00:00
#include <string.h>
#include <Files.h>
#include "nfullpath.h"
/* Mac file system parameters */
#define MAXPATH 256 /* Max path name length+1 */
#define SEP ':' /* Separator in path names */
/* Macro to find out whether we can do HFS-only calls: */
#define FSFCBLen (* (short *) 0x3f6)
#define hfsrunning() (FSFCBLen > 0)
int
nfullpath(fsp, retbuf)
FSSpec *fsp;
char *retbuf;
{
union {
HFileInfo f;
DirInfo d;
WDPBRec w;
VolumeParam v;
} pb;
1995-02-21 00:44:14 +00:00
char cwd[2*MAXPATH];
unsigned char namebuf[MAXPATH];
short err;
int dir;
long dirid;
1995-02-21 00:44:14 +00:00
char *next = cwd + sizeof cwd - 1;
int len;
1995-02-21 00:44:14 +00:00
int need_sep = 1;
if (!hfsrunning())
return -1;
1995-02-21 00:44:14 +00:00
dir = fsp->vRefNum;
dirid = fsp->parID;
/* Stuff the filename into the buffer */
len = fsp->name[0];
*next = '\0';
1995-02-21 00:44:14 +00:00
next -= len;
memcpy(next, fsp->name+1, len);
1995-02-21 00:44:14 +00:00
while (dirid != fsRtParID) {
pb.d.ioNamePtr = namebuf;
pb.d.ioVRefNum = dir;
pb.d.ioFDirIndex = -1;
pb.d.ioDrDirID = dirid;
err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
1995-02-21 00:44:14 +00:00
if (err != noErr)
return err;
1995-02-21 00:44:14 +00:00
*--next = SEP;
len = namebuf[0];
if ( len + strlen(next) >= MAXPATH )
return -1;
next -= len;
memcpy(next, (char *)namebuf+1, len);
1995-02-21 00:44:14 +00:00
dirid = pb.d.ioDrParID;
need_sep = 0;
}
1995-02-21 00:44:14 +00:00
strcpy(retbuf, next);
1995-02-21 00:44:14 +00:00
if (need_sep) {
next = strchr(retbuf, '\0');
*next++ = SEP;
*next++ = '\0';
}
return 0;
}