Files
glibc/stdio-common/tmpnam.c
T

50 lines
1.6 KiB
C
Raw Normal View History

1997-01-24 02:23:54 +00:00
/* Copyright (C) 1991, 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
1995-02-18 01:27:10 +00:00
1997-01-24 02:23:54 +00:00
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
1995-02-18 01:27:10 +00:00
1997-01-24 02:23:54 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
1995-02-18 01:27:10 +00:00
1997-01-24 02:23:54 +00:00
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
1995-02-18 01:27:10 +00:00
#include <stdio.h>
#include <string.h>
1996-09-28 03:24:10 +00:00
/* Generate a unique filename in P_tmpdir.
This function is *not* thread safe! */
1995-02-18 01:27:10 +00:00
char *
1996-09-28 03:24:10 +00:00
tmpnam (char *s)
1995-02-18 01:27:10 +00:00
{
1996-09-28 03:24:10 +00:00
/* By using two buffers we manage to be thread safe in the case
where S != NULL. */
static char buf[L_tmpnam];
1996-10-02 01:40:17 +00:00
char tmpbuf[L_tmpnam];
1995-02-18 01:27:10 +00:00
1996-09-28 03:24:10 +00:00
/* 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
1998-08-03 16:47:01 +00:00
to L_tmpnam characters in any case. */
if (__path_search (s ? : tmpbuf, L_tmpnam, NULL, NULL))
return NULL;
1995-02-18 01:27:10 +00:00
1998-08-03 16:47:01 +00:00
if (__gen_tempname (s ? : tmpbuf, 0, 0))
return NULL;
if (s == NULL)
1996-09-28 03:24:10 +00:00
{
1998-08-03 16:47:01 +00:00
memcpy (buf, tmpbuf, L_tmpnam);
return buf;
1996-09-28 03:24:10 +00:00
}
1998-08-03 16:47:01 +00:00
else
return s;
1995-02-18 01:27:10 +00:00
}