OpenCoverage

canonicalize.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/canonicalize.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Return the canonical absolute name of a given file.-
2 Copyright (C) 1996-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#include <config.h>-
18-
19#include "canonicalize.h"-
20-
21#include <errno.h>-
22#include <stdlib.h>-
23#include <string.h>-
24#include <sys/stat.h>-
25#include <unistd.h>-
26-
27#include "areadlink.h"-
28#include "file-set.h"-
29#include "hash-triple.h"-
30#include "pathmax.h"-
31#include "xalloc.h"-
32#include "xgetcwd.h"-
33#include "dosname.h"-
34-
35#define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0)-
36-
37/* In this file, we cannot handle file names longer than PATH_MAX.-
38 On systems with no file name length limit, use a fallback. */-
39#ifndef PATH_MAX-
40# define PATH_MAX 8192-
41#endif-
42-
43#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT-
44# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0-
45#endif-
46-
47#if ISSLASH ('\\')-
48# define SLASHES "/\\"-
49#else-
50# define SLASHES "/"-
51#endif-
52-
53#if !((HAVE_CANONICALIZE_FILE_NAME && FUNC_REALPATH_WORKS) \-
54 || GNULIB_CANONICALIZE_LGPL)-
55/* Return the canonical absolute name of file NAME. A canonical name-
56 does not contain any ".", ".." components nor any repeated file name-
57 separators ('/') or symlinks. All components must exist.-
58 The result is malloc'd. */-
59-
60char *-
61canonicalize_file_name (const char *name)-
62{-
63 return canonicalize_filename_mode (name, CAN_EXISTING);-
64}-
65#endif /* !HAVE_CANONICALIZE_FILE_NAME */-
66-
67/* Return true if we've already seen the triple, <FILENAME, dev, ino>.-
68 If *HT is not initialized, initialize it. */-
69static bool-
70seen_triple (Hash_table **ht, char const *filename, struct stat const *st)-
71{-
72 if (*ht == NULL)
*ht == ((void *)0)Description
TRUEevaluated 130 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • ln
  • readlink
45-130
73 {-
74 size_t initial_capacity = 7;-
75 *ht = hash_initialize (initial_capacity,-
76 NULL,-
77 triple_hash,-
78 triple_compare_ino_str,-
79 triple_free);-
80 if (*ht == NULL)
*ht == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 130 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-130
81 xalloc_die ();
never executed: xalloc_die ();
0
82 }
executed 130 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
130
83-
84 if (seen_file (*ht, filename, st))
seen_file (*ht, filename, st)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 165 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
10-165
85 return true;
executed 10 times by 1 test: return 1 ;
Executed by:
  • readlink
10
86-
87 record_file (*ht, filename, st);-
88 return false;
executed 165 times by 3 tests: return 0 ;
Executed by:
  • ln
  • readlink
  • realpath
165
89}-
90-
91/* Return the canonical absolute name of file NAME, while treating-
92 missing elements according to CAN_MODE. A canonical name-
93 does not contain any ".", ".." components nor any repeated file name-
94 separators ('/') or, depending on other CAN_MODE flags, symlinks.-
95 Whether components must exist or not depends on canonicalize mode.-
96 The result is malloc'd. */-
97-
98char *-
99canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)-
100{-
101 char *rname, *dest, *extra_buf = NULL;-
102 char const *start;-
103 char const *end;-
104 char const *rname_limit;-
105 size_t extra_len = 0;-
106 Hash_table *ht = NULL;-
107 int saved_errno;-
108 int can_flags = can_mode & ~CAN_MODE_MASK;-
109 bool logical = can_flags & CAN_NOLINKS;-
110 size_t prefix_len;-
111-
112 can_mode &= CAN_MODE_MASK;-
113-
114 if (MULTIPLE_BITS_SET (can_mode))
(((can_mode) &...e) - 1)) != 0)Description
TRUEnever evaluated
FALSEevaluated 273 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-273
115 {-
116 errno = EINVAL;-
117 return NULL;
never executed: return ((void *)0) ;
0
118 }-
119-
120 if (name == NULL)
name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 273 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-273
121 {-
122 errno = EINVAL;-
123 return NULL;
never executed: return ((void *)0) ;
0
124 }-
125-
126 if (name[0] == '\0')
name[0] == '\0'Description
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • ln
  • realpath
