211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
+
+
+
+
+
|
** * removing /./
** * removing /A/../
**
** Changes are made in-place. Return the new name length.
*/
int file_simplify_name(char *z, int n){
int i, j;
#ifdef __MINGW32__
for(i=0; i<n; i++){
if( z[i]=='\\' ) z[i] = '/';
}
#endif
while( n>1 && z[n-1]=='/' ){ n--; }
for(i=j=0; i<n; i++){
if( z[i]=='/' ){
if( z[i+1]=='/' ) continue;
if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
i += 1;
continue;
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
blob_zero(&x);
for(i=2; i<g.argc; i++){
file_canonical_name(g.argv[i], &x);
printf("%s\n", blob_buffer(&x));
blob_reset(&x);
}
}
/*
** Return TRUE if the given filename is canonical.
**
** Canonical names are full pathnames using "/" not "\" and which
** contain no "/./" or "/../" terms.
*/
int file_is_canonical(const char *z){
int i;
if( z[0]!='/'
#ifdef __MINGW32__
&& (z[0]==0 || z[1]!=':' || z[2]!='/')
#endif
) return 0;
for(i=0; z[i]; i++){
if( z[i]=='\\' ) return 0;
if( z[i]=='/' ){
if( z[i+1]=='.' ){
if( z[i+2]=='/' || z[i+2]==0 ) return 0;
if( z[i+2]=='.' && (z[i+3]=='/' || z[i+3]==0) ) return 0;
}
}
}
return 1;
}
/*
** Compute a pathname for a file or directory that is relative
** to the current directory.
*/
void file_relative_name(const char *zOrigName, Blob *pOut){
char *zPath;
|