octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #43844] tmpnam() ignores dir parameter if syst


From: Rik
Subject: [Octave-bug-tracker] [bug #43844] tmpnam() ignores dir parameter if systems temporary dir environment variable is set.
Date: Sun, 21 Dec 2014 15:35:51 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0

Update of bug #43844 (project octave):

                  Status:               Confirmed => Patch Submitted        

    _______________________________________________________

Follow-up Comment #4:

Matlab doesn't have the tmpnam function so I don't think Matlab can be doing
this correctly as implied by "Matlab just uses whatever is provided as a dir
name."

The root cause analysis is correct that Octave is using the C library function
tempnam.  'man tempnam' says:


NAME
       tempnam - create a name for a temporary file

SYNOPSIS
       #include <stdio.h>

       char *tempnam(const char *dir, const char *pfx);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       tempnam(): _BSD_SOURCE || _SVID_SOURCE

DESCRIPTION
       The  tempnam()  function  returns a pointer to a string that is a valid
filename, and such
       that a file with this name did not exist when tempnam() checked.  The
filename  suffix  of
       the  pathname  generated  will  start with pfx in case pfx is a
non-NULL string of at most
       five bytes.  The directory prefix part of the pathname generated is
required to be "appro‐
       priate" (often that at least implies writable).

       Attempts to find an appropriate directory go through the following
steps:

       a) In  case the environment variable TMPDIR exists and contains the
name of an appropriate
          directory, that is used.

       b) Otherwise, if the dir argument is non-NULL and appropriate, it is
used.

       c) Otherwise, P_tmpdir (as defined in <stdio.h>) is used when
appropriate.

       d) Finally an implementation-defined directory may be used.


So it is pretty clear why this is happening.  The code for this is in function
octave_tempnam is liboctave/system/file-ops.cc at line 674.

I've attached a patch which seems to work.  Another solution would be to
temporarily unset the environment variable TMPDIR ahead of calling tmpnam. 
But I think the code for that gets a little harder because one has to figure
out which platform is active and whether the environment variable is TMP or
TMPDIR.





(file #32697)
    _______________________________________________________

Additional Item Attachment:

File name: tmpnam.cset                    Size:1 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43844>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]