Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/backup-find.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* backupfile.c -- make Emacs style backup file names | - | ||||||||||||
2 | - | |||||||||||||
3 | Copyright 2017-2018 Free Software Foundation, Inc. | - | ||||||||||||
4 | - | |||||||||||||
5 | This program is free software: you can redistribute it and/or modify | - | ||||||||||||
6 | it under the terms of the GNU General Public License as published by | - | ||||||||||||
7 | the Free Software Foundation; either version 3 of the License, or | - | ||||||||||||
8 | (at your option) any later version. | - | ||||||||||||
9 | - | |||||||||||||
10 | This program 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 | - | ||||||||||||
13 | GNU General Public License for more details. | - | ||||||||||||
14 | - | |||||||||||||
15 | You should have received a copy of the GNU General Public License | - | ||||||||||||
16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||||||||
17 | - | |||||||||||||
18 | #include <config.h> | - | ||||||||||||
19 | - | |||||||||||||
20 | #include "backup-internal.h" | - | ||||||||||||
21 | - | |||||||||||||
22 | #include "argmatch.h" | - | ||||||||||||
23 | #include "xalloc.h" | - | ||||||||||||
24 | - | |||||||||||||
25 | #include <stdlib.h> | - | ||||||||||||
26 | - | |||||||||||||
27 | /* Return the name of a backup file for the existing file FILE, | - | ||||||||||||
28 | allocated with malloc. Report an error and exit if out of memory. | - | ||||||||||||
29 | Do not call this function if backup_type == no_backups. */ | - | ||||||||||||
30 | - | |||||||||||||
31 | char * | - | ||||||||||||
32 | find_backup_file_name (char const *file, enum backup_type backup_type) | - | ||||||||||||
33 | { | - | ||||||||||||
34 | char *result = backupfile_internal (file, backup_type, false); | - | ||||||||||||
35 | if (!result)
| 0-9 | ||||||||||||
36 | xalloc_die (); never executed: xalloc_die (); | 0 | ||||||||||||
37 | return result; executed 9 times by 2 tests: return result; Executed by:
| 9 | ||||||||||||
38 | } | - | ||||||||||||
39 | - | |||||||||||||
40 | static char const *const backup_args[] = | - | ||||||||||||
41 | { | - | ||||||||||||
42 | /* In a series of synonyms, present the most meaningful first, so | - | ||||||||||||
43 | that argmatch_valid be more readable. */ | - | ||||||||||||
44 | "none", "off", | - | ||||||||||||
45 | "simple", "never", | - | ||||||||||||
46 | "existing", "nil", | - | ||||||||||||
47 | "numbered", "t", | - | ||||||||||||
48 | NULL | - | ||||||||||||
49 | }; | - | ||||||||||||
50 | - | |||||||||||||
51 | static const enum backup_type backup_types[] = | - | ||||||||||||
52 | { | - | ||||||||||||
53 | no_backups, no_backups, | - | ||||||||||||
54 | simple_backups, simple_backups, | - | ||||||||||||
55 | numbered_existing_backups, numbered_existing_backups, | - | ||||||||||||
56 | numbered_backups, numbered_backups | - | ||||||||||||
57 | }; | - | ||||||||||||
58 | - | |||||||||||||
59 | /* Ensure that these two vectors have the same number of elements, | - | ||||||||||||
60 | not counting the final NULL in the first one. */ | - | ||||||||||||
61 | ARGMATCH_VERIFY (backup_args, backup_types); | - | ||||||||||||
62 | - | |||||||||||||
63 | /* Return the type of backup specified by VERSION. | - | ||||||||||||
64 | If VERSION is NULL or the empty string, return numbered_existing_backups. | - | ||||||||||||
65 | If VERSION is invalid or ambiguous, fail with a diagnostic appropriate | - | ||||||||||||
66 | for the specified CONTEXT. Unambiguous abbreviations are accepted. */ | - | ||||||||||||
67 | - | |||||||||||||
68 | enum backup_type | - | ||||||||||||
69 | get_version (char const *context, char const *version) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | if (version == 0 || *version == 0)
| 0-138 | ||||||||||||
72 | return numbered_existing_backups; executed 21 times by 3 tests: return numbered_existing_backups; Executed by:
| 21 | ||||||||||||
73 | else | - | ||||||||||||
74 | return XARGMATCH (context, version, backup_args, backup_types); executed 138 times by 4 tests: return ((backup_types) [__xargmatch_internal (context, version, backup_args, (char const *) (backup_types), sizeof *(backup_types), argmatch_die)]); Executed by:
| 138 | ||||||||||||
75 | } | - | ||||||||||||
76 | - | |||||||||||||
77 | - | |||||||||||||
78 | /* Return the type of backup specified by VERSION. | - | ||||||||||||
79 | If VERSION is NULL, use the value of the envvar VERSION_CONTROL. | - | ||||||||||||
80 | If the specified string is invalid or ambiguous, fail with a diagnostic | - | ||||||||||||
81 | appropriate for the specified CONTEXT. | - | ||||||||||||
82 | Unambiguous abbreviations are accepted. */ | - | ||||||||||||
83 | - | |||||||||||||
84 | enum backup_type | - | ||||||||||||
85 | xget_version (char const *context, char const *version) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | if (version && *version)
| 0-94 | ||||||||||||
88 | return get_version (context, version); executed 94 times by 4 tests: return get_version (context, version); Executed by:
| 94 | ||||||||||||
89 | else | - | ||||||||||||
90 | return get_version ("$VERSION_CONTROL", getenv ("VERSION_CONTROL")); executed 65 times by 3 tests: return get_version ("$VERSION_CONTROL", getenv ("VERSION_CONTROL")); Executed by:
| 65 | ||||||||||||
91 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |