OpenCoverage

pathphys.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/pathphys.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9extern char *get_working_directory (char *);-
10-
11static int-
12_path_readlink (path, buf, bufsiz)-
13 char *path;-
14 char *buf;-
15 int bufsiz;-
16{-
17-
18 return
executed 7 times by 1 test: return readlink (path, buf, bufsiz);
Executed by:
  • Self test
readlink (path, buf, bufsiz);
executed 7 times by 1 test: return readlink (path, buf, bufsiz);
Executed by:
  • Self test
7
19-
20-
21-
22-
23}-
24char *-
25sh_physpath (path, flags)-
26 char *path;-
27 int flags;-
28{-
29 char tbuf[-
30 4096-
31 +1], linkbuf[-
32 4096-
33 +1];-
34 char *result, *p, *q, *qsave, *qbase, *workpath;-
35 int double_slash_path, linklen, nlink;-
36-
37 linklen = strlen (path);-
38-
39-
40-
41-
42-
43-
44-
45 nlink = 0;-
46 q = result = (char *)sh_xmalloc((-
47 4096 -
48 + 1), "pathphys.c", 92);-
49-
50-
51-
52 if (linklen >=
linklen >= 4096Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
53 4096
linklen >= 4096Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
54 )-
55 workpath = (char *)strcpy (sh_xmalloc((1 + strlen (path)), "pathphys.c", 97), (path));
never executed: workpath = (char *)strcpy (sh_xmalloc((1 + strlen (path)), "pathphys.c", 97), (path));
0
56 else-
57 {-
58 workpath = (char *)sh_xmalloc((-
59 4096 -
60 + 1), "pathphys.c", 100);-
61 strcpy (workpath, path);-
62 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
63 qbase = workpath + 1;-
64-
65 double_slash_path = ((
(workpath[0] == '/')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
workpath[0] == '/')
(workpath[0] == '/')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
&& (
(workpath[1] == '/')Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
workpath[1] == '/')
(workpath[1] == '/')Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
&& workpath[2] != '/'
workpath[2] != '/'Description
TRUEnever evaluated
FALSEnever evaluated
);
0-4
66 qbase += double_slash_path;-
67-
68 for (p = workpath; p < qbase
p < qbaseDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
; )
4
69 *
executed 4 times by 1 test: *q++ = *p++;
Executed by:
  • Self test
q++ = *p++;
executed 4 times by 1 test: *q++ = *p++;
Executed by:
  • Self test
4
70 qbase = q;-
71 while (*
*pDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
p
*pDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
)
4-13
72 {-
73 if (((
((p[0]) == '/')Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
p[0]) == '/')
((p[0]) == '/')Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
)
6-7
74 p++;
executed 6 times by 1 test: p++;
Executed by:
  • Self test
6
75 else if(p[0] == '.'
p[0] == '.'Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
&& (((
((p[1]) == '/')Description
TRUEnever evaluated
FALSEnever evaluated
p[1]) == '/')
((p[1]) == '/')Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(p[1]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
p[1]) == 0
(p[1]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
))
0-7
76 p += 1;
never executed: p += 1;
0
77 else if (p[0] == '.'
p[0] == '.'Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
&& p[1] == '.'
p[1] == '.'Description
TRUEnever evaluated
FALSEnever evaluated
&& (((
((p[2]) == '/')Description
TRUEnever evaluated
FALSEnever evaluated
p[2]) == '/')
((p[2]) == '/')Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(p[2]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
p[2]) == 0
(p[2]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
))
0-7
78 {-
79 p += 2;-
80 if (q > qbase
q > qbaseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
81 {-
82 while (--
--q > qbaseDescription
TRUEnever evaluated
FALSEnever evaluated
q > qbase
--q > qbaseDescription
TRUEnever evaluated
FALSEnever evaluated
&& ((*
((*q) == '/') == 0Description
TRUEnever evaluated
FALSEnever evaluated
q) == '/') == 0
((*q) == '/') == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
83 ;
never executed: ;
0
84 }
never executed: end of block
0
85 }
never executed: end of block
0
86 else-
87 {-
88-
89 qsave = q;-
90 if (q != qbase
q != qbaseDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
)
1-6
91 *
executed 6 times by 1 test: *q++ = '/';
Executed by:
  • Self test
q++ = '/';
executed 6 times by 1 test: *q++ = '/';
Executed by:
  • Self test
6
92 while (*
*pDescription
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
p
*pDescription
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
&& (((*
(((*p) == '/') == 0)Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
p) == '/') == 0)
(((*p) == '/') == 0)Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
)
1-59
93 {-
94 if (q - result >=
q - result >= 4096Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
0-53
95 4096
q - result >= 4096Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
0-53
96 )-
97 {-
98-
99 -
100 (*__errno_location ()) -
101 = -
102 36-
103 ;-
104-
105-
106-
107 goto
never executed: goto error;
error;
never executed: goto error;
0
108 }-
109-
110 *q++ = *p++;-
111 }
executed 53 times by 1 test: end of block
Executed by:
  • Self test
53
112-
113 *q = '\0';-
114-
115 linklen = _path_readlink (result, linkbuf, -
116 4096-
117 );-
118 if (linklen < 0
linklen < 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-7
119 {-
120 if (-
121 (*
(*__errno_location ()) != 22Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
__errno_location ())
(*__errno_location ()) != 22Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
122 !=
(*__errno_location ()) != 22Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
123 22
(*__errno_location ()) != 22Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
124 )-
125 goto
never executed: goto error;
error;
never executed: goto error;
0
126 continue;
executed 7 times by 1 test: continue;
Executed by:
  • Self test
7
127 }-
128-
129-
130 nlink++;-
131 if (nlink >
nlink > 20Description
TRUEnever evaluated
FALSEnever evaluated
0
132 20
nlink > 20Description
TRUEnever evaluated
FALSEnever evaluated
0
133 )-
134 {-
135-
136 -
137 (*__errno_location ()) -
138 = -
139 40-
140 ;-
141-
142-
143-
144error:
code before this statement never executed: error:
0
145 sh_xfree((result), "pathphys.c", 185);-
146 sh_xfree((workpath), "pathphys.c", 186);-
147 return
never executed: return ((char *) ((void *)0) );
((char *)
never executed: return ((char *) ((void *)0) );
0
148 ((void *)0)
never executed: return ((char *) ((void *)0) );
0
149 );
never executed: return ((char *) ((void *)0) );
0
150 }-
151-
152 linkbuf[linklen] = '\0';-
153-
154-
155 if ((
(strlen (p) + ...n + 2) >= 4096Description
TRUEnever evaluated
FALSEnever evaluated
strlen (p) + linklen + 2) >=
(strlen (p) + ...n + 2) >= 4096Description
TRUEnever evaluated
FALSEnever evaluated
0
156 4096
(strlen (p) + ...n + 2) >= 4096Description
TRUEnever evaluated
FALSEnever evaluated
0
157 )-
158 {-
159-
160 -
161 (*__errno_location ()) -
162 = -
163 36-
164 ;-
165-
166-
167-
168 goto
never executed: goto error;
error;
never executed: goto error;
0
169 }-
170-
171-
172-
173-
174-
175-
176 strcpy (tbuf, linkbuf);-
177 tbuf[linklen] = '/';-
178 strcpy (tbuf + linklen, p);-
179 strcpy (workpath, tbuf);-
180-
181 if (((
((linkbuf)[0] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
linkbuf)[0] == '/')
((linkbuf)[0] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
)
0
182 {-
183 q = result;-
184-
185-
186-
187-
188 qbase = workpath + 1;-
189-
190 double_slash_path = ((
(workpath[0] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
workpath[0] == '/')
(workpath[0] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(workpath[1] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
workpath[1] == '/')
(workpath[1] == '/')Description
TRUEnever evaluated
FALSEnever evaluated
&& workpath[2] != '/'
workpath[2] != '/'Description
TRUEnever evaluated
FALSEnever evaluated
);
0
191 qbase += double_slash_path;-
192-
193 for (p = workpath; p < qbase
p < qbaseDescription
TRUEnever evaluated
FALSEnever evaluated
; )
0
194 *
never executed: *q++ = *p++;
q++ = *p++;
never executed: *q++ = *p++;
0
195 qbase = q;-
196 }
never executed: end of block
0
197 else-
198 {-
199 p = workpath;-
200 q = qsave;-
201 }
never executed: end of block
0
202 }-
203 }-
204-
205 *q = '\0';-
206 sh_xfree((workpath), "pathphys.c", 238);-
207-
208-
209-
210-
211 if (((
(result[0] == '/')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
result[0] == '/')
(result[0] == '/')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
&& (
(result[1] == '/')Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
result[1] == '/')
(result[1] == '/')Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
&& result[2] != '/'
result[2] != '/'Description
TRUEnever evaluated
FALSEnever evaluated
) && double_slash_path == 0
double_slash_path == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0-4
212 {-
213 if (result[2] == '\0'
result[2] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
214 result[1] = '\0';
never executed: result[1] = '\0';
0
215 else-
216 strcpy (result, result + 1);
never executed: strcpy (result, result + 1);
0
217 }-
218-
219 return
executed 4 times by 1 test: return (result);
Executed by:
  • Self test
(result);
executed 4 times by 1 test: return (result);
Executed by:
  • Self test
4
220}-
221-
222char *-
223sh_realpath (pathname, resolved)-
224 const char *pathname;-
225 char *resolved;-
226{-
227 char *tdir, *wd;-
228-
229 if (pathname == 0
pathname == 0Description
TRUEnever evaluated
FALSEnever evaluated
|| *
*pathname == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
pathname == '\0'
*pathname == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
230 {-
231 -
232 (*__errno_location ()) -
233 = (pathname == 0) ? -
234 22 -
235 : -
236 2-
237 ;-
238 return
never executed: return ((char *) ((void *)0) );
((char *)
never executed: return ((char *) ((void *)0) );
0
239 ((void *)0)
never executed: return ((char *) ((void *)0) );
0
240 );
never executed: return ((char *) ((void *)0) );
0
241 }-
242-
243 if (((
((pathname)[0] == '/') == 0Description
TRUEnever evaluated
FALSEnever evaluated
pathname)[0] == '/') == 0
((pathname)[0] == '/') == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
244 {-
245 wd = get_working_directory ("sh_realpath");-
246 if (wd == 0
wd == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
247 return
never executed: return ((char *) ((void *)0) );
((char *)
never executed: return ((char *) ((void *)0) );
0
248 ((void *)0)
never executed: return ((char *) ((void *)0) );
0
249 );
never executed: return ((char *) ((void *)0) );
0
250 tdir = sh_makepath (wd, (char *)pathname, 0);-
251 sh_xfree((wd), "pathphys.c", 273);-
252 }
never executed: end of block
0
253 else-
254 tdir = (char *)strcpy (sh_xmalloc((1 + strlen (pathname)), "pathphys.c", 276), (pathname));
never executed: tdir = (char *)strcpy (sh_xmalloc((1 + strlen (pathname)), "pathphys.c", 276), (pathname));
0
255-
256 wd = sh_physpath (tdir, 0);-
257 sh_xfree((tdir), "pathphys.c", 279);-
258-
259 if (resolved == 0
resolved == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
260 return
never executed: return (wd);
(wd);
never executed: return (wd);
0
261-
262 if (wd
wdDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
263 {-
264 -
265 __builtin_strncpy (-
266 resolved-
267 , -
268 wd-
269 , 4096 -
270 - 1-
271 )-
272 ;-
273 resolved[-
274 4096 -
275 - 1] = '\0';-
276 sh_xfree((wd), "pathphys.c", 288);-
277 return
never executed: return resolved;
resolved;
never executed: return resolved;
0
278 }-
279 else-
280 {-
281 resolved[0] = '\0';-
282 return
never executed: return wd;
wd;
never executed: return wd;
0
283 }-
284}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2