casts to (void)

Peter da Silva peter at baylor.UUCP
Sat Aug 17 03:53:04 AEST 1985


> >. . . and tempnam is just a throwback to the days before sprintf.
> 
> Not really; tempnam (or mktemp) is not the same as doing
> 
> 	sprintf(fname, "/tmp/x%d", getpid());
> 
> (or variations thereupon) as it actually makes sure that such a
> file doesn't already exist (what happens when you get the same pid
> as someone else did earlier?).

Never occured to me that you could get this, but of course you can. well,
you just do this:

	for(c='a'; c<='z'; c++) {
		sprintf(fname, "/tmp/x%s%c", getpid(), c);
		if(access(fname, 7))
			break;
	}
	if(c>'z') panic

which is, of course, basically what mktemp must do. Never mind.
-- 
	Peter da Silva (the mad Australian werewolf)
		UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter
		MCI: PDASILVA; CIS: 70216,1076



More information about the Comp.lang.c mailing list