1 /* Temporary file handling for tests.
2 Copyright (C) 1998-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* This is required to get an mkstemp which can create large files on
20 some 32-bit platforms. */
21 #define _FILE_OFFSET_BITS 64
23 #include <support/temp_file.h>
24 #include <support/temp_file-internal.h>
25 #include <support/support.h>
33 /* List of temporary files. */
34 static struct temp_name_list
40 /* Location of the temporary files. Set by the test skeleton via
41 support_set_test_dir. The string is not be freed. */
42 static const char *test_dir
= _PATH_TMP
;
45 add_temp_file (const char *name
)
47 struct temp_name_list
*newp
48 = (struct temp_name_list
*) xcalloc (sizeof (*newp
), 1);
49 char *newname
= strdup (name
);
53 if (temp_name_list
== NULL
)
54 temp_name_list
= (struct temp_name_list
*) &newp
->q
;
56 insque (newp
, temp_name_list
);
63 create_temp_file (const char *base
, char **filename
)
68 fname
= (char *) xmalloc (strlen (test_dir
) + 1 + strlen (base
)
70 strcpy (stpcpy (stpcpy (stpcpy (fname
, test_dir
), "/"), base
), "XXXXXX");
75 printf ("cannot open temporary file '%s': %m\n", fname
);
80 add_temp_file (fname
);
89 /* Helper functions called by the test skeleton follow. */
92 support_set_test_dir (const char *path
)
98 support_delete_temp_files (void)
100 while (temp_name_list
!= NULL
)
102 remove (temp_name_list
->name
);
103 free (temp_name_list
->name
);
105 struct temp_name_list
*next
106 = (struct temp_name_list
*) temp_name_list
->q
.q_forw
;
107 free (temp_name_list
);
108 temp_name_list
= next
;
113 support_print_temp_files (FILE *f
)
115 if (temp_name_list
!= NULL
)
117 struct temp_name_list
*n
;
118 fprintf (f
, "temp_files=(\n");
119 for (n
= temp_name_list
;
121 n
= (struct temp_name_list
*) n
->q
.q_forw
)
122 fprintf (f
, " '%s'\n", n
->name
);