From 891e44e5310ed3d2fb17c8277b2697f11da18f76 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 20 Apr 2002 21:32:49 +0000 Subject: 2002-04-19 Roland McGrath * sysdeps/mach/hurd/tmpfile.c: Create a file descriptor and use fdopen. --- sysdeps/mach/hurd/tmpfile.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'sysdeps/mach/hurd/tmpfile.c') diff --git a/sysdeps/mach/hurd/tmpfile.c b/sysdeps/mach/hurd/tmpfile.c index 90be7206e9..e738dc91c7 100644 --- a/sysdeps/mach/hurd/tmpfile.c +++ b/sysdeps/mach/hurd/tmpfile.c @@ -1,5 +1,5 @@ /* Open a stdio stream on an anonymous temporary file. Hurd version. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001,02 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #ifdef USE_IN_LIBIO # include @@ -37,6 +39,7 @@ tmpfile (void) { error_t err; file_t file; + int fd; FILE *f; /* Get a port to the directory that will contain the file. */ @@ -51,10 +54,16 @@ tmpfile (void) if (err) return __hurd_fail (err), NULL; - /* Open a stream on the port to the unnamed file. + /* 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 = __fopenport (file, "w+b")) == NULL) - __mach_port_deallocate (__mach_task_self (), file); + if ((f = __fdopen (fd, "w+b")) == NULL) + __close (fd); return f; } -- cgit v1.2.3