Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/lib/tempname.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | static inline | - | ||||||||||||
13 | _Bool __attribute__ ((__pure__)) | - | ||||||||||||
14 | - | |||||||||||||
15 | check_x_suffix (char const *s, size_t len) | - | ||||||||||||
16 | { | - | ||||||||||||
17 | return executed 596 times by 4 tests: len <= return len <= __builtin_strspn ( s , "X" ) ; Executed by:
executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
18 | __builtin_strspn ( executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
19 | s executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
20 | , executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
21 | "X" executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
22 | ) executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
23 | ; executed 596 times by 4 tests: return len <= __builtin_strspn ( s , "X" ) ; Executed by:
| 596 | ||||||||||||
24 | } | - | ||||||||||||
25 | - | |||||||||||||
26 | - | |||||||||||||
27 | static const char letters[] = | - | ||||||||||||
28 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | - | ||||||||||||
29 | - | |||||||||||||
30 | int | - | ||||||||||||
31 | try_tempname_len (char *tmpl, int suffixlen, void *args, | - | ||||||||||||
32 | int (*tryfunc) (char *, void *), size_t x_suffix_len) | - | ||||||||||||
33 | { | - | ||||||||||||
34 | size_t len; | - | ||||||||||||
35 | char *XXXXXX; | - | ||||||||||||
36 | unsigned int count; | - | ||||||||||||
37 | int fd = -1; | - | ||||||||||||
38 | int save_errno = | - | ||||||||||||
39 | (*__errno_location ()) | - | ||||||||||||
40 | ; | - | ||||||||||||
41 | struct randint_source *rand_src; | - | ||||||||||||
42 | unsigned int attempts = (62 * 62 * 62); | - | ||||||||||||
43 | - | |||||||||||||
44 | - | |||||||||||||
45 | len = strlen (tmpl); | - | ||||||||||||
46 | if (len < x_suffix_len + suffixlen
| 0-596 | ||||||||||||
47 | || ! check_x_suffix (&tmpl[len - x_suffix_len - suffixlen],
| 0-596 | ||||||||||||
48 | x_suffix_len)
| 0-596 | ||||||||||||
49 | { | - | ||||||||||||
50 | - | |||||||||||||
51 | (*__errno_location ()) | - | ||||||||||||
52 | = ( | - | ||||||||||||
53 | 22 | - | ||||||||||||
54 | ); | - | ||||||||||||
55 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
56 | } | - | ||||||||||||
57 | - | |||||||||||||
58 | - | |||||||||||||
59 | XXXXXX = &tmpl[len - x_suffix_len - suffixlen]; | - | ||||||||||||
60 | - | |||||||||||||
61 | - | |||||||||||||
62 | rand_src = randint_all_new ( | - | ||||||||||||
63 | ((void *)0) | - | ||||||||||||
64 | , x_suffix_len); | - | ||||||||||||
65 | if (! rand_src
| 0-596 | ||||||||||||
66 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
67 | - | |||||||||||||
68 | for (count = 0; count < attempts
| 0-596 | ||||||||||||
69 | { | - | ||||||||||||
70 | size_t i; | - | ||||||||||||
71 | - | |||||||||||||
72 | for (i = 0; i < x_suffix_len
| 596-2470 | ||||||||||||
73 | XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)]; executed 2470 times by 4 tests: XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)]; Executed by:
| 2470 | ||||||||||||
74 | - | |||||||||||||
75 | fd = tryfunc (tmpl, args); | - | ||||||||||||
76 | if (fd >= 0
| 2-594 | ||||||||||||
77 | { | - | ||||||||||||
78 | - | |||||||||||||
79 | (*__errno_location ()) | - | ||||||||||||
80 | = (save_errno); | - | ||||||||||||
81 | goto executed 594 times by 4 tests: done;goto done; Executed by:
executed 594 times by 4 tests: goto done; Executed by:
| 594 | ||||||||||||
82 | } | - | ||||||||||||
83 | else if ( | - | ||||||||||||
84 | (*
| 0-2 | ||||||||||||
85 | !=
| 0-2 | ||||||||||||
86 | 17
| 0-2 | ||||||||||||
87 | ) | - | ||||||||||||
88 | { | - | ||||||||||||
89 | fd = -1; | - | ||||||||||||
90 | goto executed 2 times by 2 tests: done;goto done; Executed by:
executed 2 times by 2 tests: goto done; Executed by:
| 2 | ||||||||||||
91 | } | - | ||||||||||||
92 | } never executed: end of block | 0 | ||||||||||||
93 | - | |||||||||||||
94 | randint_all_free (rand_src); | - | ||||||||||||
95 | - | |||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | (*__errno_location ()) | - | ||||||||||||
99 | = ( | - | ||||||||||||
100 | 17 | - | ||||||||||||
101 | ); | - | ||||||||||||
102 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
103 | - | |||||||||||||
104 | done: | - | ||||||||||||
105 | { | - | ||||||||||||
106 | int saved_errno = | - | ||||||||||||
107 | (*__errno_location ()) | - | ||||||||||||
108 | ; | - | ||||||||||||
109 | randint_all_free (rand_src); | - | ||||||||||||
110 | - | |||||||||||||
111 | (*__errno_location ()) | - | ||||||||||||
112 | = (saved_errno); | - | ||||||||||||
113 | } | - | ||||||||||||
114 | return executed 596 times by 4 tests: fd;return fd; Executed by:
executed 596 times by 4 tests: return fd; Executed by:
| 596 | ||||||||||||
115 | } | - | ||||||||||||
116 | - | |||||||||||||
117 | static int | - | ||||||||||||
118 | try_file (char *tmpl, void *flags) | - | ||||||||||||
119 | { | - | ||||||||||||
120 | int *openflags = flags; | - | ||||||||||||
121 | return executed 13 times by 1 test: open (tmpl,return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
122 | (*openflags & ~ executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
123 | 0003 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
124 | ) executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
125 | | executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
126 | 02 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
127 | | executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
128 | 0100 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
129 | | executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
130 | 0200 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
131 | , executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
132 | 0400 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
133 | | executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
134 | 0200 executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
135 | ); executed 13 times by 1 test: return open (tmpl, (*openflags & ~ 0003 ) | 02 | 0100 | 0200 , 0400 | 0200 ); Executed by:
| 13 | ||||||||||||
136 | } | - | ||||||||||||
137 | - | |||||||||||||
138 | static int | - | ||||||||||||
139 | try_dir (char *tmpl, void *flags __attribute__ ((__unused__))) | - | ||||||||||||
140 | { | - | ||||||||||||
141 | return executed 549 times by 1 test: mkdir (tmpl, return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
142 | 0400 executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
143 | | executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
144 | 0200 executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
145 | | executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
146 | 0100 executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
147 | ); executed 549 times by 1 test: return mkdir (tmpl, 0400 | 0200 | 0100 ); Executed by:
| 549 | ||||||||||||
148 | } | - | ||||||||||||
149 | - | |||||||||||||
150 | static int | - | ||||||||||||
151 | try_nocreate (char *tmpl, void *flags __attribute__ ((__unused__))) | - | ||||||||||||
152 | { | - | ||||||||||||
153 | struct stat st; | - | ||||||||||||
154 | - | |||||||||||||
155 | if (lstat (tmpl, &st) == 0
| 0-4 | ||||||||||||
156 | (*
| 0-4 | ||||||||||||
157 | ==
| 0-4 | ||||||||||||
158 | 75
| 0-4 | ||||||||||||
159 | ) | - | ||||||||||||
160 | - | |||||||||||||
161 | (* never executed: __errno_location ()) (*__errno_location ()) = ( 17 ); never executed: (*__errno_location ()) = ( 17 ); | 0 | ||||||||||||
162 | = ( never executed: (*__errno_location ()) = ( 17 ); | 0 | ||||||||||||
163 | 17 never executed: (*__errno_location ()) = ( 17 ); | 0 | ||||||||||||
164 | ); never executed: (*__errno_location ()) = ( 17 ); | 0 | ||||||||||||
165 | return executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
| 4 | ||||||||||||
166 | (*__errno_location ()) executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
| 4 | ||||||||||||
167 | == executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
| 4 | ||||||||||||
168 | 2 executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
| 4 | ||||||||||||
169 | ? 0 : -1; executed 4 times by 1 test: return (*__errno_location ()) == 2 ? 0 : -1; Executed by:
| 4 | ||||||||||||
170 | } | - | ||||||||||||
171 | int | - | ||||||||||||
172 | gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind, | - | ||||||||||||
173 | size_t x_suffix_len) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | int (*tryfunc) (char *, void *); | - | ||||||||||||
176 | - | |||||||||||||
177 | switch (kind) | - | ||||||||||||
178 | { | - | ||||||||||||
179 | case executed 13 times by 1 test: 0:case 0: Executed by:
executed 13 times by 1 test: case 0: Executed by:
| 13 | ||||||||||||
180 | tryfunc = try_file; | - | ||||||||||||
181 | break; executed 13 times by 1 test: break; Executed by:
| 13 | ||||||||||||
182 | - | |||||||||||||
183 | case executed 549 times by 1 test: 1:case 1: Executed by:
executed 549 times by 1 test: case 1: Executed by:
| 549 | ||||||||||||
184 | tryfunc = try_dir; | - | ||||||||||||
185 | break; executed 549 times by 1 test: break; Executed by:
| 549 | ||||||||||||
186 | - | |||||||||||||
187 | case executed 4 times by 1 test: 2:case 2: Executed by:
executed 4 times by 1 test: case 2: Executed by:
| 4 | ||||||||||||
188 | tryfunc = try_nocreate; | - | ||||||||||||
189 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
190 | - | |||||||||||||
191 | default never executed: :default: never executed: default: | 0 | ||||||||||||
192 | - | |||||||||||||
193 | (( | - | ||||||||||||
194 | ! "invalid KIND in __gen_tempname" | - | ||||||||||||
195 | ) ? (void) (0) : __assert_fail ( | - | ||||||||||||
196 | "! \"invalid KIND in __gen_tempname\"" | - | ||||||||||||
197 | , "lib/tempname.c", 327, __PRETTY_FUNCTION__)) | - | ||||||||||||
198 | ; | - | ||||||||||||
199 | abort (); never executed: abort (); | 0 | ||||||||||||
200 | } | - | ||||||||||||
201 | return executed 566 times by 1 test: try_tempname_len (tmpl, suffixlen, &flags, tryfunc, x_suffix_len);return try_tempname_len (tmpl, suffixlen, &flags, tryfunc, x_suffix_len); Executed by:
executed 566 times by 1 test: return try_tempname_len (tmpl, suffixlen, &flags, tryfunc, x_suffix_len); Executed by:
| 566 | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | int | - | ||||||||||||
205 | gen_tempname (char *tmpl, int suffixlen, int flags, int kind) | - | ||||||||||||
206 | { | - | ||||||||||||
207 | return never executed: gen_tempname_len (tmpl, suffixlen, flags, kind, 6);return gen_tempname_len (tmpl, suffixlen, flags, kind, 6); never executed: return gen_tempname_len (tmpl, suffixlen, flags, kind, 6); | 0 | ||||||||||||
208 | } | - | ||||||||||||
209 | - | |||||||||||||
210 | int | - | ||||||||||||
211 | try_tempname (char *tmpl, int suffixlen, void *args, | - | ||||||||||||
212 | int (*tryfunc) (char *, void *)) | - | ||||||||||||
213 | { | - | ||||||||||||
214 | return never executed: try_tempname_len (tmpl, suffixlen, args, tryfunc, 6);return try_tempname_len (tmpl, suffixlen, args, tryfunc, 6); never executed: return try_tempname_len (tmpl, suffixlen, args, tryfunc, 6); | 0 | ||||||||||||
215 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |