|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-03 17:51 UTC] marcel dot esser at gmail dot com
Description:
------------
Some systems add a terminating directory separator to the TMPDIR env variable, such as Mac OS X. This is not consistent with the fallback default for sys_get_temp_dir(), which is '/tmp'. This causes problems when constructing filenames when not using tempnam().
Here is a short patch against 5.2 HEAD
203c203,209
< temporary_directory = strdup(s);
---
> /* on some systems (notably mac os x) TMPDIR has a DIRECTORY_SEPARATOR appended */
> if(s[strlen(s)-1] == DEFAULT_SLASH) {
> temporary_directory = tsrm_strndup(s,strlen(s)-1);
> } else {
> temporary_directory = strdup(s);
> }
>
205a212
>
Reproduce code:
---------------
<?php
echo sys_get_temp_dir() . "\n";
Expected result:
----------------
/var/folders/yC/yCto0tGnHIqmgIv2v8-pEk+++TI/-Tmp-
Actual result:
--------------
/var/folders/yC/yCto0tGnHIqmgIv2v8-pEk+++TI/-Tmp-/
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 12:00:02 2025 UTC |
Pardon, I meant 5.2.9 CVS Also, here is diff -u output: --- main/php_open_temporary_file.c 2009-06-03 13:42:44.000000000 -0400 +++ /Users/marcelesser/php_open_temporary_file.c 2009-06-03 13:43:48.000000000 -0400 @@ -200,9 +200,16 @@ { char* s = getenv("TMPDIR"); if (s) { - temporary_directory = strdup(s); + /* on some systems (notably mac os x) TMPDIR has a DIRECTORY_SEPARATOR appended */ + if(s[strlen(s)-1] == DEFAULT_SLASH) { + temporary_directory = tsrm_strndup(s,strlen(s)-1); + } else { + temporary_directory = strdup(s); + } + return temporary_directory; } + } #ifdef P_tmpdir /* Use the standard default temporary directory. */Alternative patch: --- php52/php5/main/php_open_temporary_file.c 2009-06-03 13:42:44.000000000 -0400 +++ /Users/marcelesser/php_open_temporary_file.c 2009-06-04 02:19:29.000000000 -0400 @@ -200,9 +200,18 @@ { char* s = getenv("TMPDIR"); if (s) { - temporary_directory = strdup(s); + int last_char_idx = strlen(s) - 1; + + /* on some systems (notably mac os x) TMPDIR has a DIRECTORY_SEPARATOR appended */ + if(s[last_char_idx] == DEFAULT_SLASH) { + temporary_directory = tsrm_strndup(s,last_char_idx); + } else { + temporary_directory = strdup(s); + } + return temporary_directory; } + } #ifdef P_tmpdir /* Use the standard default temporary directory. */