FALSEevaluated 270 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
3-270
127 {-
128 errno = ENOENT;-
129 return NULL;
executed 3 times by 2 tests: return ((void *)0) ;
Executed by:
  • ln
  • realpath
3
130 }-
131-
132 /* This is always zero for Posix hosts, but can be 2 for MS-Windows-
133 and MS-DOS X:/foo/bar file names. */-
134 prefix_len = FILE_SYSTEM_PREFIX_LEN (name);-
135-
136 if (!IS_ABSOLUTE_FILE_NAME (name))
(((name)[0]) == '/')Description
TRUEevaluated 135 times by 2 tests
Evaluated by:
  • readlink
  • realpath
FALSEevaluated 135 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0 != 0Description
TRUEnever evaluated
FALSEevaluated 135 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-135
137 {-
138 rname = xgetcwd ();-
139 if (!rname)
!rnameDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 132 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
3-132
140 return NULL;
executed 3 times by 1 test: return ((void *)0) ;
Executed by:
  • readlink
3
141 dest = strchr (rname, '\0');
__builtin_constant_p ( '\0' )Description
TRUEevaluated 132 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
!__builtin_con...nt_p ( rname )Description
TRUEevaluated 132 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
( '\0' ) == '\0'Description
TRUEevaluated 132 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
0-132
142 if (dest - rname < PATH_MAX)
dest - rname < 4096Description
TRUEevaluated 132 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
0-132
143 {-
144 char *p = xrealloc (rname, PATH_MAX);-
145 dest = p + (dest - rname);-
146 rname = p;-
147 rname_limit = rname + PATH_MAX;-
148 }
executed 132 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
132
149 else-
150 {-
151 rname_limit = dest;-
152 }
never executed: end of block
0
153 start = name;-
154 prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);-
155 }
executed 132 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
132
156 else-
157 {-
158 rname = xmalloc (PATH_MAX);-
159 rname_limit = rname + PATH_MAX;-
160 dest = rname;-
161 if (prefix_len)
prefix_lenDescription
TRUEnever evaluated
FALSEevaluated 135 times by 2 tests
Evaluated by:
  • readlink
  • realpath
0-135
162 {-
163 memcpy (rname, name, prefix_len);-
164 dest += prefix_len;-
165 }
never executed: end of block
0
166 *dest++ = '/';-
167 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
168 {
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
169 if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
170 *dest++ = '/';
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
171 *dest = '\0';
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
172 }
dead code: { if (((name[1]) == '/') && !((name[2]) == '/') && !prefix_len) *dest++ = '/'; *dest = '\0'; }
-
173 start = name + prefix_len;-
174 }
executed 135 times by 2 tests: end of block
Executed by:
  • readlink
  • realpath
