Boost logo

Boost :

Subject: Re: [boost] [filesystem] temp_dir_path()
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-10-12 20:49:28


John B. Turpish wrote:
> On Mon, Oct 11, 2010 at 9:19 AM, Jeff Flinn
> <TriumphSprint2000_at_[hidden]> wrote:
> > Stewart, Robert wrote:
> >> Jeff Flinn wrote:
> >>>
> >>> http://en.wikipedia.org/wiki/TMPDIR calls TMPDIR the
> >>> "canonical Unix environment variable" and refers to the
> >>> following for that justification:
> >>>
> >>> Is the above reference sufficient to only rely on TMPDIR?
> >>
> >> I don't think so, but I'm inclined to say don't look for
> >> /tmp. That is, rely on the environment as the sole means
> >> to find the correct directory and if that is deficient,
> >> declare an error.
> >
> > I agree it's not a good idea to look for a fixed path. I
> > don't have broad enough UNIX systems experience to make the
> > call on whether to look for additional environment
> > variables. If TMPDIR *is* the POSIX standard should that be
> > all that we support?
>
> I'm not going to pretend to be an expert, but I just ran a
> simple test. Of those environment variables the only one I had
> set was TMPDIR (I did not set up my envs and was surprised,
> actually). I compiled and ran a program that did nothing more
> than print the return of tmpnam(NULL) to std::cout. It
> resulted in a file that was in a different directory than
> ${TMPDIR} (and not /tmp either). env | grep
> 'directory.in.output' provided me with nothing. So I do not
> know where it got the directory for tmpnam(), but not from any
> env var.

According to <http://linux.die.net/man/3/tmpnam>, one should not
use tmpname(3) but should instead call mkstemp(3) or tmpfile(3).
The former makes a unique filename from a supplied template, so
it is the caller's responsibility to select the directory. The
latter creates a file which is deleted automatically when closed
or when the process terminates. Neither mentions e-vars as
influencing their behavior.

> Is it wrong for me to think tmpnam() would name to something in my
> temporary directory?

I wouldn't say it was wrong, but it was clearly misguided.

According to <http://linux.die.net/man/1/mktemp>, mktemp(1)
references TMPDIR and falls back on /tmp unless "-p directory"
was set on the command line.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk