about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-07-22 22:18:27 +0000
committerUlrich Drepper <drepper@redhat.com>2002-07-22 22:18:27 +0000
commit10e62564606e5c51d0d3426d1f26ad4aaa34b70a (patch)
tree9664a4e3ab9a773d802881ccb41f29711f8efff8
parentbb379770049386cd7996bcbe3938dd4f17a88343 (diff)
downloadglibc-10e62564606e5c51d0d3426d1f26ad4aaa34b70a.tar.gz
glibc-10e62564606e5c51d0d3426d1f26ad4aaa34b70a.tar.xz
glibc-10e62564606e5c51d0d3426d1f26ad4aaa34b70a.zip
(create_temp_file): New function.
-rw-r--r--test-skeleton.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/test-skeleton.c b/test-skeleton.c
index c1fa96c22f..3216b94511 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -1,5 +1,5 @@
 /* Skeleton for test programs.
-   Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
@@ -90,6 +90,38 @@ delete_temp_files (void)
     }
 }
 
+/* Create a temporary file.  */
+static int
+__attribute__ ((unused))
+create_temp_file (const char *base, char **filename)
+{
+  char *fname;
+  int fd;
+
+  fname = (char *) malloc (strlen (test_dir) + 1 + strlen (base)
+			   + sizeof ("XXXXXX"));
+  if (fname == NULL)
+    {
+      puts ("out of memory");
+      return -1;
+    }
+  strcpy (stpcpy (stpcpy (stpcpy (fname, test_dir), "/"), base), "XXXXXX");
+
+  fd = mkstemp (fname);
+  if (fd == -1)
+    {
+      printf ("cannot open temporary file '%s': %m\n", fname);
+      free (fname);
+      return -1;
+    }
+
+  add_temp_file (fname);
+  if (filename != NULL)
+    *filename = fname;
+
+  return fd;
+}
+
 /* Timeout handler.  We kill the child and exit with an error.  */
 static void
 __attribute__ ((noreturn))