OpenCoverage

mktemp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/mktemp.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Create a temporary file or directory, safely.-
2 Copyright (C) 2007-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Written by Jim Meyering and Eric Blake. */-
18-
19#include <config.h>-
20#include <sys/types.h>-
21#include <getopt.h>-
22-
23#include "system.h"-
24-
25#include "close-stream.h"-
26#include "die.h"-
27#include "error.h"-
28#include "filenamecat.h"-
29#include "quote.h"-
30#include "tempname.h"-
31-
32/* The official name of this program (e.g., no 'g' prefix). */-
33#define PROGRAM_NAME "mktemp"-
34-
35#define AUTHORS \-
36 proper_name ("Jim Meyering"), \-
37 proper_name ("Eric Blake")-
38-
39static const char *default_template = "tmp.XXXXXXXXXX";-
40-
41/* For long options that have no equivalent short option, use a-
42 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
43enum-
44{-
45 SUFFIX_OPTION = CHAR_MAX + 1,-
46};-
47-
48static struct option const longopts[] =-
49{-
50 {"directory", no_argument, NULL, 'd'},-
51 {"quiet", no_argument, NULL, 'q'},-
52 {"dry-run", no_argument, NULL, 'u'},-
53 {"suffix", required_argument, NULL, SUFFIX_OPTION},-
54 {"tmpdir", optional_argument, NULL, 'p'},-
55 {GETOPT_HELP_OPTION_DECL},-
56 {GETOPT_VERSION_OPTION_DECL},-
57 {NULL, 0, NULL, 0}-
58};-
59-
60void-
61usage (int status)-
62{-
63 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 13 times by 1 test
Evaluated by:
  • mktemp
5-13
64 emit_try_help ();
executed 5 times by 1 test: end of block
Executed by:
  • mktemp
5
65 else-
66 {-
67 printf (_("Usage: %s [OPTION]... [TEMPLATE]\n"), program_name);-
68 fputs (_("\-
69Create a temporary file or directory, safely, and print its name.\n\-
70TEMPLATE must contain at least 3 consecutive 'X's in last component.\n\-
71If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied.\n\-
72"), stdout);-
73 fputs (_("\-
74Files are created u+rw, and directories u+rwx, minus umask restrictions.\n\-
75"), stdout);-
76 fputs ("\n", stdout);-
77 fputs (_("\-
78 -d, --directory create a directory, not a file\n\-
79 -u, --dry-run do not create anything; merely print a name (unsafe)\n\-
80 -q, --quiet suppress diagnostics about file/dir-creation failure\n\-
81"), stdout);-
82 fputs (_("\-
83 --suffix=SUFF append SUFF to TEMPLATE; SUFF must not contain a slash.\n\-
84 This option is implied if TEMPLATE does not end in X\n\-
85"), stdout);-
86 fputs (_("\-
87 -p DIR, --tmpdir[=DIR] interpret TEMPLATE relative to DIR; if DIR is not\n\-
88 specified, use $TMPDIR if set, else /tmp. With\n\-
89 this option, TEMPLATE must not be an absolute name;\n\-
90 unlike with -t, TEMPLATE may contain slashes, but\n\-
91 mktemp creates only the final component\n\-
92"), stdout);-
93 fputs (_("\-
94 -t interpret TEMPLATE as a single file name component,\n\-
95 relative to a directory: $TMPDIR, if set; else the\n\-
96 directory specified via -p; else /tmp [deprecated]\n\-
97"), stdout);-
98 fputs (HELP_OPTION_DESCRIPTION, stdout);-
99 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
100 emit_ancillary_info (PROGRAM_NAME);-
101 }
executed 13 times by 1 test: end of block
Executed by:
  • mktemp
13
102-
103 exit (status);
executed 18 times by 1 test: exit (status);
Executed by:
  • mktemp
18
104}-
105-
106static size_t-
107count_consecutive_X_s (const char *s, size_t len)-
108{-
109 size_t n = 0;-
110 for ( ; len && s[len-1] == 'X'; len--)
lenDescription
TRUEevaluated 2874 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
s[len-1] == 'X'Description
TRUEevaluated 2304 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 570 times by 1 test
Evaluated by:
  • mktemp
1-2874
111 ++n;
executed 2304 times by 1 test: ++n;
Executed by:
  • mktemp
2304
112 return n;
executed 571 times by 1 test: return n;
Executed by:
  • mktemp
571
113}-
114-
115static int-
116mkstemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)-
117{-
118 return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_FILE,
executed 16 times by 1 test: return gen_tempname_len (tmpl, suff_len, 0, dry_run ? 2 : 0, x_len);
Executed by:
  • mktemp
16
119 x_len);
executed 16 times by 1 test: return gen_tempname_len (tmpl, suff_len, 0, dry_run ? 2 : 0, x_len);
Executed by:
  • mktemp
16
120}-
121-
122static int-
123mkdtemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)-
124{-
125 return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_DIR,
executed 550 times by 1 test: return gen_tempname_len (tmpl, suff_len, 0, dry_run ? 2 : 1, x_len);
Executed by:
  • mktemp
550
126 x_len);
executed 550 times by 1 test: return gen_tempname_len (tmpl, suff_len, 0, dry_run ? 2 : 1, x_len);
Executed by:
  • mktemp
550
127}-
128-
129/* True if we have already closed standard output. */-
130static bool stdout_closed;-
131-
132/* Avoid closing stdout twice. Since we conditionally call-
133 close_stream (stdout) in order to decide whether to clean up a-
134 temporary file, the exit hook needs to know whether to do all of-
135 close_stdout or just the stderr half. */-
136static void-
137maybe_close_stdout (void)-
138{-
139 if (!stdout_closed)
!stdout_closedDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 561 times by 1 test
Evaluated by:
  • mktemp
36-561
140 close_stdout ();
executed 36 times by 1 test: close_stdout ();
Executed by:
  • mktemp
36
141 else if (close_stream (stderr) != 0)
close_stream ( stderr ) != 0Description
TRUEnever evaluated
FALSEevaluated 561 times by 1 test
Evaluated by:
  • mktemp
0-561
142 _exit (EXIT_FAILURE);
never executed: _exit ( 1 );
0
143}
executed 597 times by 1 test: end of block
Executed by:
  • mktemp
