00001 /* Copyright (C) 1991, 1993 Free Software Foundation, Inc. 00002 This file is part of the GNU C Library. 00003 00004 The GNU C Library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 The GNU C Library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with the GNU C Library; see the file COPYING.LIB. If 00016 not, write to the Free Software Foundation, Inc., 51 Franklin Street, 00017 Fifth Floor, Boston, MA 02110-1301, USA. */ 00018 00019 #ifdef HAVE_CONFIG_H 00020 #include <config.h> 00021 #endif 00022 00023 #ifndef HAVE_TEMPNAM 00024 00025 #include <stddef.h> 00026 #include <stdio.h> 00027 #include <stdlib.h> 00028 #include <string.h> 00029 00030 extern char *__stdio_gen_tempname (const char *dir, const char *pfx, 00031 int dir_search, size_t *lenptr, 00032 FILE **streamptr); 00033 00034 /* Generate a unique temporary filename using up to five characters of PFX 00035 if it is not NULL. The directory to put this file in is searched for 00036 as follows: First the environment variable "TMPDIR" is checked. 00037 If it contains the name of a writable directory, that directory is used. 00038 If not and if DIR is not NULL, that value is checked. If that fails, 00039 P_tmpdir is tried and finally "/tmp". The storage for the filename 00040 is allocated by `malloc'. */ 00041 char * 00042 tempnam (const char *dir, const char *pfx) 00043 { 00044 size_t len; 00045 register char *s; 00046 register char *t = __stdio_gen_tempname(dir, pfx, 1, &len, (FILE **) NULL); 00047 00048 if (t == NULL) 00049 return NULL; 00050 00051 s = (char *) malloc(len); 00052 if (s == NULL) 00053 return NULL; 00054 00055 (void) memcpy(s, t, len); 00056 return s; 00057 } 00058 00059 #endif