Differences From:
File
src/file.c
part of check-in
[7a2c37063a]
- merge trunk into creole branch
by
bob on
2009-09-22 07:49:39.
Also file
src/file.c
part of check-in
[42bf80978d]
- On windows, if the first character of a pathname is '\' then assume that is
a full pathname, not a relative pathname. Ticket cdd360438de.
by
drh on
2009-09-13 16:19:43.
[view]
To:
File
src/file.c
part of check-in
[d5695157d0]
- Deal with windows filename aliasing in the "all" command.
Ticket 974618fe5a8. Also display the home directory for windows
users with the "info" command since the home directory is non-obvious
in windows.
by
drh on
2009-11-11 16:21:19.
[view]
@@ -214,8 +214,13 @@
** 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;
@@ -278,8 +283,34 @@
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