Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | #include <config.h> | - |
22 | | - |
23 | #include <bashtypes.h> | - |
24 | #if defined (HAVE_SYS_PARAM_H) | - |
25 | # include <sys/param.h> | - |
26 | #endif | - |
27 | #include <posixstat.h> | - |
28 | | - |
29 | #if defined (HAVE_UNISTD_H) | - |
30 | # include <unistd.h> | - |
31 | #endif | - |
32 | | - |
33 | #include <filecntl.h> | - |
34 | #include <bashansi.h> | - |
35 | #include <stdio.h> | - |
36 | #include <chartypes.h> | - |
37 | #include <errno.h> | - |
38 | | - |
39 | #include "shell.h" | - |
40 | | - |
41 | #if !defined (errno) | - |
42 | extern int errno; | - |
43 | #endif | - |
44 | | - |
45 | #if defined (__CYGWIN__) | - |
46 | #include <sys/cygwin.h> | - |
47 | | - |
48 | static int | - |
49 | _is_cygdrive (path) | - |
50 | char *path; | - |
51 | { | - |
52 | static char user[MAXPATHLEN]; | - |
53 | static char system[MAXPATHLEN]; | - |
54 | static int first_time = 1; | - |
55 | | - |
56 | | - |
57 | | - |
58 | if (path[0] == '/' && path[1] == '/' && !strchr (path + 2, '/')) | - |
59 | return 1; | - |
60 | | - |
61 | if (first_time) | - |
62 | { | - |
63 | char user_flags[MAXPATHLEN]; | - |
64 | char system_flags[MAXPATHLEN]; | - |
65 | | - |
66 | cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags, system_flags); | - |
67 | first_time = 0; | - |
68 | } | - |
69 | return !strcasecmp (path, user) || !strcasecmp (path, system); | - |
70 | } | - |
71 | #endif /* __CYGWIN__ */ | - |
72 | | - |
73 | | - |
74 | static int | - |
75 | _path_isdir (path) | - |
76 | char *path; | - |
77 | { | - |
78 | int l; | - |
79 | struct stat sb; | - |
80 | | - |
81 | | - |
82 | errno = 0; | - |
83 | l = stat (path, &sb) == 0 && S_ISDIR (sb.st_mode);TRUE | evaluated 38354 times by 1 test | FALSE | evaluated 5 times by 1 test |
TRUE | evaluated 38353 times by 1 test | FALSE | evaluated 1 time by 1 test |
| 1-38354 |
84 | #if defined (__CYGWIN__) | - |
85 | if (l == 0) | - |
86 | l = _is_cygdrive (path); | - |
87 | #endif | - |
88 | return l;executed 38359 times by 1 test: return l; | 38359 |
89 | } | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | #define DOUBLE_SLASH(p) ((p[0] == '/') && (p[1] == '/') && p[2] != '/') | - |
102 | | - |
103 | char * | - |
104 | sh_canonpath (path, flags) | - |
105 | char *path; | - |
106 | int flags; | - |
107 | { | - |
108 | char stub_char; | - |
109 | char *result, *p, *q, *base, *dotdot; | - |
110 | int rooted, double_slash_path; | - |
111 | | - |
112 | | - |
113 | result = (flags & PATH_NOALLOC) ? path : savestring (path);TRUE | never evaluated | FALSE | evaluated 5515 times by 1 test |
| 0-5515 |
114 | | - |
115 | | - |
116 | | - |
117 | if (rooted = ROOTEDPATH(path))TRUE | evaluated 5515 times by 1 test | FALSE | never evaluated |
| 0-5515 |
118 | { | - |
119 | stub_char = DIRSEP; | - |
120 | #if defined (__CYGWIN__) | - |
121 | base = (ISALPHA((unsigned char)result[0]) && result[1] == ':') ? result + 3 : result + 1; | - |
122 | #else | - |
123 | base = result + 1; | - |
124 | #endif | - |
125 | double_slash_path = DOUBLE_SLASH (path);TRUE | evaluated 5515 times by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 5515 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
| 0-5515 |
126 | base += double_slash_path; | - |
127 | }executed 5515 times by 1 test: end of block | 5515 |
128 | else | - |
129 | { | - |
130 | stub_char = '.'; | - |
131 | #if defined (__CYGWIN__) | - |
132 | base = (ISALPHA((unsigned char)result[0]) && result[1] == ':') ? result + 2 : result; | - |
133 | #else | - |
134 | base = result; | - |
135 | #endif | - |
136 | double_slash_path = 0; | - |
137 | } never executed: end of block | 0 |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | p = q = dotdot = base; | - |
148 | | - |
149 | while (*p)TRUE | evaluated 71210 times by 1 test | FALSE | evaluated 5509 times by 1 test |
| 5509-71210 |
150 | { | - |
151 | if (ISDIRSEP(p[0])) TRUE | evaluated 32850 times by 1 test | FALSE | evaluated 38360 times by 1 test |
| 32850-38360 |
152 | p++;executed 32850 times by 1 test: p++; | 32850 |
153 | else if(p[0] == '.' && PATHSEP(p[1])) TRUE | evaluated 1 time by 1 test | FALSE | evaluated 38359 times by 1 test |
TRUE | evaluated 1 time by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-38359 |
154 | p += 1; executed 1 time by 1 test: p += 1; | 1 |
155 | else if (p[0] == '.' && p[1] == '.' && PATHSEP(p[2])) TRUE | never evaluated | FALSE | evaluated 38359 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-38359 |
156 | { | - |
157 | p += 2; | - |
158 | if (q > dotdot) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
159 | { | - |
160 | if (flags & PATH_CHECKDOTDOT)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
161 | { | - |
162 | char c; | - |
163 | | - |
164 | | - |
165 | | - |
166 | c = *q; | - |
167 | *q = '\0'; | - |
168 | if (_path_isdir (result) == 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
169 | { | - |
170 | if ((flags & PATH_NOALLOC) == 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
171 | free (result); never executed: sh_xfree((result), "pathcanon.c", 171); | 0 |
172 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 |
173 | } | - |
174 | *q = c; | - |
175 | } never executed: end of block | 0 |
176 | | - |
177 | while (--q > dotdot && ISDIRSEP(*q) == 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
178 | ; never executed: ; | 0 |
179 | } never executed: end of block | 0 |
180 | else if (rooted == 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
181 | { | - |
182 | | - |
183 | if (q != base)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
184 | *q++ = DIRSEP; never executed: *q++ = '/'; | 0 |
185 | *q++ = '.'; | - |
186 | *q++ = '.'; | - |
187 | dotdot = q; | - |
188 | } never executed: end of block | 0 |
189 | } never executed: end of block | 0 |
190 | else | - |
191 | { | - |
192 | | - |
193 | if (q != base)TRUE | evaluated 32849 times by 1 test | FALSE | evaluated 5510 times by 1 test |
| 5510-32849 |
194 | *q++ = DIRSEP;executed 32849 times by 1 test: *q++ = '/'; | 32849 |
195 | while (*p && (ISDIRSEP(*p) == 0))TRUE | evaluated 323202 times by 1 test | FALSE | evaluated 5510 times by 1 test |
TRUE | evaluated 290353 times by 1 test | FALSE | evaluated 32849 times by 1 test |
| 5510-323202 |
196 | *q++ = *p++;executed 290353 times by 1 test: *q++ = *p++; | 290353 |
197 | | - |
198 | if (flags & PATH_CHECKEXISTS)TRUE | evaluated 38359 times by 1 test | FALSE | never evaluated |
| 0-38359 |
199 | { | - |
200 | char c; | - |
201 | | - |
202 | | - |
203 | | - |
204 | c = *q; | - |
205 | *q = '\0'; | - |
206 | if (_path_isdir (result) == 0)TRUE | evaluated 6 times by 1 test | FALSE | evaluated 38353 times by 1 test |
| 6-38353 |
207 | { | - |
208 | if ((flags & PATH_NOALLOC) == 0)TRUE | evaluated 6 times by 1 test | FALSE | never evaluated |
| 0-6 |
209 | free (result);executed 6 times by 1 test: sh_xfree((result), "pathcanon.c", 209); | 6 |
210 | return ((char *)NULL);executed 6 times by 1 test: return ((char *) ((void *)0) ); | 6 |
211 | } | - |
212 | *q = c; | - |
213 | }executed 38353 times by 1 test: end of block | 38353 |
214 | }executed 38353 times by 1 test: end of block | 38353 |
215 | } | - |
216 | | - |
217 | | - |
218 | if (q == result)TRUE | never evaluated | FALSE | evaluated 5509 times by 1 test |
| 0-5509 |
219 | *q++ = stub_char; never executed: *q++ = stub_char; | 0 |
220 | *q = '\0'; | - |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | if (DOUBLE_SLASH(result) && double_slash_path == 0)TRUE | evaluated 5509 times by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 5509 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-5509 |
226 | { | - |
227 | if (result[2] == '\0') TRUE | never evaluated | FALSE | never evaluated |
| 0 |
228 | result[1] = '\0'; never executed: result[1] = '\0'; | 0 |
229 | else | - |
230 | strcpy (result, result + 1); never executed: strcpy (result, result + 1); | 0 |
231 | } | - |
232 | | - |
233 | return (result);executed 5509 times by 1 test: return (result); | 5509 |
234 | } | - |
| | |