135
175-
176 for ( ; *start; start = end)
*startDescription
TRUEevaluated 1351 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 124 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
124-1351
177 {-
178 /* Skip sequence of multiple file name separators. */-
179 while (ISSLASH (*start))
((*start) == '/')Description
TRUEevaluated 1121 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 1351 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
1121-1351
180 ++start;
executed 1121 times by 3 tests: ++start;
Executed by:
  • ln
  • readlink
  • realpath
1121
181-
182 /* Find end of component. */-
183 for (end = start; *end && !ISSLASH (*end); ++end)
*endDescription
TRUEevaluated 9435 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 271 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
!((*end) == '/')Description
TRUEevaluated 8355 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 1080 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
271-9435
184 /* Nothing. */;
executed 8355 times by 3 tests: ;
Executed by:
  • ln
  • readlink
  • realpath
8355
185-
186 if (end - start == 0)
end - start == 0Description
TRUEevaluated 81 times by 2 tests
Evaluated by:
  • readlink
  • realpath
FALSEevaluated 1270 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
81-1270
187 break;
executed 81 times by 2 tests: break;
Executed by:
  • readlink
  • realpath
81
188 else if (end - start == 1 && start[0] == '.')
end - start == 1Description
TRUEevaluated 234 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 1036 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
start[0] == '.'Description
TRUEevaluated 94 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 140 times by 2 tests
Evaluated by:
  • readlink
  • realpath
94-1036
189 /* nothing */;
executed 94 times by 3 tests: ;
Executed by:
  • ln
  • readlink
  • realpath
94
190 else if (end - start == 2 && start[0] == '.' && start[1] == '.')
end - start == 2Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 1154 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
start[0] == '.'Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
start[1] == '.'Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
0-1154
191 {-
192 /* Back up to previous component, ignore if at root already. */-
193 if (dest > rname + prefix_len + 1)
dest > rname + prefix_len + 1Description
TRUEevaluated 13 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 9 times by 1 test
Evaluated by:
  • readlink
9-13
194 for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
dest > rnameDescription
TRUEevaluated 33 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
!((dest[-1]) == '/')Description
TRUEevaluated 20 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 13 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-33
195 continue;
executed 20 times by 3 tests: continue;
Executed by:
  • ln
  • readlink
  • realpath
20
196 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
dead code: dest == rname + 1
-
197 && !prefix_len && ISSLASH (*dest) && !ISSLASH (dest[1]))
dead code: !prefix_len
dead code: ((*dest) == '/')
dead code: !((dest[1]) == '/')
dead code: dest++;
-
198 dest++;
dead code: dest++;
-
199 }
executed 22 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
22
200 else-
201 {-
202 struct stat st;-
203-
204 if (!ISSLASH (dest[-1]))
!((dest[-1]) == '/')Description
TRUEevaluated 889 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 265 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
265-889
205 *dest++ = '/';
executed 889 times by 3 tests: *dest++ = '/';
Executed by:
  • ln
  • readlink
  • realpath
889
206-
207 if (dest + (end - start) >= rname_limit)
dest + (end - ...>= rname_limitDescription
TRUEnever evaluated
FALSEevaluated 1154 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-1154
208 {-
209 ptrdiff_t dest_offset = dest - rname;-
210 size_t new_size = rname_limit - rname;-
211-
212 if (end - start + 1 > PATH_MAX)
end - start + 1 > 4096Description
TRUEnever evaluated
FALSEnever evaluated
0
213 new_size += end - start + 1;
never executed: new_size += end - start + 1;
0
214 else-
215 new_size += PATH_MAX;
never executed: new_size += 4096 ;
0
216 rname = xrealloc (rname, new_size);-
217 rname_limit = rname + new_size;-
218-
219 dest = rname + dest_offset;-
220 }
never executed: end of block
0
221-
222 dest = memcpy (dest, start, end - start);-
223 dest += end - start;-
224 *dest = '\0';-
225-
226 if (logical && (can_mode == CAN_MISSING))
logicalDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • realpath
FALSEevaluated 1131 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
(can_mode == CAN_MISSING)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • realpath
FALSEevaluated 2 times by 1 test
Evaluated by:
  • realpath
2-1131
227 {-
228 /* Avoid the stat in this case as it's inconsequential.-
229 i.e. we're neither resolving symlinks or testing-
230 component existence. */-
231 st.st_mode = 0;-
232 }
executed 21 times by 1 test: end of block
Executed by:
  • realpath
21
233 else if ((logical ? stat (rname, &st) : lstat (rname, &st)) != 0)
(logical ? sta...me, &st)) != 0Description
TRUEevaluated 133 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 1000 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
logicalDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • realpath
FALSEevaluated 1131 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
2-1131
234 {-
235 /* FIXME: If errno == EOVERFLOW here, the entry exists. */-
236 saved_errno = errno;-
237 if (can_mode == CAN_EXISTING)
can_mode == CAN_EXISTINGDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 115 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
18-115
238 goto error;
executed 18 times by 1 test: goto error;
Executed by:
  • readlink
18
239 if (can_mode == CAN_ALL_BUT_LAST)
can_mode == CAN_ALL_BUT_LASTDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 79 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
36-79
240 {-
241 if (end[strspn (end, SLASHES)] || saved_errno != ENOENT)
end[ __builtin... end , "/" ) ]Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 20 times by 1 test
Evaluated by:
  • readlink
saved_errno != 2Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • readlink
0-20
242 goto error;
executed 16 times by 1 test: goto error;
Executed by:
  • readlink
16
243 continue;
executed 20 times by 1 test: continue;
Executed by:
  • readlink
20
244 }-
245 st.st_mode = 0;-
246 }
executed 79 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
79
247-
248 if (S_ISLNK (st.st_mode))
(((( st.st_mod... == (0120000))Description
TRUEevaluated 175 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 925 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
175-925
249 {-
250 char *buf;-
251 size_t n, len;-
252-
253 /* Detect loops. We cannot use the cycle-check module here,-
254 since it's actually possible to encounter the same symlink-
255 more than once in a given traversal. However, encountering-
256 the same symlink,NAME pair twice does indicate a loop. */-
257 if (seen_triple (&ht, name, &st))
seen_triple (&ht, name, &st)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 165 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
10-165
258 {-
259 if (can_mode == CAN_MISSING)
can_mode == CAN_MISSINGDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • readlink
0-10
260 continue;
never executed: continue;
0
261 saved_errno = ELOOP;-
262 goto error;
executed 10 times by 1 test: goto error;
Executed by:
  • readlink
10
263 }-
264-
265 buf = areadlink_with_size (rname, st.st_size);-
266 if (!buf)
!bufDescription
TRUEnever evaluated
FALSEevaluated 165 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-165
267 {-
268 if (can_mode == CAN_MISSING && errno != ENOMEM)
can_mode == CAN_MISSINGDescription
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) != 12Description
TRUEnever evaluated
FALSEnever evaluated
0
269 continue;
never executed: continue;
0
270 saved_errno = errno;-
271 goto error;
never executed: goto error;
0
272 }-
273-
274 n = strlen (buf);-
275 len = strlen (end);-
276-
277 if (!extra_len)
!extra_lenDescription
TRUEevaluated 130 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • ln
  • readlink
35-130
278 {-
279 extra_len =-
280 ((n + len + 1) > PATH_MAX) ? (n + len + 1) : PATH_MAX;
((n + len + 1) > 4096 )Description
TRUEnever evaluated
FALSEevaluated 130 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-130
281 extra_buf = xmalloc (extra_len);-
282 }
executed 130 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
130
283 else if ((n + len + 1) > extra_len)
(n + len + 1) > extra_lenDescription
TRUEnever evaluated
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • ln
  • readlink
0-35
284 {-
285 extra_len = n + len + 1;-
286 extra_buf = xrealloc (extra_buf, extra_len);-
287 }
never executed: end of block
0
288-
289 /* Careful here, end may be a pointer into extra_buf... */-
290 memmove (&extra_buf[n], end, len + 1);-
291 name = end = memcpy (extra_buf, buf, n);-
292-
293 if (IS_ABSOLUTE_FILE_NAME (buf))
(((buf)[0]) == '/')Description
TRUEevaluated 18 times by 2 tests
Evaluated by:
  • readlink
  • realpath
FALSEevaluated 147 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0 != 0Description
TRUEnever evaluated
FALSEevaluated 147 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-147
294 {-
295 size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);-
296-
297 if (pfxlen)
pfxlenDescription
TRUEnever evaluated
FALSEevaluated 18 times by 2 tests
Evaluated by:
  • readlink
  • realpath
0-18
298 memcpy (rname, buf, pfxlen);
never executed: memcpy (rname, buf, pfxlen);
0
299 dest = rname + pfxlen;-
300 *dest++ = '/'; /* It's an absolute symlink */-
301 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
302 {
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
303 if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen)
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
304 *dest++ = '/';
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
305 *dest = '\0';
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
306 }
dead code: { if (((buf[1]) == '/') && !((buf[2]) == '/') && !pfxlen) *dest++ = '/'; *dest = '\0'; }
-
307 /* Install the new prefix to be in effect hereafter. */-
308 prefix_len = pfxlen;-
309 }
executed 18 times by 2 tests: end of block
Executed by:
  • readlink
  • realpath
18
310 else-
311 {-
312 /* Back up to previous component, ignore if at root-
313 already: */-
314 if (dest > rname + prefix_len + 1)
dest > rname + prefix_len + 1Description
TRUEevaluated 147 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
0-147
315 for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
dest > rnameDescription
TRUEevaluated 608 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
!((dest[-1]) == '/')Description
TRUEevaluated 461 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 147 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
0-608
316 continue;
executed 461 times by 3 tests: continue;
Executed by:
  • ln
  • readlink
  • realpath
461
317 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
dead code: dest == rname + 1
-
318 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
dead code: ((*dest) == '/')
dead code: !((dest[1]) == '/')
dead code: !prefix_len
dead code: dest++;
-
319 dest++;
dead code: dest++;
-
320 }
executed 147 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
147
321-
322 free (buf);-
323 }
executed 165 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
165
324 else-
325 {-
326 if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING))
! (((( st.st_m... == (0040000))Description
TRUEevaluated 149 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 776 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
*endDescription
TRUEevaluated 73 times by 2 tests
Evaluated by:
  • readlink
  • realpath
FALSEevaluated 76 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
(can_mode != CAN_MISSING)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 55 times by 2 tests
Evaluated by:
  • readlink
  • realpath
18-776
327 {-
328 saved_errno = ENOTDIR;-
329 goto error;
executed 18 times by 1 test: goto error;
Executed by:
  • readlink
18
330 }-
331 }
executed 907 times by 3 tests: end of block
Executed by:
  • ln
  • readlink
  • realpath
907
332 }-
333 }-
334 if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
dest > rname + prefix_len + 1Description
TRUEevaluated 170 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • readlink
  • realpath
