Path: utzoo!mnetor!uunet!mcvax!guido From: guido@cwi.nl (Guido van Rossum) Newsgroups: comp.sys.mac.programmer Subject: Re: Full path name of a file Message-ID: <301@piring.cwi.nl> Date: 6 May 88 10:44:41 GMT References: <2532@chalmers.UUCP> Reply-To: guido@cwi.nl (Guido van Rossum) Organization: The Royal Society for Prevention of Cruelty to Amoebae Lines: 76 In article <2532@chalmers.UUCP> olausson@chalmers.UUCP (Stefan Olausson) writes: >Given the information in a SFReply, how do I construct the full path name >of a file (as a string), i e "disk:dir1:dir2:...:filename" ? Here's my code. I am not posting the header file "macdefs.h" or the "dprintf" routine but you should be able to gues what's in them.; or ask me to mail them. This was tested with MPW. /* GET FULL PATHNAME OF A FILE. Public Domain by Guido van Rossum, CWI, Amsterdam. May 1988. */ #include "macwin.h" /* Mac file system parameters */ #define MAXPATH 256 /* Max path name length+1 */ #define SEP ':' /* Separator in path names */ #define ROOTID 2 /* DirID of a volume's root directory */ /* Macro to find out whether we can do HFS-only calls: */ #define FSFCBLen (* (short *) 0x3f6) #define hfsrunning() (FSFCBLen > 0) char * getdirname(dir) long dir; /* WDRefNum */ { union { HFileInfo f; DirInfo d; WDPBRec w; VolumeParam v; } pb; static char cwd[2*MAXPATH]; char namebuf[MAXPATH]; short err; long dirid= 0; char *next= cwd + sizeof cwd - 1; int len; if (!hfsrunning()) return ""; for (;;) { pb.d.ioNamePtr= namebuf; pb.d.ioVRefNum= dir; pb.d.ioFDirIndex= -1; pb.d.ioDrDirID= dirid; err= PBGetCatInfo(&pb.d, FALSE); if (err != noErr) { dprintf("PBCatInfo err %d", err); return NULL; } *--next= SEP; len= namebuf[0]; /* There is no overflow check on cwd here! */ strncpy(next -= len, namebuf+1, len); if (pb.d.ioDrDirID == ROOTID) break; dirid= pb.d.ioDrParID; } return next; } void fullpath(buf, wdrefnum, file) char *buf; int wdrefnum; char *file; { strcpy(buf, getdirname(wdrefnum)); strcat(buf, file); } -- Guido van Rossum, Centre for Mathematics and Computer Science (CWI), Amsterdam guido@piring.cwi.nl or mcvax!piring!guido or guido%piring.cwi.nl@uunet.uu.net