Back to index

glibc  2.9
oldtmpfile.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1993,1996-2000,2003,2004,2007
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <shlib-compat.h>
00021 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
00022 
00023 #define _IO_USE_OLD_IO_FILE
00024 #include <stdio.h>
00025 #include <unistd.h>
00026 #include <iolibio.h>
00027 
00028 /* This returns a new stream opened on a temporary file (generated
00029    by tmpnam).  The file is opened with mode "w+b" (binary read/write).
00030    If we couldn't generate a unique filename or the file couldn't
00031    be opened, NULL is returned.  */
00032 FILE *
00033 attribute_compat_text_section
00034 __old_tmpfile (void)
00035 {
00036   char buf[FILENAME_MAX];
00037   int fd;
00038   FILE *f;
00039 
00040   if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
00041     return NULL;
00042   fd = __gen_tempname (buf, 0, __GT_FILE);
00043   if (fd < 0)
00044     return NULL;
00045 
00046   /* Note that this relies on the Unix semantics that
00047      a file is not really removed until it is closed.  */
00048   (void) __unlink (buf);
00049 
00050   if ((f = _IO_old_fdopen (fd, "w+b")) == NULL)
00051     __close (fd);
00052 
00053   return f;
00054 }
00055 
00056 compat_symbol (libc, __old_tmpfile, tmpfile, GLIBC_2_0);
00057 #endif