((dest[-1]) == '/')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • realpath
FALSEevaluated 168 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
2-170
335 --dest;
executed 2 times by 1 test: --dest;
Executed by:
  • realpath
2
336 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len
dead code: dest == rname + 1
dead code: !prefix_len
-
337 && ISSLASH (*dest) && !ISSLASH (dest[1]))
dead code: ((*dest) == '/')
dead code: !((dest[1]) == '/')
dead code: dest++;
-
338 dest++;
dead code: dest++;
-
339 *dest = '\0';-
340 if (rname_limit != dest + 1)
rname_limit != dest + 1Description
TRUEevaluated 205 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEnever evaluated
0-205
341 rname = xrealloc (rname, dest - rname + 1);
executed 205 times by 3 tests: rname = xrealloc (rname, dest - rname + 1);
Executed by:
  • ln
  • readlink
  • realpath
205
342-
343 free (extra_buf);-
344 if (ht)
htDescription
TRUEevaluated 84 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
FALSEevaluated 121 times by 3 tests
Evaluated by:
  • ln
  • readlink
  • realpath
84-121
345 hash_free (ht);
executed 84 times by 3 tests: hash_free (ht);
Executed by:
  • ln
  • readlink
  • realpath
84
346 return rname;
executed 205 times by 3 tests: return rname;
Executed by:
  • ln
  • readlink
  • realpath
205
347-
348error:-
349 free (extra_buf);-
350 free (rname);-
351 if (ht)
htDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • readlink
FALSEevaluated 16 times by 1 test
Evaluated by:
  • readlink
16-46
352 hash_free (ht);
executed 46 times by 1 test: hash_free (ht);
Executed by:
  • readlink
46
353 errno = saved_errno;-
354 return NULL;
executed 62 times by 1 test: return ((void *)0) ;
Executed by:
  • readlink
62
355}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2