597
144-
145int-
146main (int argc, char **argv)-
147{-
148 char const *dest_dir;-
149 char const *dest_dir_arg = NULL;-
150 bool suppress_file_err = false;-
151 int c;-
152 unsigned int n_args;-
153 char *template;-
154 char *suffix = NULL;-
155 bool use_dest_dir = false;-
156 bool deprecated_t_option = false;-
157 bool create_directory = false;-
158 bool dry_run = false;-
159 int status = EXIT_SUCCESS;-
160 size_t x_count;-
161 size_t suffix_len;-
162 char *dest_name;-
163-
164 initialize_main (&argc, &argv);-
165 set_program_name (argv[0]);-
166 setlocale (LC_ALL, "");-
167 bindtextdomain (PACKAGE, LOCALEDIR);-
168 textdomain (PACKAGE);-
169-
170 atexit (maybe_close_stdout);-
171-
172 while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, NULL)) != -1)
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 1688 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 577 times by 1 test
Evaluated by:
  • mktemp
577-1688
173 {-
174 switch (c)-
175 {-
176 case 'd':
executed 554 times by 1 test: case 'd':
Executed by:
  • mktemp
554
177 create_directory = true;-
178 break;
executed 554 times by 1 test: break;
Executed by:
  • mktemp
554
179 case 'p':
executed 547 times by 1 test: case 'p':
Executed by:
  • mktemp
547
180 dest_dir_arg = optarg;-
181 use_dest_dir = true;-
182 break;
executed 547 times by 1 test: break;
Executed by:
  • mktemp
547
183 case 'q':
executed 6 times by 1 test: case 'q':
Executed by:
  • mktemp
6
184 suppress_file_err = true;-
185 break;
executed 6 times by 1 test: break;
Executed by:
  • mktemp
6
186 case 't':
executed 545 times by 1 test: case 't':
Executed by:
  • mktemp
545
187 use_dest_dir = true;-
188 deprecated_t_option = true;-
189 break;
executed 545 times by 1 test: break;
Executed by:
  • mktemp
545
190 case 'u':
executed 6 times by 1 test: case 'u':
Executed by:
  • mktemp
6
191 dry_run = true;-
192 break;
executed 6 times by 1 test: break;
Executed by:
  • mktemp
6
193-
194 case SUFFIX_OPTION:
executed 10 times by 1 test: case SUFFIX_OPTION:
Executed by:
  • mktemp
10
195 suffix = optarg;-
196 break;
executed 10 times by 1 test: break;
Executed by:
  • mktemp
10
197-
198 case_GETOPT_HELP_CHAR;
never executed: break;
executed 13 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • mktemp
0-13
199-
200 case 'V': /* Undocumented alias, for compatibility with the original
never executed: case 'V':
0
201 mktemp program. */-
202 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • mktemp
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • mktemp
0-4
203 default:
executed 3 times by 1 test: default:
Executed by:
  • mktemp
3
204 usage (EXIT_FAILURE);-
205 }
never executed: end of block
0
206 }-
207-
208 n_args = argc - optind;-
209 if (2 <= n_args)
2 <= n_argsDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 575 times by 1 test
Evaluated by:
  • mktemp
