Patchwork - fix handling of temporary directories on Windows

login
register
mail settings
Submitter Pascal Obry
Date July 12, 2010, 4:04 p.m.
Message ID <4C3B3D11.7030501@adacore.com>
Download mbox | patch
Permalink /patch/58632/
State New
Headers show

Comments

Pascal Obry - July 12, 2010, 4:04 p.m.
ChangeLog:

2010-07-09  Pascal Obry  <obry@adacore.com>

   * libibery/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP
   are not set, P_tmpdir is used on Windows. This is defined as "\" in
   current MingW header. Append a dot to ensure that when concatenating
   with \dir we do not end-up with an UNC path. Fix a crash on the
   compiler.


Patch as attachment.
DJ Delorie - July 12, 2010, 5:28 p.m.
>    * libibery/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP
>    are not set, P_tmpdir is used on Windows. This is defined as "\" in
>    current MingW header. Append a dot to ensure that when concatenating
>    with \dir we do not end-up with an UNC path. Fix a crash on the
>    compiler.

Ok.
Pascal Obry - July 12, 2010, 7:16 p.m.
Le 12/07/2010 20:30, Florian Weimer a écrit :
> * Pascal Obry:
> 
>> ChangeLog:
>>
>> 2010-07-09  Pascal Obry  <obry@adacore.com>
>>
>>    * libibery/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP
> 
> I think it's "libiberty". 8-)

Right, good catch :) The change log should read:


2010-07-09  Pascal Obry  <obry@adacore.com>

   * libiberty/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP
   are not set, P_tmpdir is used on Windows. This is defined as "\" in
   current MingW header. Append a dot to ensure that when concatenating
   with \dir we do not end-up with an UNC path. Fix a crash on the
   compiler.
Dave Korn - July 12, 2010, 11:34 p.m.
On 12/07/2010 20:16, Pascal Obry wrote:
> Le 12/07/2010 20:30, Florian Weimer a écrit :
>> * Pascal Obry:
>>
>>> ChangeLog:
>>>
>>> 2010-07-09  Pascal Obry  <obry@adacore.com>
>>>
>>>    * libibery/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP
>> I think it's "libiberty". 8-)
> 
> Right, good catch :) The change log should read:
> 
> 
> 2010-07-09  Pascal Obry  <obry@adacore.com>
> 
>    * libiberty/make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP

  Well, if we're being pedantic, it should actually say:

>    * make-temp-file.c (choose_tmpdir): When TMPDIR, TMP and TEMP [ ... ]

... since this entry is going into libiberty/ChangeLog you discard the common
leading prefix.

    cheers,
      DaveK

Patch

diff libiberty/make-temp-file.c libiberty/make-temp-file.c
index 13e1925..f754b45 100644
--- libiberty/make-temp-file.c
+++ libiberty/make-temp-file.c
@@ -121,7 +121,12 @@  choose_tmpdir (void)
 #endif
       
 #ifdef P_tmpdir
-      base = try_dir (P_tmpdir, base);
+      /* We really want a directory name here as if concatenated with say \dir
+         we do not end-up with a double \\ which defines an UNC path.  */
+      if (strcmp (P_tmpdir, "\\") == 0)
+	base = try_dir ("\\.", base);
+      else
+	base = try_dir (P_tmpdir, base);
 #endif
 
       /* Try /var/tmp, /usr/tmp, then /tmp.  */