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:
@@ -14,31 +14,35 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
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
|
License along with the GNU C Library; if not, write to the Free
|
||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
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>
|
#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
|
/** Generate a unique temporary filename using up to five characters of PFX
|
||||||
as follows: First the environment variable "TMPDIR" is checked.
|
* if it is not NULL. The directory to put this file in is searched for
|
||||||
If it contains the name of a writable directory, that directory is used.
|
* as follows: First the environment variable "TMPDIR" is checked.
|
||||||
If not and if DIR is not NULL, that value is checked. If that fails,
|
* If it contains the name of a writable directory, that directory is used.
|
||||||
P_tmpdir is tried and finally "/tmp". The storage for the filename
|
* If not and if DIR is not NULL, that value is checked. If that fails,
|
||||||
is allocated by `malloc'. */
|
* P_tmpdir is tried and finally "/tmp". The storage for the filename
|
||||||
|
* is allocated by `malloc'.
|
||||||
|
*/
|
||||||
|
|
||||||
char *
|
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;
|
return NULL;
|
||||||
|
|
||||||
if (__gen_tempname (buf, __GT_NOCREATE))
|
if (__gen_tempname(buffer, __GT_NOCREATE))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return __strdup (buf);
|
return strdup(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
link_warning (tempnam,
|
//link_warning(tempnam, "the use of `tempnam' is dangerous, better use `mkstemp'")
|
||||||
"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
|
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
|
License along with the GNU C Library; if not, write to the Free
|
||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
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>
|
#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 *
|
char *
|
||||||
tmpnam (char *s)
|
tmpnam (char *s)
|
||||||
{
|
{
|
||||||
/* By using two buffers we manage to be thread safe in the case
|
static char tmpnam_buffer[L_tmpnam];
|
||||||
where S != NULL. */
|
|
||||||
char tmpbufmem[L_tmpnam];
|
|
||||||
char *tmpbuf = s ?: tmpbufmem;
|
|
||||||
|
|
||||||
/* In the following call we use the buffer pointed to by S if
|
/* By using two buffers we manage to be thread safe in the case where S != NULL. */
|
||||||
non-NULL although we don't know the size. But we limit the size
|
char tmpbufmem[L_tmpnam];
|
||||||
to L_tmpnam characters in any case. */
|
char *tmpbuf = s ?: tmpbufmem;
|
||||||
if (__builtin_expect (__path_search (tmpbuf, L_tmpnam, NULL, NULL, 0),
|
|
||||||
0))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0))
|
/* In the following call we use the buffer pointed to by S if
|
||||||
return NULL;
|
* 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 (s == NULL)
|
if (__builtin_expect(__gen_tempname(tmpbuf, __GT_NOCREATE), 0))
|
||||||
return (char *) memcpy (tmpnam_buffer, tmpbuf, L_tmpnam);
|
return NULL;
|
||||||
|
|
||||||
return s;
|
if (s == NULL)
|
||||||
|
return (char *)memcpy(tmpnam_buffer, tmpbuf, L_tmpnam);
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
link_warning (tmpnam,
|
//link_warning (tmpnam, "the use of `tmpnam' is dangerous, better use `mkstemp'")
|
||||||
"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
|
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
|
License along with the GNU C Library; if not, write to the Free
|
||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
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.
|
#include <stdio_private.h>
|
||||||
This makes this function thread safe. */
|
|
||||||
|
|
||||||
|
/** Generate a unique filename in P_tmpdir. If S is NULL return NULL.
|
||||||
|
* This makes this function thread safe.
|
||||||
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
tmpnam_r (char *s)
|
tmpnam_r(char *s)
|
||||||
{
|
{
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (__path_search (s, L_tmpnam, NULL, NULL, 0))
|
if (__path_search(s, L_tmpnam, NULL, NULL, 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (__gen_tempname (s, __GT_NOCREATE))
|
if (__gen_tempname(s, __GT_NOCREATE))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
link_warning (tmpnam_r,
|
//link_warning (tmpnam_r, "the use of `tmpnam_r' is dangerous, better use `mkstemp'")
|
||||||
"the use of `tmpnam_r' is dangerous, better use `mkstemp'")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user