[comp.lang.c] MSC V5.x, tempnam function gotcha

cramer@optilink.UUCP (Clayton Cramer) (07/01/88)

I ran into an interesting quirk (I hesitate to call it a bug) of the
tempnam function in Microsoft C.  The tempnam function provides a fairly
painless way to create temporary file names in the directory specified
by your TMP environment variable.  However, there is a slight quirk.

The manual says that the temporary file name is created in "Directory
specified by TMP" if "TMP environment variable is set, and directory
specified by TMP exist."

So, when I tried to use it, it behaved as though TMP wasn't set, or the
directory specified didn't exist.  The cause, it turns out, was that
my AUTOEXEC.BAT file says, "set TMP=e:" and tempnam doesn't consider
"e:" by itself to be a directory -- it needs "e:\".

As I said, it's not really a bug -- it does EXACTLY what it says it will
do, but it's only obvious to the very literal-minded (or a computer)
that "e:" is not a directory in this context.

Clayton E. Cramer

tneff@dasys1.UUCP (Tom Neff) (07/06/88)

Clayton Cramer points out that the MSC5.x 'tempnam' function doesn't
recognize an environment variable of the form 'TMP=e:' -- it requires
the trailing backslash, as in 'TMP=e:\'.

Perhaps the MSC RTL people were being a tad literal-minded here, but I
ought to point out that in DOS parlance, "e:" is NOT a unique and
invariable directory specification -- in particular it does NOT mean
the root directory of the disk in the E drive.  What it means is the
*current* directory selected on the disk in the E drive.  This can
change with every CHDIR command and chdir() call.  MS-DOS retains a
separate "current directory" for every disk drive attached.  If a path
specification does not include a leading backslash (after any drive
identifier), DOS will attempt to base the path from the current
directory on the specified (or default) drive.  

The MSC folks probably decided that only an invariant, absolute path
spec was suitable for what they wanted to do with the TMP variable.
Reasonable people might disagree on this, but I don't think they are
completely in left field.
-- 
Tom Neff			UUCP: ...!cmcl2!phri!dasys1!tneff
	"None of your toys	CIS: 76556,2536	       MCI: TNEFF
	 will function..."	GEnie: TOMNEFF	       BIX: t.neff (no kidding)