Back to index

glibc  2.9
tmpfile.c File Reference
#include <stdio.h>
#include <hurd.h>
#include <hurd/fs.h>
#include <hurd/fd.h>
#include <fcntl.h>
#include <unistd.h>
#include <iolibio.h>
#include <shlib-compat.h>

Go to the source code of this file.


FILE__tmpfile (void)
 versioned_symbol (libc, __tmpfile, tmpfile, GLIBC_2_1)

Function Documentation

FILE* __tmpfile ( void  )

Definition at line 33 of file tmpfile.c.

  error_t err;
  file_t file;
  int fd;
  FILE *f;

  /* Get a port to the directory that will contain the file.  */
  const char *dirname = __secure_getenv ("TMPDIR") ?: P_tmpdir;
  file_t dir = __file_name_lookup (dirname, 0, 0);
  if (dir == MACH_PORT_NULL)
    return NULL;

  /* Create an unnamed file in the temporary directory.  */
  err = __dir_mkfile (dir, O_RDWR, S_IRUSR | S_IWUSR, &file);
  __mach_port_deallocate (__mach_task_self (), dir);
  if (err)
    return __hurd_fail (err), NULL;

  /* Get a file descriptor for that port.  POSIX.1 requires that streams
     returned by tmpfile allocate file descriptors as fopen would.  */
  fd = _hurd_intern_fd (file, O_RDWR, 1); /* dealloc on error */
  if (fd < 0)
    return NULL;

  /* Open a stream on the unnamed file.
     It will cease to exist when this stream is closed.  */
  if ((f = INTUSE(_IO_fdopen) (fd, "w+b")) == NULL)
    __close (fd);

  return f;

Here is the call graph for this function:

versioned_symbol ( libc  ,
__tmpfile  ,
tmpfile  ,