| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/force-link.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | static char const simple_pattern[] = "CuXXXXXX"; | - | ||||||||||||
| 10 | enum { x_suffix_len = sizeof "XXXXXX" - 1 }; | - | ||||||||||||
| 11 | - | |||||||||||||
| 12 | - | |||||||||||||
| 13 | - | |||||||||||||
| 14 | - | |||||||||||||
| 15 | enum { smallsize = 256 }; | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | - | |||||||||||||
| 18 | - | |||||||||||||
| 19 | - | |||||||||||||
| 20 | - | |||||||||||||
| 21 | static char * | - | ||||||||||||
| 22 | samedir_template (char const *dstname, char buf[smallsize]) | - | ||||||||||||
| 23 | { | - | ||||||||||||
| 24 | ptrdiff_t dstdirlen = last_component (dstname) - dstname; | - | ||||||||||||
| 25 | size_t dsttmpsize = dstdirlen + sizeof simple_pattern; | - | ||||||||||||
| 26 | char *dsttmp; | - | ||||||||||||
| 27 | if (dsttmpsize <= smallsize
| 0-30 | ||||||||||||
| 28 | dsttmp = buf; executed 30 times by 3 tests: dsttmp = buf;Executed by:
| 30 | ||||||||||||
| 29 | else | - | ||||||||||||
| 30 | { | - | ||||||||||||
| 31 | dsttmp = malloc (dsttmpsize); | - | ||||||||||||
| 32 | if (!dsttmp
| 0 | ||||||||||||
| 33 | return never executed: dsttmp;return dsttmp;never executed: return dsttmp; | 0 | ||||||||||||
| 34 | } never executed: end of block | 0 | ||||||||||||
| 35 | strcpy (mempcpy (dsttmp, dstname, dstdirlen), simple_pattern); | - | ||||||||||||
| 36 | return executed 30 times by 3 tests: dsttmp;return dsttmp;Executed by:
executed 30 times by 3 tests: return dsttmp;Executed by:
| 30 | ||||||||||||
| 37 | } | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | - | |||||||||||||
| 40 | - | |||||||||||||
| 41 | - | |||||||||||||
| 42 | struct link_arg | - | ||||||||||||
| 43 | { | - | ||||||||||||
| 44 | int srcdir; | - | ||||||||||||
| 45 | char const *srcname; | - | ||||||||||||
| 46 | int dstdir; | - | ||||||||||||
| 47 | int flags; | - | ||||||||||||
| 48 | }; | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | static int | - | ||||||||||||
| 51 | try_link (char *dest, void *arg) | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | struct link_arg *a = arg; | - | ||||||||||||
| 54 | return executed 19 times by 3 tests: linkat (a->srcdir, a->srcname, a->dstdir, dest, a->flags);return linkat (a->srcdir, a->srcname, a->dstdir, dest, a->flags);Executed by:
executed 19 times by 3 tests: return linkat (a->srcdir, a->srcname, a->dstdir, dest, a->flags);Executed by:
| 19 | ||||||||||||
| 55 | } | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | - | |||||||||||||
| 59 | - | |||||||||||||
| 60 | - | |||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | extern int | - | ||||||||||||
| 64 | force_linkat (int srcdir, char const *srcname, | - | ||||||||||||
| 65 | int dstdir, char const *dstname, int flags, | - | ||||||||||||
| 66 | _Bool | - | ||||||||||||
| 67 | force) | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | int r = linkat (srcdir, srcname, dstdir, dstname, flags); | - | ||||||||||||
| 70 | if (!force
| 18-30103 | ||||||||||||
| 71 | (*
| 0-19 | ||||||||||||
| 72 | !=
| 0-19 | ||||||||||||
| 73 | 17
| 0-19 | ||||||||||||
| 74 | ) | - | ||||||||||||
| 75 | return executed 30121 times by 3 tests: r;return r;Executed by:
executed 30121 times by 3 tests: return r;Executed by:
| 30121 | ||||||||||||
| 76 | - | |||||||||||||
| 77 | char buf[smallsize]; | - | ||||||||||||
| 78 | char *dsttmp = samedir_template (dstname, buf); | - | ||||||||||||
| 79 | if (! dsttmp
| 0-19 | ||||||||||||
| 80 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 81 | struct link_arg arg = { srcdir, srcname, dstdir, flags }; | - | ||||||||||||
| 82 | int err; | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | if (try_tempname_len (dsttmp, 0, &arg, try_link, x_suffix_len) != 0
| 1-18 | ||||||||||||
| 85 | err = executed 1 time by 1 test: err = (*__errno_location ()) ;Executed by:
| 1 | ||||||||||||
| 86 | (*__errno_location ()) executed 1 time by 1 test: err = (*__errno_location ()) ;Executed by:
| 1 | ||||||||||||
| 87 | ; executed 1 time by 1 test: err = (*__errno_location ()) ;Executed by:
| 1 | ||||||||||||
| 88 | else | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | err = renameat (dstdir, dsttmp, dstdir, dstname) == 0
| 0-18 | ||||||||||||
| 91 | (*__errno_location ()) | - | ||||||||||||
| 92 | ; | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | - | |||||||||||||
| 95 | - | |||||||||||||
| 96 | unlinkat (dstdir, dsttmp, 0); | - | ||||||||||||
| 97 | } executed 18 times by 3 tests: end of blockExecuted by:
| 18 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | if (dsttmp != buf
| 0-19 | ||||||||||||
| 100 | free (dsttmp); never executed: free (dsttmp); | 0 | ||||||||||||
| 101 | if (!err
| 1-18 | ||||||||||||
| 102 | return executed 18 times by 3 tests: 1;return 1;Executed by:
executed 18 times by 3 tests: return 1;Executed by:
| 18 | ||||||||||||
| 103 | - | |||||||||||||
| 104 | (*__errno_location ()) | - | ||||||||||||
| 105 | = err; | - | ||||||||||||
| 106 | return executed 1 time by 1 test: -1;return -1;Executed by:
executed 1 time by 1 test: return -1;Executed by:
| 1 | ||||||||||||
| 107 | } | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | - | |||||||||||||
| 111 | - | |||||||||||||
| 112 | struct symlink_arg | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | char const *srcname; | - | ||||||||||||
| 115 | int dstdir; | - | ||||||||||||
| 116 | }; | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | static int | - | ||||||||||||
| 119 | try_symlink (char *dest, void *arg) | - | ||||||||||||
| 120 | { | - | ||||||||||||
| 121 | struct symlink_arg *a = arg; | - | ||||||||||||
| 122 | return executed 11 times by 2 tests: symlinkat (a->srcname, a->dstdir, dest);return symlinkat (a->srcname, a->dstdir, dest);Executed by:
executed 11 times by 2 tests: return symlinkat (a->srcname, a->dstdir, dest);Executed by:
| 11 | ||||||||||||
| 123 | } | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | - | |||||||||||||
| 126 | - | |||||||||||||
| 127 | - | |||||||||||||
| 128 | - | |||||||||||||
| 129 | - | |||||||||||||
| 130 | extern int | - | ||||||||||||
| 131 | force_symlinkat (char const *srcname, int dstdir, char const *dstname, | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | _Bool | - | ||||||||||||
| 134 | force) | - | ||||||||||||
| 135 | { | - | ||||||||||||
| 136 | int r = symlinkat (srcname, dstdir, dstname); | - | ||||||||||||
| 137 | if (!force
| 11-651 | ||||||||||||
| 138 | (*
| 0-11 | ||||||||||||
| 139 | !=
| 0-11 | ||||||||||||
| 140 | 17
| 0-11 | ||||||||||||
| 141 | ) | - | ||||||||||||
| 142 | return executed 697 times by 3 tests: r;return r;Executed by:
executed 697 times by 3 tests: return r;Executed by:
| 697 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | char buf[smallsize]; | - | ||||||||||||
| 145 | char *dsttmp = samedir_template (dstname, buf); | - | ||||||||||||
| 146 | if (!dsttmp
| 0-11 | ||||||||||||
| 147 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 148 | struct symlink_arg arg = { srcname, dstdir }; | - | ||||||||||||
| 149 | int err; | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | if (try_tempname_len (dsttmp, 0, &arg, try_symlink, x_suffix_len) != 0
| 0-11 | ||||||||||||
| 152 | err = never executed: err = (*__errno_location ()) ; | 0 | ||||||||||||
| 153 | (*__errno_location ()) never executed: err = (*__errno_location ()) ; | 0 | ||||||||||||
| 154 | ; never executed: err = (*__errno_location ()) ; | 0 | ||||||||||||
| 155 | else if (renameat (dstdir, dsttmp, dstdir, dstname) != 0
| 0-11 | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | err = | - | ||||||||||||
| 158 | (*__errno_location ()) | - | ||||||||||||
| 159 | ; | - | ||||||||||||
| 160 | unlinkat (dstdir, dsttmp, 0); | - | ||||||||||||
| 161 | } never executed: end of block | 0 | ||||||||||||
| 162 | else | - | ||||||||||||
| 163 | { | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | - | |||||||||||||
| 166 | err = 0; | - | ||||||||||||
| 167 | } executed 11 times by 2 tests: end of blockExecuted by:
| 11 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | if (dsttmp != buf
| 0-11 | ||||||||||||
| 170 | free (dsttmp); never executed: free (dsttmp); | 0 | ||||||||||||
| 171 | if (!err
| 0-11 | ||||||||||||
| 172 | return executed 11 times by 2 tests: 1;return 1;Executed by:
executed 11 times by 2 tests: return 1;Executed by:
| 11 | ||||||||||||
| 173 | - | |||||||||||||
| 174 | (*__errno_location ()) | - | ||||||||||||
| 175 | = err; | - | ||||||||||||
| 176 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 177 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |