bugGNU Octave - Bugs: bug #43844, tmpnam() ignores dir parameter if...

 
 

bug #43844: tmpnam() ignores dir parameter if systems temporary dir environment variable is set.

Submitted by:  sergey plotnikov <nul0m>
Submitted on:  Thu 18 Dec 2014 02:06:44 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 22 Dec 2014 05:05:43 AM UTC, comment #8:

I checked in a change that fixes tempname and adds BIST tests which should work on both UNIX and Windows (http://hg.savannah.gnu.org/hgweb/octave/rev/82f2a3437e02). Closing report.

Rik <rik5>
Project Administrator
Mon 22 Dec 2014 01:31:59 AM UTC, comment #7:

I meant tempname in matlab [1]

According to the docs for matlab, it doesn't accept any arguments, however looking at the .m file, it does.

[1] http://www.mathworks.com/help/matlab/ref/tempname.html

John Donoghue <lostbard>
Project Member
Sun 21 Dec 2014 05:41:59 PM UTC, comment #6:

Aaach, thanks for checking the patch. I had a feeling I might get something wrong here so I didn't commit it immediately. I'll take a look at the best way to handle a null prefix.

Rik <rik5>
Project Administrator
Sun 21 Dec 2014 04:21:35 PM UTC, comment #5:

I looked back to when the tmpnam function was added to Octave, and it looks like there was never a time when it was a simple wrapper for the C library tmpnam function. Instead it called tempnam. I don't know why exactly. Then sometime later I assume the handling of the DIR and PREFIX arguments was added.

Rik, I agree that it is probably easier to just rewrite the file name. I tried your patch and now if I try someething like tmpnam ("/home", ""), the result is "/home/". Without the patch it was something like "/home/fileFH6WIK". Was that intentional?

John W. Eaton <jwe>
Project Administrator
Sun 21 Dec 2014 03:35:51 PM UTC, 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:

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)

Rik <rik5>
Project Administrator
Fri 19 Dec 2014 01:35:22 PM UTC, comment #3:

So it is a bug in all OS.

Rewrote summary to reflect full bug and set OS to any.

tempname and tmpnam ignore the DIR parameter if the OS specific temporty dir environment variable is set.
In windows: TMP
In Linux: TMPDIR

Matlab just uses whatever is provided as a dir name.

John Donoghue <lostbard>
Project Member
Fri 19 Dec 2014 01:09:02 PM UTC, comment #2:

Use of TMP is for windows - the Linux version behaves the same if the TMPDIR environment variable it set.

On my Linux system, TMPDIR is not set by default. On my windows machine TMP is set.

John Donoghue <lostbard>
Project Member
Thu 18 Dec 2014 06:18:28 PM UTC, comment #1:

octave uses the systems tempnam function which says it uses the dir if environment variable TMP is not set.

On my windows machine:
I tried on Matlab 2013, and it uses the input name, regardless of whether it is a valid directory, character etc.

John Donoghue <lostbard>
Project Member
Thu 18 Dec 2014 02:06:44 PM UTC, original submission:

on Windows machines tmpnam() is not able to construct the name using user-defined directory.

sergey plotnikov <nul0m>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #32697:  tmpnam.cset added by rik5 (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by avinoam
  • -unavailable- added by lostbard (Posted a comment)
  • -unavailable- added by nul0m (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 22 Dec 2014 05:05:43 AM UTCrik5StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Sun 21 Dec 2014 03:35:51 PM UTCrik5Attached File-=>Added tmpnam.cset, #32697
      StatusConfirmed=>Patch Submitted
    Fri 19 Dec 2014 01:35:22 PM UTClostbardStatusNone=>Confirmed
      Operating SystemMicrosoft Windows=>Any
      Summarytmpnam() always uses default directory for temporary files on Windows=>tmpnam() ignores dir parameter if systems temporary dir environment variable is set.
    Thu 18 Dec 2014 07:19:39 PM UTCavinoamCarbon-Copy-=>Added avinoam

    Back to the top


    Powered by Savane 3.1-cleanup1