t[e]mpnam() stuff now works.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5433 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cc9c5de901
commit
bc659826df
@ -14,31 +14,35 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
02111-1307 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdio_private.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Generate a unique temporary filename using up to five characters of PFX
|
||||
if it is not NULL. The directory to put this file in is searched for
|
||||
as follows: First the environment variable "TMPDIR" is checked.
|
||||
If it contains the name of a writable directory, that directory is used.
|
||||
If not and if DIR is not NULL, that value is checked. If that fails,
|
||||
P_tmpdir is tried and finally "/tmp". The storage for the filename
|
||||
is allocated by `malloc'. */
|
||||
|
||||
/** Generate a unique temporary filename using up to five characters of PFX
|
||||
* if it is not NULL. The directory to put this file in is searched for
|
||||
* as follows: First the environment variable "TMPDIR" is checked.
|
||||
* If it contains the name of a writable directory, that directory is used.
|
||||
* If not and if DIR is not NULL, that value is checked. If that fails,
|
||||
* P_tmpdir is tried and finally "/tmp". The storage for the filename
|
||||
* is allocated by `malloc'.
|
||||
*/
|
||||
|
||||
char *
|
||||
tempnam (const char *dir, const char *pfx)
|
||||
tempnam(const char *dir, const char *prefix)
|
||||
{
|
||||
char buf[FILENAME_MAX];
|
||||
char buffer[NAME_MAX];
|
||||
|
||||
if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
|
||||
if (__path_search(buffer, NAME_MAX, dir, prefix, 1))
|
||||
return NULL;
|
||||
|
||||
if (__gen_tempname (buf, __GT_NOCREATE))
|
||||
if (__gen_tempname(buffer, __GT_NOCREATE))
|
||||
return NULL;
|
||||
|
||||
return __strdup (buf);
|
||||
return strdup(buffer);
|
||||
}
|
||||
|
||||
link_warning (tempnam,
|
||||
"the use of `tempnam' is dangerous, better use `mkstemp'")
|
||||
//link_warning(tempnam, "the use of `tempnam' is dangerous, better use `mkstemp'")
|
||||
|
@ -14,39 +14,41 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
02111-1307 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdio_private.h>
|
||||
#include <string.h>
|
||||
|
||||
static char tmpnam_buffer[L_tmpnam];
|
||||
|
||||
/* Generate a unique filename in P_tmpdir.
|
||||
/** Generate a unique filename in P_tmpdir.
|
||||
* This function is *not* thread safe!
|
||||
*/
|
||||
|
||||
This function is *not* thread safe! */
|
||||
char *
|
||||
tmpnam (char *s)
|
||||
{
|
||||
/* By using two buffers we manage to be thread safe in the case
|
||||
where S != NULL. */
|
||||
static char tmpnam_buffer[L_tmpnam];
|
||||
|
||||
/* By using two buffers we manage to be thread safe in the case where S != NULL. */
|
||||
char tmpbufmem[L_tmpnam];
|
||||
char *tmpbuf = s ?: tmpbufmem;
|
||||
|
||||
/* In the following call we use the buffer pointed to by S if
|
||||
non-NULL although we don't know the size. But we limit the size
|
||||
to L_tmpnam characters in any case. */
|
||||
if (__builtin_expect (__path_search (tmpbuf, L_tmpnam, NULL, NULL, 0),
|
||||
0))
|
||||
* non-NULL although we don't know the size. But we limit the size
|
||||
* to L_tmpnam characters in any case.
|
||||
*/
|
||||
if (__builtin_expect(__path_search(tmpbuf, L_tmpnam, NULL, NULL, 0), 0))
|
||||
return NULL;
|
||||
|
||||
if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0))
|
||||
if (__builtin_expect(__gen_tempname(tmpbuf, __GT_NOCREATE), 0))
|
||||
return NULL;
|
||||
|
||||
if (s == NULL)
|
||||
return (char *) memcpy (tmpnam_buffer, tmpbuf, L_tmpnam);
|
||||
return (char *)memcpy(tmpnam_buffer, tmpbuf, L_tmpnam);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
link_warning (tmpnam,
|
||||
"the use of `tmpnam' is dangerous, better use `mkstemp'")
|
||||
//link_warning (tmpnam, "the use of `tmpnam' is dangerous, better use `mkstemp'")
|
||||
|
@ -14,25 +14,29 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
02111-1307 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Generate a unique filename in P_tmpdir. If S is NULL return NULL.
|
||||
This makes this function thread safe. */
|
||||
#include <stdio_private.h>
|
||||
|
||||
|
||||
/** Generate a unique filename in P_tmpdir. If S is NULL return NULL.
|
||||
* This makes this function thread safe.
|
||||
*/
|
||||
|
||||
char *
|
||||
tmpnam_r (char *s)
|
||||
tmpnam_r(char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
if (__path_search (s, L_tmpnam, NULL, NULL, 0))
|
||||
if (__path_search(s, L_tmpnam, NULL, NULL, 0))
|
||||
return NULL;
|
||||
if (__gen_tempname (s, __GT_NOCREATE))
|
||||
if (__gen_tempname(s, __GT_NOCREATE))
|
||||
return NULL;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
link_warning (tmpnam_r,
|
||||
"the use of `tmpnam_r' is dangerous, better use `mkstemp'")
|
||||
//link_warning (tmpnam_r, "the use of `tmpnam_r' is dangerous, better use `mkstemp'")
|
||||
|
Loading…
Reference in New Issue
Block a user