about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/tempname.c41
-rw-r--r--sysdeps/unix/sysv/linux/configure3
2 files changed, 44 insertions, 0 deletions
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
index f2da66a211..c70a6e8d35 100644
--- a/sysdeps/posix/tempname.c
+++ b/sysdeps/posix/tempname.c
@@ -27,6 +27,11 @@ Cambridge, MA 02139, USA.  */
 #include <fcntl.h>
 #include <unistd.h>
 
+#ifdef USE_IN_LIBIO
+# include "libioP.h"
+# include <libio.h>
+#endif
+
 /* Return nonzero if DIR is an existent directory.  */
 static int
 DEFUN(diraccess, (dir), CONST char *dir)
@@ -169,6 +174,41 @@ DEFUN(__stdio_gen_tempname, (dir, pfx, dir_search, lenptr, streamptr),
 	    {
 	      /* We got a new file that did not previously exist.
 		 Create a stream for it.  */
+#ifdef USE_IN_LIBIO
+	      int save;
+	      struct _IO_FILE_plus *fp;
+
+	      fp = (struct _IO_FILE_plus *)
+		malloc(sizeof (struct _IO_FILE_plus));
+	      if (fp == NULL)
+		{
+		  /* We lost trying to create a stream (out of memory?).
+		     Nothing to do but remove the file, close the descriptor,
+		     and return failure.  */
+		  save = errno;
+		lose:
+		  (void) remove (buf);
+		  (void) __close (fd);
+		  errno = save;
+		  return NULL;
+		}
+	      _IO_init (&fp->file, 0);
+	      _IO_JUMPS (&fp->file) = &_IO_file_jumps;
+	      _IO_file_init (&fp->file);
+# if !_IO_UNIFIED_JUMPTABLES
+	      fp->vtable = NULL;
+# endif
+	      if (_IO_file_attach (&fp->file, fd) == NULL)
+		{
+		  save = errno;
+		  free (fp);
+		  goto lose;
+		}
+	      fp->file._flags &= ~_IO_DELETE_DONT_CLOSE;
+	      fp->file._IO_file_flags = 0;
+
+	      *streamptr = (FILE *) fp;
+#else
 	      *streamptr = __newstream ();
 	      if (*streamptr == NULL)
 		{
@@ -185,6 +225,7 @@ DEFUN(__stdio_gen_tempname, (dir, pfx, dir_search, lenptr, streamptr),
 	      (*streamptr)->__mode.__write = 1;
 	      (*streamptr)->__mode.__read = 1;
 	      (*streamptr)->__mode.__binary = 1;
+#endif
 	    }
 	  else
 	    continue;
diff --git a/sysdeps/unix/sysv/linux/configure b/sysdeps/unix/sysv/linux/configure
new file mode 100644
index 0000000000..63693e088e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/configure
@@ -0,0 +1,3 @@
+# On Linux, the default is to use libio instead of stdio.
+
+test $stdio = default && stdio=libio