Blame libio/oldtmpfile.c

Packit Service 82fcde
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <shlib-compat.h>
Packit Service 82fcde
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
Packit Service 82fcde
Packit Service 82fcde
#define _IO_USE_OLD_IO_FILE
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
#include <iolibio.h>
Packit Service 82fcde
Packit Service 82fcde
/* This returns a new stream opened on a temporary file (generated
Packit Service 82fcde
   by tmpnam).  The file is opened with mode "w+b" (binary read/write).
Packit Service 82fcde
   If we couldn't generate a unique filename or the file couldn't
Packit Service 82fcde
   be opened, NULL is returned.  */
Packit Service 82fcde
FILE *
Packit Service 82fcde
attribute_compat_text_section
Packit Service 82fcde
__old_tmpfile (void)
Packit Service 82fcde
{
Packit Service 82fcde
  char buf[FILENAME_MAX];
Packit Service 82fcde
  int fd;
Packit Service 82fcde
  FILE *f;
Packit Service 82fcde
Packit Service 82fcde
  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
Packit Service 82fcde
    return NULL;
Packit Service 82fcde
  fd = __gen_tempname (buf, 0, 0, __GT_FILE);
Packit Service 82fcde
  if (fd < 0)
Packit Service 82fcde
    return NULL;
Packit Service 82fcde
Packit Service 82fcde
  /* Note that this relies on the Unix semantics that
Packit Service 82fcde
     a file is not really removed until it is closed.  */
Packit Service 82fcde
  (void) __unlink (buf);
Packit Service 82fcde
Packit Service 82fcde
  if ((f = _IO_old_fdopen (fd, "w+b")) == NULL)
Packit Service 82fcde
    __close (fd);
Packit Service 82fcde
Packit Service 82fcde
  return f;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
compat_symbol (libc, __old_tmpfile, tmpfile, GLIBC_2_0);
Packit Service 82fcde
#endif