🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #3302

Re: How to determine if a file is in a root directory?

#3302
From: fisher
Date: Wed, 05 Dec 1990 11:26
75 lines
2797 bytes
In article <12201@life.ai.mit.edu>, mbeck@ai.mit.edu (Mark Becker) writes:
> [ needs a temporary directory, name taken from a configuration file
> and wants to determine whether this particular path is JOIN'ed, SUBST'ed
> or on a Novell network drive, i.e.: ]
>
> In order to prevent possible configuration errors and major grief, I
> want do a little sanity checking on the reference that the installer
> sets up.  Turning this thing loose on someone's root directory could
> lead to a disaster.

My first advice would be to check the content of the directory, of course.
If the directory exists and isn't empty, the exit with an error.  (BTW:
I would recommend checking for a TMP variable (which sometimes points to
a RAM-drive, or the like) and use, say, <TMP><progname> as the root of
your tmp directory...)

Still, it's possible to obtain the "physical" directory through a DOS function
call.  As it's not too long, consider the following quick hack (from the
program "write" in queue for posting in c.b.i.p).
Original idea adapted from some posting on the net, two years ago:

	From: pfales@ttrde.UUCP (Peter Fales)
	Newsgroups: comp.sys.ibm.pc
	Subject: Finding free space on a joined drive
	Date: 9 Jan 89 15:19:32 GMT
	Organization: AT&T, Skokie, IL


TurboC 1.5 source file:

#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <dir.h>

char path[MAXPATH], true_path[MAXPATH];

void getpath(void)
/*
 * Stores the current path into `path' and the true path into `true_path'.
 * The true path is obtaind by the dos function call 0x60.
 * DS:SI is input path; ES:DI is output path.
 */
{
	union REGS r;
	struct SREGS s;

	getcwd (path, MAXPATH);
	r.x.ax = 0x6000;
	/* assuming near pointers: */
	r.x.si = (unsigned)path;
	r.x.di = (unsigned)true_path;
	segread(&s);
	s.es = s.ds;
	intdosx(&r,&r,&s);
}

void main ()
{
	char *diagnosis = NULL;

	getpath();
	printf("path: %s", path);
	if (*true_path == '\\')
		diagnosis = "network path";
	else
		if (*path != *true_path)
			if (strlen(true_path) > strlen(path))
				diagnosis = "substitutes for";
			else
				diagnosis = "is joined from";
	if (diagnosis)
		printf(";  %s: %s", diagnosis, true_path);
	printf("\n");
}
Technical Details
Message-ID: <1990Dec5.132650.336@sc2a.unige.ch>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!ugun2b!ugsc2a!fisher
References: <12201@life.ai.mit.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!ugun2b!ugsc2a!fisher
From: fisher@sc2a.unige.ch
Newsgroups: comp.os.msdos.programmer
Subject: Re: How to determine if a file is in a root directory?
Message-ID: <1990Dec5.132650.336@sc2a.unige.ch>
Date: 5 Dec 90 11:26:50 GMT
References: <12201@life.ai.mit.edu>
Followup-To: comp.os.msdos.programmer
Organization: University of Geneva, Switzerland
Lines: 75