Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | extern void _hs_append_history_line (int, const char *); | - |
30 | | - |
31 | | - |
32 | int history_file_version = 1; | - |
33 | | - |
34 | | - |
35 | int history_write_timestamps = 0; | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | int history_multiline_entries = 0; | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | int history_lines_read_from_file = 0; | - |
46 | | - |
47 | | - |
48 | | - |
49 | | - |
50 | int history_lines_written_to_file = 0; | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | static char *history_backupfile (const char *); | - |
57 | static char *history_tempfile (const char *); | - |
58 | static int histfile_backup (const char *, const char *); | - |
59 | static int histfile_restore (const char *, const char *); | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | static char * | - |
65 | history_filename (const char *filename) | - |
66 | { | - |
67 | char *return_val; | - |
68 | const char *home; | - |
69 | int home_len; | - |
70 | | - |
71 | return_val = filenameTRUE | evaluated 35 times by 1 test | FALSE | evaluated 15 times by 1 test |
? strcpy (xmalloc (1 + strlen (filename)), (filename)) : (char *) | 15-35 |
72 | ((void *)0) | - |
73 | ; | - |
74 | | - |
75 | if (return_valTRUE | evaluated 35 times by 1 test | FALSE | evaluated 15 times by 1 test |
) | 15-35 |
76 | returnexecuted 35 times by 1 test: return (return_val); (return_val);executed 35 times by 1 test: return (return_val); | 35 |
77 | | - |
78 | home = sh_get_env_value ("HOME"); | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | if (home == 0TRUE | never evaluated | FALSE | evaluated 15 times by 1 test |
) | 0-15 |
85 | return never executed: return ( ((void *)0) ); (never executed: return ( ((void *)0) ); | 0 |
86 | ((void *)0) never executed: return ( ((void *)0) ); | 0 |
87 | ); never executed: return ( ((void *)0) ); | 0 |
88 | else | - |
89 | home_len = strlen (home);executed 15 times by 1 test: home_len = strlen (home); | 15 |
90 | | - |
91 | return_val = (char *)xmalloc (2 + home_len + 8); | - |
92 | strcpy (return_val, home); | - |
93 | return_val[home_len] = '/'; | - |
94 | | - |
95 | | - |
96 | | - |
97 | strcpy (return_val + home_len + 1, ".history"); | - |
98 | | - |
99 | | - |
100 | returnexecuted 15 times by 1 test: return (return_val); (return_val);executed 15 times by 1 test: return (return_val); | 15 |
101 | } | - |
102 | | - |
103 | static char * | - |
104 | history_backupfile (const char *filename) | - |
105 | { | - |
106 | const char *fn; | - |
107 | char *ret, linkbuf[ | - |
108 | 4096 | - |
109 | +1]; | - |
110 | size_t len; | - |
111 | ssize_t n; | - |
112 | struct stat fs; | - |
113 | | - |
114 | fn = filename; | - |
115 | | - |
116 | | - |
117 | | - |
118 | if ((TRUE | never evaluated | FALSE | never evaluated |
n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
119 | { | - |
120 | linkbuf[n] = '\0'; | - |
121 | fn = linkbuf; | - |
122 | } never executed: end of block | 0 |
123 | | - |
124 | | - |
125 | len = strlen (fn); | - |
126 | ret = xmalloc (len + 2); | - |
127 | strcpy (ret, fn); | - |
128 | ret[len] = '-'; | - |
129 | ret[len+1] = '\0'; | - |
130 | return never executed: return ret; ret;never executed: return ret; | 0 |
131 | } | - |
132 | | - |
133 | static char * | - |
134 | history_tempfile (const char *filename) | - |
135 | { | - |
136 | const char *fn; | - |
137 | char *ret, linkbuf[ | - |
138 | 4096 | - |
139 | +1]; | - |
140 | size_t len; | - |
141 | ssize_t n; | - |
142 | struct stat fs; | - |
143 | int pid; | - |
144 | | - |
145 | fn = filename; | - |
146 | | - |
147 | | - |
148 | | - |
149 | if ((TRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0TRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
) | 0-2 |
150 | { | - |
151 | linkbuf[n] = '\0'; | - |
152 | fn = linkbuf; | - |
153 | } never executed: end of block | 0 |
154 | | - |
155 | | - |
156 | len = strlen (fn); | - |
157 | ret = xmalloc (len + 11); | - |
158 | strcpy (ret, fn); | - |
159 | | - |
160 | pid = (int)getpid (); | - |
161 | | - |
162 | | - |
163 | ret[len] = '-'; | - |
164 | ret[len+1] = (pid / 10000 % 10) + '0'; | - |
165 | ret[len+2] = (pid / 1000 % 10) + '0'; | - |
166 | ret[len+3] = (pid / 100 % 10) + '0'; | - |
167 | ret[len+4] = (pid / 10 % 10) + '0'; | - |
168 | ret[len+5] = (pid % 10) + '0'; | - |
169 | strcpy (ret + len + 6, ".tmp"); | - |
170 | | - |
171 | returnexecuted 2 times by 1 test: return ret; ret;executed 2 times by 1 test: return ret; | 2 |
172 | } | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | int | - |
178 | read_history (const char *filename) | - |
179 | { | - |
180 | returnexecuted 4 times by 1 test: return (read_history_range (filename, 0, -1)); (read_history_range (filename, 0, -1));executed 4 times by 1 test: return (read_history_range (filename, 0, -1)); | 4 |
181 | } | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | int | - |
189 | read_history_range (const char *filename, int from, int to) | - |
190 | { | - |
191 | register char *line_start, *line_end, *p; | - |
192 | char *input, *buffer, *bufend, *last_ts; | - |
193 | int file, current_line, chars_read, has_timestamps, reset_comment_char; | - |
194 | struct stat finfo; | - |
195 | size_t file_size; | - |
196 | | - |
197 | int overflow_errno = | - |
198 | 27 | - |
199 | ; | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | history_lines_read_from_file = 0; | - |
207 | | - |
208 | buffer = last_ts = (char *) | - |
209 | ((void *)0) | - |
210 | ; | - |
211 | input = history_filename (filename); | - |
212 | file = inputTRUE | evaluated 5 times by 1 test | FALSE | never evaluated |
? open (input, | 0-5 |
213 | 00 | - |
214 | |0, 0666) : -1; | - |
215 | | - |
216 | if ((TRUE | never evaluated | FALSE | evaluated 5 times by 1 test |
file < 0)TRUE | never evaluated | FALSE | evaluated 5 times by 1 test |
|| (TRUE | never evaluated | FALSE | evaluated 5 times by 1 test |
fstat (file, &finfo) == -1)TRUE | never evaluated | FALSE | evaluated 5 times by 1 test |
) | 0-5 |
217 | goto never executed: goto error_and_exit; error_and_exit;never executed: goto error_and_exit; | 0 |
218 | | - |
219 | if ( | - |
220 | ((((TRUE | evaluated 2 times by 1 test | FALSE | evaluated 3 times by 1 test |
| 2-3 |
221 | finfo.st_modeTRUE | evaluated 2 times by 1 test | FALSE | evaluated 3 times by 1 test |
| 2-3 |
222 | )) & 0170000) == (0100000)) TRUE | evaluated 2 times by 1 test | FALSE | evaluated 3 times by 1 test |
| 2-3 |
223 | == 0TRUE | evaluated 2 times by 1 test | FALSE | evaluated 3 times by 1 test |
) | 2-3 |
224 | { | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | (*__errno_location ()) | - |
230 | = | - |
231 | 22 | - |
232 | ; | - |
233 | | - |
234 | gotoexecuted 2 times by 1 test: goto error_and_exit; error_and_exit;executed 2 times by 1 test: goto error_and_exit; | 2 |
235 | } | - |
236 | | - |
237 | file_size = (size_t)finfo.st_size; | - |
238 | | - |
239 | | - |
240 | if (file_size != finfo.st_sizeTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
|| file_size + 1 < file_sizeTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
) | 0-3 |
241 | { | - |
242 | | - |
243 | (*__errno_location ()) | - |
244 | = overflow_errno; | - |
245 | goto never executed: goto error_and_exit; error_and_exit;never executed: goto error_and_exit; | 0 |
246 | } | - |
247 | | - |
248 | if (file_size == 0TRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
) | 0-3 |
249 | { | - |
250 | free (input); | - |
251 | return never executed: return 0; 0;never executed: return 0; | 0 |
252 | } | - |
253 | buffer = (char *)malloc (file_size + 1); | - |
254 | if (buffer == 0TRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
) | 0-3 |
255 | { | - |
256 | | - |
257 | (*__errno_location ()) | - |
258 | = overflow_errno; | - |
259 | goto never executed: goto error_and_exit; error_and_exit;never executed: goto error_and_exit; | 0 |
260 | } | - |
261 | | - |
262 | chars_read = read (file, buffer, file_size); | - |
263 | | - |
264 | if (chars_read < 0TRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
) | 0-3 |
265 | { | - |
266 | error_and_exit: | - |
267 | if ( | - |
268 | (*TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
__errno_location ()) TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
| 0-2 |
269 | != 0TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
) | 0-2 |
270 | chars_read = executed 2 times by 1 test: chars_read = (*__errno_location ()) ; | 2 |
271 | (*__errno_location ())executed 2 times by 1 test: chars_read = (*__errno_location ()) ; | 2 |
272 | ;executed 2 times by 1 test: chars_read = (*__errno_location ()) ; | 2 |
273 | else | - |
274 | chars_read = never executed: chars_read = 5 ; | 0 |
275 | 5 never executed: chars_read = 5 ; | 0 |
276 | ; never executed: chars_read = 5 ; | 0 |
277 | if (file >= 0TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
) | 0-2 |
278 | close (file);executed 2 times by 1 test: close (file); | 2 |
279 | | - |
280 | if (inputTRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
) free (input);executed 2 times by 1 test: free (input); | 0-2 |
281 | | - |
282 | if (bufferTRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
) free (buffer);never executed: free (buffer); | 0-2 |
283 | | - |
284 | | - |
285 | returnexecuted 2 times by 1 test: return (chars_read); (chars_read);executed 2 times by 1 test: return (chars_read); | 2 |
286 | } | - |
287 | | - |
288 | close (file); | - |
289 | | - |
290 | | - |
291 | if (to < 0TRUE | evaluated 3 times by 1 test | FALSE | never evaluated |
) | 0-3 |
292 | to = chars_read;executed 3 times by 1 test: to = chars_read; | 3 |
293 | | - |
294 | | - |
295 | bufend = buffer + chars_read; | - |
296 | *bufend = '\0'; | - |
297 | current_line = 0; | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | reset_comment_char = 0; | - |
303 | if (history_comment_char == '\0'TRUE | evaluated 1 time by 1 test | FALSE | evaluated 2 times by 1 test |
&& buffer[0] == '#'TRUE | never evaluated | FALSE | evaluated 1 time by 1 test |
&& | 0-2 |
304 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
305 | (unsigned char)buffer[1]TRUE | never evaluated | FALSE | never evaluated |
| 0 |
306 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
307 | ) | - |
308 | { | - |
309 | history_comment_char = '#'; | - |
310 | reset_comment_char = 1; | - |
311 | } never executed: end of block | 0 |
312 | | - |
313 | has_timestamps = (*(TRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
buffer) == history_comment_charTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
&& | 0-3 |
314 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
315 | (unsigned char)(buffer)[1]TRUE | never evaluated | FALSE | never evaluated |
| 0 |
316 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
317 | ); | - |
318 | history_multiline_entries += has_timestampsTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
&& history_write_timestampsTRUE | never evaluated | FALSE | never evaluated |
; | 0-3 |
319 | | - |
320 | | - |
321 | for (line_start = line_end = buffer; line_end < bufendTRUE | evaluated 3 times by 1 test | FALSE | never evaluated |
&& current_line < fromTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
; line_end++) | 0-3 |
322 | if (*TRUE | never evaluated | FALSE | never evaluated |
line_end == '\n'TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
323 | { | - |
324 | p = line_end + 1; | - |
325 | | - |
326 | | - |
327 | if ((*(TRUE | never evaluated | FALSE | never evaluated |
p) == history_comment_charTRUE | never evaluated | FALSE | never evaluated |
&& TRUE | never evaluated | FALSE | never evaluated |
| 0 |
328 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
329 | (unsigned char)(p)[1]TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
330 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
331 | ) == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
332 | current_line++; never executed: current_line++; | 0 |
333 | line_start = p; | - |
334 | } never executed: end of block | 0 |
335 | | - |
336 | | - |
337 | for (line_end = line_start; line_end < bufendTRUE | evaluated 360 times by 1 test | FALSE | evaluated 3 times by 1 test |
; line_end++) | 3-360 |
338 | if (*TRUE | evaluated 17 times by 1 test | FALSE | evaluated 343 times by 1 test |
line_end == '\n'TRUE | evaluated 17 times by 1 test | FALSE | evaluated 343 times by 1 test |
) | 17-343 |
339 | { | - |
340 | | - |
341 | if (line_end > line_startTRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
&& line_end[-1] == '\r'TRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
) | 0-17 |
342 | line_end[-1] = '\0'; never executed: line_end[-1] = '\0'; | 0 |
343 | else | - |
344 | *executed 17 times by 1 test: *line_end = '\0'; line_end = '\0';executed 17 times by 1 test: *line_end = '\0'; | 17 |
345 | | - |
346 | if (*TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
line_startTRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
) | 0-17 |
347 | { | - |
348 | if ((*(TRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
line_start) == history_comment_charTRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
&& TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
349 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
350 | (unsigned char)(line_start)[1]TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
351 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
352 | ) == 0TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
) | 0-17 |
353 | { | - |
354 | if (last_ts == TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
355 | ((void *)0)TRUE | evaluated 17 times by 1 test | FALSE | never evaluated |
| 0-17 |
356 | && history_multiline_entriesTRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
) | 0-17 |
357 | _hs_append_history_line (history_length - 1, line_start); never executed: _hs_append_history_line (history_length - 1, line_start); | 0 |
358 | else | - |
359 | add_history (line_start);executed 17 times by 1 test: add_history (line_start); | 17 |
360 | if (last_tsTRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
) | 0-17 |
361 | { | - |
362 | add_history_time (last_ts); | - |
363 | last_ts = | - |
364 | ((void *)0) | - |
365 | ; | - |
366 | } never executed: end of block | 0 |
367 | }executed 17 times by 1 test: end of block | 17 |
368 | else | - |
369 | { | - |
370 | last_ts = line_start; | - |
371 | current_line--; | - |
372 | } never executed: end of block | 0 |
373 | } | - |
374 | | - |
375 | current_line++; | - |
376 | | - |
377 | if (current_line >= toTRUE | never evaluated | FALSE | evaluated 17 times by 1 test |
) | 0-17 |
378 | break; never executed: break; | 0 |
379 | | - |
380 | line_start = line_end + 1; | - |
381 | }executed 17 times by 1 test: end of block | 17 |
382 | | - |
383 | history_lines_read_from_file = current_line; | - |
384 | if (reset_comment_charTRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
) | 0-3 |
385 | history_comment_char = '\0'; never executed: history_comment_char = '\0'; | 0 |
386 | | - |
387 | if (inputTRUE | evaluated 3 times by 1 test | FALSE | never evaluated |
) free (input);executed 3 times by 1 test: free (input); | 0-3 |
388 | | - |
389 | if (bufferTRUE | evaluated 3 times by 1 test | FALSE | never evaluated |
) free (buffer);executed 3 times by 1 test: free (buffer); | 0-3 |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | returnexecuted 3 times by 1 test: return (0); (0);executed 3 times by 1 test: return (0); | 3 |
395 | } | - |
396 | | - |
397 | | - |
398 | | - |
399 | static int | - |
400 | histfile_backup (const char *filename, const char *back) | - |
401 | { | - |
402 | | - |
403 | char linkbuf[ | - |
404 | 4096 | - |
405 | +1]; | - |
406 | ssize_t n; | - |
407 | | - |
408 | | - |
409 | if ((TRUE | never evaluated | FALSE | never evaluated |
n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
410 | { | - |
411 | linkbuf[n] = '\0'; | - |
412 | return never executed: return (rename (linkbuf, back)); (rename (linkbuf, back));never executed: return (rename (linkbuf, back)); | 0 |
413 | } | - |
414 | | - |
415 | return never executed: return (rename (filename, back)); (rename (filename, back));never executed: return (rename (filename, back)); | 0 |
416 | } | - |
417 | | - |
418 | | - |
419 | | - |
420 | static int | - |
421 | histfile_restore (const char *backup, const char *orig) | - |
422 | { | - |
423 | | - |
424 | char linkbuf[ | - |
425 | 4096 | - |
426 | +1]; | - |
427 | ssize_t n; | - |
428 | | - |
429 | | - |
430 | if ((TRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
n = readlink (orig, linkbuf, sizeof (linkbuf) - 1)) > 0TRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
) | 0-2 |
431 | { | - |
432 | linkbuf[n] = '\0'; | - |
433 | return never executed: return (rename (backup, linkbuf)); (rename (backup, linkbuf));never executed: return (rename (backup, linkbuf)); | 0 |
434 | } | - |
435 | | - |
436 | returnexecuted 2 times by 1 test: return (rename (backup, orig)); (rename (backup, orig));executed 2 times by 1 test: return (rename (backup, orig)); | 2 |
437 | } | - |
438 | | - |
439 | | - |
440 | | - |
441 | | - |
442 | int | - |
443 | history_truncate_file (const char *fname, int lines) | - |
444 | { | - |
445 | char *buffer, *filename, *tempname, *bp, *bp1; | - |
446 | int file, chars_read, rv, orig_lines, exists, r; | - |
447 | struct stat finfo; | - |
448 | size_t file_size; | - |
449 | | - |
450 | history_lines_written_to_file = 0; | - |
451 | | - |
452 | buffer = (char *) | - |
453 | ((void *)0) | - |
454 | ; | - |
455 | filename = history_filename (fname); | - |
456 | tempname = 0; | - |
457 | file = filenameTRUE | evaluated 38 times by 1 test | FALSE | never evaluated |
? open (filename, | 0-38 |
458 | 00 | - |
459 | |0, 0666) : -1; | - |
460 | rv = exists = 0; | - |
461 | | - |
462 | | - |
463 | if (file == -1TRUE | evaluated 30 times by 1 test | FALSE | evaluated 8 times by 1 test |
|| fstat (file, &finfo) == -1TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
) | 0-30 |
464 | { | - |
465 | rv = | - |
466 | (*__errno_location ()) | - |
467 | ; | - |
468 | if (file != -1TRUE | never evaluated | FALSE | evaluated 30 times by 1 test |
) | 0-30 |
469 | close (file); never executed: close (file); | 0 |
470 | gotoexecuted 30 times by 1 test: goto truncate_exit; truncate_exit;executed 30 times by 1 test: goto truncate_exit; | 30 |
471 | } | - |
472 | exists = 1; | - |
473 | | - |
474 | if ( | - |
475 | ((((TRUE | evaluated 1 time by 1 test | FALSE | evaluated 7 times by 1 test |
| 1-7 |
476 | finfo.st_modeTRUE | evaluated 1 time by 1 test | FALSE | evaluated 7 times by 1 test |
| 1-7 |
477 | )) & 0170000) == (0100000)) TRUE | evaluated 1 time by 1 test | FALSE | evaluated 7 times by 1 test |
| 1-7 |
478 | == 0TRUE | evaluated 1 time by 1 test | FALSE | evaluated 7 times by 1 test |
) | 1-7 |
479 | { | - |
480 | close (file); | - |
481 | | - |
482 | | - |
483 | | - |
484 | rv = | - |
485 | 22 | - |
486 | ; | - |
487 | | - |
488 | gotoexecuted 1 time by 1 test: goto truncate_exit; truncate_exit;executed 1 time by 1 test: goto truncate_exit; | 1 |
489 | } | - |
490 | | - |
491 | file_size = (size_t)finfo.st_size; | - |
492 | | - |
493 | | - |
494 | if (file_size != finfo.st_sizeTRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
|| file_size + 1 < file_sizeTRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
495 | { | - |
496 | close (file); | - |
497 | | - |
498 | rv = | - |
499 | (*__errno_location ()) | - |
500 | = | - |
501 | 27 | - |
502 | ; | - |
503 | | - |
504 | | - |
505 | | - |
506 | | - |
507 | | - |
508 | goto never executed: goto truncate_exit; truncate_exit;never executed: goto truncate_exit; | 0 |
509 | } | - |
510 | | - |
511 | buffer = (char *)malloc (file_size + 1); | - |
512 | if (buffer == 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
513 | { | - |
514 | rv = | - |
515 | (*__errno_location ()) | - |
516 | ; | - |
517 | close (file); | - |
518 | goto never executed: goto truncate_exit; truncate_exit;never executed: goto truncate_exit; | 0 |
519 | } | - |
520 | | - |
521 | chars_read = read (file, buffer, file_size); | - |
522 | close (file); | - |
523 | | - |
524 | if (chars_read <= 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
525 | { | - |
526 | rv = (TRUE | never evaluated | FALSE | never evaluated |
chars_read < 0)TRUE | never evaluated | FALSE | never evaluated |
? | 0 |
527 | (*__errno_location ()) | - |
528 | : 0; | - |
529 | goto never executed: goto truncate_exit; truncate_exit;never executed: goto truncate_exit; | 0 |
530 | } | - |
531 | | - |
532 | orig_lines = lines; | - |
533 | | - |
534 | | - |
535 | | - |
536 | | - |
537 | for (bp1 = bp = buffer + chars_read - 1; linesTRUE | evaluated 966 times by 1 test | FALSE | never evaluated |
&& bp > bufferTRUE | evaluated 959 times by 1 test | FALSE | evaluated 7 times by 1 test |
; bp--) | 0-966 |
538 | { | - |
539 | if (*TRUE | evaluated 57 times by 1 test | FALSE | evaluated 902 times by 1 test |
bp == '\n'TRUE | evaluated 57 times by 1 test | FALSE | evaluated 902 times by 1 test |
&& (*(TRUE | never evaluated | FALSE | evaluated 57 times by 1 test |
bp1) == history_comment_charTRUE | never evaluated | FALSE | evaluated 57 times by 1 test |
&& TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
| 0-902 |
540 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
| 0-57 |
541 | (unsigned char)(bp1)[1]TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
| 0-57 |
542 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
| 0-57 |
543 | ) == 0TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
) | 0-57 |
544 | lines--;executed 57 times by 1 test: lines--; | 57 |
545 | bp1 = bp; | - |
546 | }executed 959 times by 1 test: end of block | 959 |
547 | | - |
548 | | - |
549 | | - |
550 | | - |
551 | | - |
552 | | - |
553 | for ( ; bp > bufferTRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
; bp--) | 0-7 |
554 | { | - |
555 | if (*TRUE | never evaluated | FALSE | never evaluated |
bp == '\n'TRUE | never evaluated | FALSE | never evaluated |
&& (*(TRUE | never evaluated | FALSE | never evaluated |
bp1) == history_comment_charTRUE | never evaluated | FALSE | never evaluated |
&& TRUE | never evaluated | FALSE | never evaluated |
| 0 |
556 | ((*TRUE | never evaluated | FALSE | never evaluated |
__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
557 | (unsigned char)(bp1)[1]TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
558 | ))] & (unsigned short int) _ISdigit)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
559 | ) == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
560 | { | - |
561 | bp++; | - |
562 | break; never executed: break; | 0 |
563 | } | - |
564 | bp1 = bp; | - |
565 | } never executed: end of block | 0 |
566 | | - |
567 | | - |
568 | | - |
569 | if (bp <= bufferTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
) | 0-7 |
570 | { | - |
571 | rv = 0; | - |
572 | | - |
573 | history_lines_written_to_file = orig_lines - lines; | - |
574 | gotoexecuted 7 times by 1 test: goto truncate_exit; truncate_exit;executed 7 times by 1 test: goto truncate_exit; | 7 |
575 | } | - |
576 | | - |
577 | tempname = history_tempfile (filename); | - |
578 | | - |
579 | if ((TRUE | never evaluated | FALSE | never evaluated |
file = open (tempname, TRUE | never evaluated | FALSE | never evaluated |
| 0 |
580 | 01TRUE | never evaluated | FALSE | never evaluated |
| 0 |
581 | |TRUE | never evaluated | FALSE | never evaluated |
| 0 |
582 | 0100TRUE | never evaluated | FALSE | never evaluated |
| 0 |
583 | |TRUE | never evaluated | FALSE | never evaluated |
| 0 |
584 | 01000TRUE | never evaluated | FALSE | never evaluated |
| 0 |
585 | |0, 0600)) != -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
586 | { | - |
587 | if (write (file, bp, chars_read - (bp - buffer)) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
588 | rv = never executed: rv = (*__errno_location ()) ; | 0 |
589 | (*__errno_location ()) never executed: rv = (*__errno_location ()) ; | 0 |
590 | ; never executed: rv = (*__errno_location ()) ; | 0 |
591 | | - |
592 | if (close (file) < 0TRUE | never evaluated | FALSE | never evaluated |
&& rv == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
593 | rv = never executed: rv = (*__errno_location ()) ; | 0 |
594 | (*__errno_location ()) never executed: rv = (*__errno_location ()) ; | 0 |
595 | ; never executed: rv = (*__errno_location ()) ; | 0 |
596 | } never executed: end of block | 0 |
597 | else | - |
598 | rv = never executed: rv = (*__errno_location ()) ; | 0 |
599 | (*__errno_location ()) never executed: rv = (*__errno_location ()) ; | 0 |
600 | ; never executed: rv = (*__errno_location ()) ; | 0 |
601 | | - |
602 | truncate_exit: code before this statement never executed: truncate_exit: | 0 |
603 | if (bufferTRUE | evaluated 7 times by 1 test | FALSE | evaluated 31 times by 1 test |
) free (buffer);executed 7 times by 1 test: free (buffer); | 7-31 |
604 | | - |
605 | history_lines_written_to_file = orig_lines - lines; | - |
606 | | - |
607 | if (rv == 0TRUE | evaluated 7 times by 1 test | FALSE | evaluated 31 times by 1 test |
&& filenameTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
&& tempnameTRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-31 |
608 | rv = histfile_restore (tempname, filename); never executed: rv = histfile_restore (tempname, filename); | 0 |
609 | | - |
610 | if (rv != 0TRUE | evaluated 31 times by 1 test | FALSE | evaluated 7 times by 1 test |
) | 7-31 |
611 | { | - |
612 | if (tempnameTRUE | never evaluated | FALSE | evaluated 31 times by 1 test |
) | 0-31 |
613 | unlink (tempname); never executed: unlink (tempname); | 0 |
614 | history_lines_written_to_file = 0; | - |
615 | }executed 31 times by 1 test: end of block | 31 |
616 | | - |
617 | | - |
618 | | - |
619 | | - |
620 | | - |
621 | | - |
622 | if (rv == 0TRUE | evaluated 7 times by 1 test | FALSE | evaluated 31 times by 1 test |
&& existsTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
) | 0-31 |
623 | r = chown (filename, finfo.st_uid, finfo.st_gid);executed 7 times by 1 test: r = chown (filename, finfo.st_uid, finfo.st_gid); | 7 |
624 | | - |
625 | | - |
626 | xfree (filename); | - |
627 | if (tempnameTRUE | never evaluated | FALSE | evaluated 38 times by 1 test |
) free (tempname);never executed: free (tempname); | 0-38 |
628 | | - |
629 | returnexecuted 38 times by 1 test: return rv; rv;executed 38 times by 1 test: return rv; | 38 |
630 | } | - |
631 | | - |
632 | | - |
633 | | - |
634 | | - |
635 | static int | - |
636 | history_do_write (const char *filename, int nelements, int overwrite) | - |
637 | { | - |
638 | register int i; | - |
639 | char *output, *tempname, *histname; | - |
640 | int file, mode, rv, exists; | - |
641 | struct stat finfo; | - |
642 | | - |
643 | | - |
644 | | - |
645 | | - |
646 | | - |
647 | | - |
648 | | - |
649 | mode = overwriteTRUE | evaluated 2 times by 1 test | FALSE | evaluated 5 times by 1 test |
? | 2-5 |
650 | 01 | - |
651 | | | - |
652 | 0100 | - |
653 | | | - |
654 | 01000 | - |
655 | |0 : | - |
656 | 01 | - |
657 | | | - |
658 | 02000 | - |
659 | |0; | - |
660 | | - |
661 | histname = history_filename (filename); | - |
662 | exists = histnameTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
? (stat (histname, &finfo) == 0) : 0; | 0-7 |
663 | | - |
664 | tempname = (overwriteTRUE | evaluated 2 times by 1 test | FALSE | evaluated 5 times by 1 test |
&& existsTRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
&& | 0-5 |
665 | ((((TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
| 0-2 |
666 | finfo.st_modeTRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
| 0-2 |
667 | )) & 0170000) == (0100000))TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
| 0-2 |
668 | ) ? history_tempfile (histname) : 0; | - |
669 | output = tempnameTRUE | evaluated 2 times by 1 test | FALSE | evaluated 5 times by 1 test |
? tempname : histname; | 2-5 |
670 | | - |
671 | file = outputTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
? open (output, mode, 0600) : -1; | 0-7 |
672 | rv = 0; | - |
673 | | - |
674 | if (file == -1TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
675 | { | - |
676 | rv = | - |
677 | (*__errno_location ()) | - |
678 | ; | - |
679 | if (histnameTRUE | never evaluated | FALSE | never evaluated |
) free (histname);never executed: free (histname); | 0 |
680 | if (tempnameTRUE | never evaluated | FALSE | never evaluated |
) free (tempname);never executed: free (tempname); | 0 |
681 | return never executed: return (rv); (rv);never executed: return (rv); | 0 |
682 | } | - |
683 | | - |
684 | | - |
685 | | - |
686 | | - |
687 | | - |
688 | if (nelements > history_lengthTRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
689 | nelements = history_length; never executed: nelements = history_length; | 0 |
690 | | - |
691 | | - |
692 | | - |
693 | { | - |
694 | HIST_ENTRY **the_history; | - |
695 | register int j; | - |
696 | int buffer_size; | - |
697 | char *buffer; | - |
698 | | - |
699 | the_history = history_list (); | - |
700 | | - |
701 | for (buffer_size = 0, i = history_length - nelements; i < history_lengthTRUE | evaluated 27 times by 1 test | FALSE | evaluated 7 times by 1 test |
; i++) | 7-27 |
702 | | - |
703 | | - |
704 | | - |
705 | { | - |
706 | if (history_write_timestampsTRUE | never evaluated | FALSE | evaluated 27 times by 1 test |
&& the_history[i]->timestampTRUE | never evaluated | FALSE | never evaluated |
&& the_history[i]->timestamp[0]TRUE | never evaluated | FALSE | never evaluated |
) | 0-27 |
707 | buffer_size += strlen (the_history[i]->timestamp) + 1; never executed: buffer_size += strlen (the_history[i]->timestamp) + 1; | 0 |
708 | buffer_size += strlen (the_history[i]->line) + 1; | - |
709 | }executed 27 times by 1 test: end of block | 27 |
710 | buffer = (char *)malloc (buffer_size); | - |
711 | if (buffer == 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
712 | { | - |
713 | rv = | - |
714 | (*__errno_location ()) | - |
715 | ; | - |
716 | close (file); | - |
717 | if (tempnameTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
718 | unlink (tempname); never executed: unlink (tempname); | 0 |
719 | if (histnameTRUE | never evaluated | FALSE | never evaluated |
) free (histname);never executed: free (histname); | 0 |
720 | if (tempnameTRUE | never evaluated | FALSE | never evaluated |
) free (tempname);never executed: free (tempname); | 0 |
721 | return never executed: return rv; rv;never executed: return rv; | 0 |
722 | } | - |
723 | | - |
724 | | - |
725 | for (j = 0, i = history_length - nelements; i < history_lengthTRUE | evaluated 27 times by 1 test | FALSE | evaluated 7 times by 1 test |
; i++) | 7-27 |
726 | { | - |
727 | if (history_write_timestampsTRUE | never evaluated | FALSE | evaluated 27 times by 1 test |
&& the_history[i]->timestampTRUE | never evaluated | FALSE | never evaluated |
&& the_history[i]->timestamp[0]TRUE | never evaluated | FALSE | never evaluated |
) | 0-27 |
728 | { | - |
729 | strcpy (buffer + j, the_history[i]->timestamp); | - |
730 | j += strlen (the_history[i]->timestamp); | - |
731 | buffer[j++] = '\n'; | - |
732 | } never executed: end of block | 0 |
733 | strcpy (buffer + j, the_history[i]->line); | - |
734 | j += strlen (the_history[i]->line); | - |
735 | buffer[j++] = '\n'; | - |
736 | }executed 27 times by 1 test: end of block | 27 |
737 | | - |
738 | | - |
739 | | - |
740 | | - |
741 | | - |
742 | if (write (file, buffer, buffer_size) < 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
743 | rv = never executed: rv = (*__errno_location ()) ; | 0 |
744 | (*__errno_location ()) never executed: rv = (*__errno_location ()) ; | 0 |
745 | ; never executed: rv = (*__errno_location ()) ; | 0 |
746 | xfree (buffer); | - |
747 | | - |
748 | } | - |
749 | | - |
750 | history_lines_written_to_file = nelements; | - |
751 | | - |
752 | if (close (file) < 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
&& rv == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0-7 |
753 | rv = never executed: rv = (*__errno_location ()) ; | 0 |
754 | (*__errno_location ()) never executed: rv = (*__errno_location ()) ; | 0 |
755 | ; never executed: rv = (*__errno_location ()) ; | 0 |
756 | | - |
757 | if (rv == 0TRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
&& histnameTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
&& tempnameTRUE | evaluated 2 times by 1 test | FALSE | evaluated 5 times by 1 test |
) | 0-7 |
758 | rv = histfile_restore (tempname, histname);executed 2 times by 1 test: rv = histfile_restore (tempname, histname); | 2 |
759 | | - |
760 | if (rv != 0TRUE | never evaluated | FALSE | evaluated 7 times by 1 test |
) | 0-7 |
761 | { | - |
762 | if (tempnameTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
763 | unlink (tempname); never executed: unlink (tempname); | 0 |
764 | history_lines_written_to_file = 0; | - |
765 | } never executed: end of block | 0 |
766 | | - |
767 | | - |
768 | | - |
769 | | - |
770 | | - |
771 | | - |
772 | if (rv == 0TRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
&& existsTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
) | 0-7 |
773 | mode = chown (histname, finfo.st_uid, finfo.st_gid);executed 7 times by 1 test: mode = chown (histname, finfo.st_uid, finfo.st_gid); | 7 |
774 | | - |
775 | | - |
776 | if (histnameTRUE | evaluated 7 times by 1 test | FALSE | never evaluated |
) free (histname);executed 7 times by 1 test: free (histname); | 0-7 |
777 | if (tempnameTRUE | evaluated 2 times by 1 test | FALSE | evaluated 5 times by 1 test |
) free (tempname);executed 2 times by 1 test: free (tempname); | 2-5 |
778 | | - |
779 | returnexecuted 7 times by 1 test: return (rv); (rv);executed 7 times by 1 test: return (rv); | 7 |
780 | } | - |
781 | | - |
782 | | - |
783 | | - |
784 | int | - |
785 | append_history (int nelements, const char *filename) | - |
786 | { | - |
787 | returnexecuted 5 times by 1 test: return (history_do_write (filename, nelements, 0)); (history_do_write (filename, nelements, 0));executed 5 times by 1 test: return (history_do_write (filename, nelements, 0)); | 5 |
788 | } | - |
789 | | - |
790 | | - |
791 | | - |
792 | | - |
793 | int | - |
794 | write_history (const char *filename) | - |
795 | { | - |
796 | returnexecuted 2 times by 1 test: return (history_do_write (filename, history_length, 1)); (history_do_write (filename, history_length, 1));executed 2 times by 1 test: return (history_do_write (filename, history_length, 1)); | 2 |
797 | } | - |
| | |