2-575
210 {-
211 error (0, 0, _("too many templates"));-
212 usage (EXIT_FAILURE);-
213 }
never executed: end of block
0
214-
215 if (n_args == 0)
n_args == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 572 times by 1 test
Evaluated by:
  • mktemp
3-572
216 {-
217 use_dest_dir = true;-
218 template = (char *) default_template;-
219 }
executed 3 times by 1 test: end of block
Executed by:
  • mktemp
3
220 else-
221 {-
222 template = argv[optind];-
223 }
executed 572 times by 1 test: end of block
Executed by:
  • mktemp
572
224-
225 if (suffix)
suffixDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 566 times by 1 test
Evaluated by:
  • mktemp
9-566
226 {-
227 size_t len = strlen (template);-
228 if (!len || template[len - 1] != 'X')
!lenDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 8 times by 1 test
Evaluated by:
  • mktemp
template[len - 1] != 'X'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 7 times by 1 test
Evaluated by:
  • mktemp
1-8
229 {-
230 die (EXIT_FAILURE, 0,-
231 _("with --suffix, template %s must end in X"),-
232 quote (template));-
233 }
never executed: end of block
0
234 suffix_len = strlen (suffix);-
235 dest_name = xcharalloc (len + suffix_len + 1);-
236 memcpy (dest_name, template, len);-
237 memcpy (dest_name + len, suffix, suffix_len + 1);-
238 template = dest_name;-
239 suffix = dest_name + len;-
240 }
executed 7 times by 1 test: end of block
Executed by:
  • mktemp
7
241 else-
242 {-
243 template = xstrdup (template);-
244 suffix = strrchr (template, 'X');-
245 if (!suffix)
!suffixDescription
TRUEnever evaluated
FALSEevaluated 566 times by 1 test
Evaluated by:
  • mktemp
0-566
246 suffix = strchr (template, '\0');
never executed: suffix = (__extension__ (__builtin_constant_p ( '\0' ) && !__builtin_constant_p ( template ) && ( '\0' ) == '\0' ? (char *) __rawmemchr ( template , '\0' ) : __builtin_strchr ( template , '\0' ))) ;
__builtin_constant_p ( '\0' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_con...p ( template )Description
TRUEnever evaluated
FALSEnever evaluated
( '\0' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
247 else-
248 suffix++;
executed 566 times by 1 test: suffix++;
Executed by:
  • mktemp
566
249 suffix_len = strlen (suffix);-
250 }
executed 566 times by 1 test: end of block
Executed by:
  • mktemp
566
251-
252 /* At this point, template is malloc'd, and suffix points into template. */-
253 if (suffix_len && last_component (suffix) != suffix)
suffix_lenDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 561 times by 1 test
Evaluated by:
  • mktemp
last_component...fix) != suffixDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 10 times by 1 test
Evaluated by:
  • mktemp
2-561
254 {-
255 die (EXIT_FAILURE, 0,-
256 _("invalid suffix %s, contains directory separator"),-
257 quote (suffix));-
258 }
never executed: end of block
0
259 x_count = count_consecutive_X_s (template, suffix - template);-
260 if (x_count < 3)
x_count < 3Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 568 times by 1 test
Evaluated by:
  • mktemp
3-568
261 die (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"too few X's in template %s\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "too few X's in template %s" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "too few X's in template %s" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • mktemp
3
262-
263 if (use_dest_dir)
use_dest_dirDescription
TRUEevaluated 549 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 19 times by 1 test
Evaluated by:
  • mktemp
19-549
264 {-
265 if (deprecated_t_option)
deprecated_t_optionDescription
TRUEevaluated 544 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 5 times by 1 test
Evaluated by:
  • mktemp
5-544
266 {-
267 char *env = getenv ("TMPDIR");-
268 if (env && *env)
envDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 543 times by 1 test
Evaluated by:
  • mktemp
*envDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
0-543
269 dest_dir = env;
executed 1 time by 1 test: dest_dir = env;
Executed by:
  • mktemp
1
270 else if (dest_dir_arg && *dest_dir_arg)
dest_dir_argDescription
TRUEevaluated 543 times by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
*dest_dir_argDescription
TRUEevaluated 543 times by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
0-543
271 dest_dir = dest_dir_arg;
executed 543 times by 1 test: dest_dir = dest_dir_arg;
Executed by:
  • mktemp
543
272 else-
273 dest_dir = "/tmp";
never executed: dest_dir = "/tmp";
0
274-
275 if (last_component (template) != template)
last_component...e) != templateDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 543 times by 1 test
Evaluated by:
  • mktemp
1-543
276 die (EXIT_FAILURE, 0,
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s, contains directory separator\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext...parator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s, contains directory separator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
277 _("invalid template, %s, contains directory separator"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s, contains directory separator\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext...parator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s, contains directory separator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
278 quote (template));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s, contains directory separator\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext...parator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s, contains directory separator" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
279 }
executed 543 times by 1 test: end of block
Executed by:
  • mktemp
543
280 else-
281 {-
282 if (dest_dir_arg && *dest_dir_arg)
dest_dir_argDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
*dest_dir_argDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
0-3
283 dest_dir = dest_dir_arg;
executed 2 times by 1 test: dest_dir = dest_dir_arg;
Executed by:
  • mktemp
2
284 else-
285 {-
286 char *env = getenv ("TMPDIR");-
287 dest_dir = (env && *env ? env : "/tmp");
envDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
*envDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
0-3
288 }
executed 3 times by 1 test: end of block
Executed by:
  • mktemp
3
289 if (IS_ABSOLUTE_FILE_NAME (template))
(((template)[0]) == '/')Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 4 times by 1 test
Evaluated by:
  • mktemp
0 != 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • mktemp
0-4
290 die (EXIT_FAILURE, 0,
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s; with --tmpdir,\" \" it may not be absolute\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 ...) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s; with --tmpdir," " it may not be absolute" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
291 _("invalid template, %s; with --tmpdir,"
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s; with --tmpdir,\" \" it may not be absolute\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 ...) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s; with --tmpdir," " it may not be absolute" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
292 " it may not be absolute"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s; with --tmpdir,\" \" it may not be absolute\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 ...) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s; with --tmpdir," " it may not be absolute" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
293 quote (template));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid template, %s; with --tmpdir,\" \" it may not be absolute\", 5), quote (template)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 ...) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid template, %s; with --tmpdir," " it may not be absolute" , 5) , quote (template)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • mktemp
1
294 }
executed 4 times by 1 test: end of block
Executed by:
  • mktemp
4
295-
296 dest_name = file_name_concat (dest_dir, template, NULL);-
297 free (template);-
298 template = dest_name;-
299 /* Note that suffix is now invalid. */-
300 }
executed 547 times by 1 test: end of block
Executed by:
  • mktemp
547
301-
302 /* Make a copy to be used in case of diagnostic, since failing-
303 mkstemp may leave the buffer in an undefined state. */-
304 dest_name = xstrdup (template);-
305-
306 if (create_directory)
create_directoryDescription
TRUEevaluated 550 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 16 times by 1 test
Evaluated by:
  • mktemp
16-550
307 {-
308 int err = mkdtemp_len (dest_name, suffix_len, x_count, dry_run);-
309 if (err != 0)
err != 0Description
TRUEnever evaluated
FALSEevaluated 550 times by 1 test
Evaluated by:
  • mktemp
0-550
310 {-
311 if (!suppress_file_err)
!suppress_file_errDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 error (0, errno, _("failed to create directory via template %s"),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to create directory via template %s" , 5) , quote (template));
0
313 quote (template));
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to create directory via template %s" , 5) , quote (template));
0
314 status = EXIT_FAILURE;-
315 }
never executed: end of block
0
316 }
executed 550 times by 1 test: end of block
Executed by:
  • mktemp
550
317 else-
318 {-
319 int fd = mkstemp_len (dest_name, suffix_len, x_count, dry_run);-
320 if (fd < 0 || (!dry_run && close (fd) != 0))
fd < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 15 times by 1 test
Evaluated by:
  • mktemp
!dry_runDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 3 times by 1 test
Evaluated by:
  • mktemp
close (fd) != 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • mktemp
0-15
321 {-
322 if (!suppress_file_err)
!suppress_file_errDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
FALSEnever evaluated
0-1
323 error (0, errno, _("failed to create file via template %s"),
executed 1 time by 1 test: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to create file via template %s" , 5) , quote (template));
Executed by:
  • mktemp
1
324 quote (template));
executed 1 time by 1 test: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to create file via template %s" , 5) , quote (template));
Executed by:
  • mktemp
1
325 status = EXIT_FAILURE;-
326 }
executed 1 time by 1 test: end of block
Executed by:
  • mktemp
1
327 }
executed 16 times by 1 test: end of block
Executed by:
  • mktemp
16
328-
329 if (status == EXIT_SUCCESS)
status == 0Description
TRUEevaluated 565 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 1 time by 1 test
Evaluated by:
  • mktemp
1-565
330 {-
331 puts (dest_name);-
332 /* If we created a file, but then failed to output the file-
333 name, we should clean up the mess before failing. */-
334 if (!dry_run && ((stdout_closed = true), close_stream (stdout) != 0))
!dry_runDescription
TRUEevaluated 561 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 4 times by 1 test
Evaluated by:
  • mktemp
((stdout_close...stdout ) != 0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 557 times by 1 test
Evaluated by:
  • mktemp
4-561
335 {-
336 int saved_errno = errno;-
337 remove (dest_name);-
338 if (!suppress_file_err)
!suppress_file_errDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
FALSEevaluated 2 times by 1 test
Evaluated by:
  • mktemp
2
339 error (0, saved_errno, _("write error"));
executed 2 times by 1 test: error (0, saved_errno, dcgettext (((void *)0), "write error" , 5) );
Executed by:
  • mktemp
2
340 status = EXIT_FAILURE;-
341 }
executed 4 times by 1 test: end of block
Executed by:
  • mktemp
4
342 }
executed 565 times by 1 test: end of block
Executed by:
  • mktemp
565
343-
344#ifdef lint-
345 free (dest_name);-
346 free (template);-
347#endif-
348-
349 return status;
executed 566 times by 1 test: return status;
Executed by:
  • mktemp
566
350}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2