[comp.sys.mac] Reading a full pathname in HFS - source code

tim@hoptoad.uucp (Tim Maroney) (12/12/87)

You're quite correct, Justin.  The disadvantage of modular source code is
that, six months later, you forget how the function works.  Here is my
source code for getting a full path name.  fullname is a return parameter
which receives the full name of the (file, volume, dirID) triplet.

void
GetFullName(fullname, file, volume, dirID)
char *fullname, *file;
word volume;
longword dirID;
{
	char buffer[256], buf2[256], *name, *accum, *tmp;
	HVolumeParam hvp;
	DirInfo di;

	hvp.ioNamePtr = (StringPtr)fullname;
	hvp.ioVRefNum = volume;
	hvp.ioVolIndex = 0;
	PBHGetVInfo(&hvp, false);
	fullname[++fullname[0]] = ':';
	p2cstr(fullname);

	if (FSFCBLen > 0) {
		/* runnning HFS */
		if (hvp.ioVSigWord != 0xd2d7) {
			/* HFS volume, use CurDirStore and GetCatInfo */
			name = buffer;
			accum = buf2;
			accum[0] = '\0';
			while (dirID != 2) {
				di.ioNamePtr = name;
				di.ioVRefNum = volume;
				di.ioFDirIndex = -1;
				di.ioDrDirID = dirID;
				PBGetCatInfo(&di, false);
				name[++name[0]] = ':';
				p2cstr(name);
				strcat(name, accum);
				tmp = accum;
				accum = name;
				name = tmp;
				dirID = di.ioDrParID;
			}
			strcat(fullname, accum);
		}
	}

	/* concatenate the volume and file names */
	strcat(fullname, file);
}

and as an extra, this-week-only bonus, here's what I call on Standard File's
vRefNum to get a (volume, directory) pair:

void
GetVolDir(invol, volume, directory)
word invol, *volume;
longword *directory;
{
	WDPBRec wdpb;
	String(70) name;

	if (FSFCBLen < 0) {
		*volume = invol;
		*directory = 2;
		return;
	}

	/* in HFS, it's a working directory */
	wdpb.ioNamePtr = &name;
	wdpb.ioVRefNum = invol;
	wdpb.ioWDIndex = 0;
	wdpb.ioWDProcID = 0;
	wdpb.ioWDVRefNum = 0;
	PBGetWDInfo(&wdpb, false);
	*volume = wdpb.ioWDVRefNum;
	*directory = wdpb.ioWDDirID;
}

Sorry for the earlier misinformation.
-- 
Tim Maroney, {ihnp4,sun,well,ptsfa,lll-crg}!hoptoad!tim; hoptoad!tim@lll-crg
"What's bad? What's the use of turning?
 In Hell I'll be there a-burning!
 Meanwhile, think of what I'm earning
 All on account of my name." - Bill Sykes, "Oliver"