diff options
author | Ole Loots <ole@monochrom.net> | 2013-10-26 17:24:09 +0200 |
---|---|---|
committer | Ole Loots <ole@monochrom.net> | 2013-10-26 17:24:09 +0200 |
commit | 77129038ee8aa8ccdf8f4a264fd1189459e69326 (patch) | |
tree | dacbbc96fb24b913b9daa57626b5ce253bf993d5 /atari | |
parent | 164571aa98871d47f2efda842d75507f9bd03150 (diff) | |
download | netsurf-77129038ee8aa8ccdf8f4a264fd1189459e69326.tar.gz netsurf-77129038ee8aa8ccdf8f4a264fd1189459e69326.tar.bz2 |
Handle the fact that / is NOT the root of the filesystem on MiNT.
(/ means current drive!) This may break under Classic TOS
versions, because it may rely on the U: drive. However,
that can be fixed later on.
Diffstat (limited to 'atari')
-rwxr-xr-x | atari/findfile.c | 71 | ||||
-rw-r--r-- | atari/osspec.c | 103 |
2 files changed, 50 insertions, 124 deletions
diff --git a/atari/findfile.c b/atari/findfile.c index d4c4c308d..61dc3a292 100755 --- a/atari/findfile.c +++ b/atari/findfile.c @@ -37,6 +37,9 @@ char * local_file_to_url( const char * filename ) { #define BACKSLASH 0x5C char * url; + + LOG(("in: %s", filename)); + if( strlen(filename) <= 2){ return( NULL ); } @@ -45,22 +48,6 @@ char * local_file_to_url( const char * filename ) char * start = (char*)fname_local; strcpy( start, filename ); - /* if path points to unified filesystem, skip that info: */ - if( fname_local[1] == ':' && fname_local[0] == 'U' ){ - start = &fname_local[2]; - } - - /* if we got something like "C:\folder\file.txt", handle that: */ - if( start[1] == ':' ){ - start[1] = (char)tolower(start[0]); - start++; - } - - /* skip leading slash, already included in file scheme: */ - if( start[0] == (char)BACKSLASH || start[0] == '/' ){ - start++; - } - /* convert backslashes: */ for( unsigned int i=0; i<strlen(start); i++ ){ if( start[i] == BACKSLASH ){ @@ -70,11 +57,13 @@ char * local_file_to_url( const char * filename ) // TODO: make file path absolute if it isn't yet. url = malloc( strlen(start) + FILE_SCHEME_PREFIX_LEN + 1); - strcpy( url, FILE_SCHEME_PREFIX ); - strcat( url, start ); + strcpy(url, FILE_SCHEME_PREFIX ); + strcat(url, start ); free(fname_local); + LOG(("out: %s", url)); + return( url ); #undef BACKSLASH } @@ -83,27 +72,11 @@ char * local_file_to_url( const char * filename ) char *path_to_url(const char *path_in) { #define BACKSLASH 0x5C - char * path_ptr=NULL; char * path; - LOG(("path2url in: %s\n", path_in)); - if (*path_in == '/') { - path_in++; /* file: path is are already absolute */ - path = (char*)path_in; - } else { - path = path_ptr = (char*)malloc(PATH_MAX+1); - gemdos_realpath(path_in, path); + LOG(("path2url in: %s\n", path_in)); - if( *path == '/' || *path == BACKSLASH ) { - path++; - } - if( sys_type() != SYS_MINT ){ - if( path[1] == ':' ) { - path[1] = path[0]; - path++; - } - } - } + path = (char*)path_in; int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; char *url = malloc(urllen); @@ -117,8 +90,7 @@ char *path_to_url(const char *path_in) } i++; } - if( path_ptr ) - free( path_ptr ); + LOG(("path2url out: %s\n", url)); return url; #undef BACKSLASH @@ -130,21 +102,22 @@ char *url_to_path(const char *url) char *url_path = curl_unescape(url, 0); char *path; char abspath[PATH_MAX+1]; - LOG(( "url2path in: %s\n", url )); - /* printf( "url2path in: %s\n", url_path ); */ - /* return the absolute path including leading / */ - /* todo: better check for filesystem? */ - if( sys_type() & SYS_MINT ) { - /* it's ok to have relative paths with mint, just strip proto: */ - path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN -1)); + + LOG(( "url2path in: %s (%s)\n", url, url_path )); + + // is the URL relative? + if (url_path[7] == '.') { + // yes, make it absolute... + gemdos_realpath(url_path + (FILE_SCHEME_PREFIX_LEN-1), abspath); + path = strdup(abspath); } else { - /* do not include / within url_path */ - char * tmp = url_path + (FILE_SCHEME_PREFIX_LEN-1); - gemdos_realpath( tmp, (char*)&abspath ); - path = strdup( (char*)&abspath ); + path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN)); } + curl_free(url_path); + LOG(( "url2path out: %s\n", path )); + return path; } diff --git a/atari/osspec.c b/atari/osspec.c index ada1e05c4..5bd7320dc 100644 --- a/atari/osspec.c +++ b/atari/osspec.c @@ -22,7 +22,8 @@ #include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
+#include <string.h> +#include <support.h>
#include <mint/osbind.h>
#include <mint/cookie.h>
@@ -96,86 +97,38 @@ int tos_getcookie(long tag, long * value) }
/*
+ a fixed version of realpath() which returns valid
- paths for TOS which have no root fs. (/ , U: )
+ paths for TOS which have no U: drive
+ */
char * gemdos_realpath(const char * path, char * rpath)
{
char work[PATH_MAX+1];
- char * work_ptr;
- size_t l;
-
- if( rpath == NULL ){
- return( NULL );
- }
- if( sys_type() & SYS_MINT ){
- return( realpath(path, rpath) );
- }
-
- LOG(("gdos rpath in: %s\n", path));
- memset( rpath, 0, PATH_MAX );
-
- /* first, absolutize relative path: */
- if( *path == '.' ){
- char cwd[PATH_MAX+1];
- getcwd((char*)&cwd, PATH_MAX);
- l = strlen( cwd );
- if( cwd[l-1] != 0x5C && cwd[l-1] != '/' ){
- cwd[l] = 0x5C;
- cwd[l+1] = 0;
- l++;
- }
-
- strncpy( (char*)&work, cwd, PATH_MAX );
-
- /* check for path, or maybe just a file name? */
- if( strlen(path) > 2 ) {
- int off = 0;
- if( path[1] == '/' || path[1] == 0x5C ){
- off = 2;
- }
- strncat( (char*)&work, (char*)(path+off), PATH_MAX-l );
- }
- work_ptr = (char*)&work;
- } else {
- work_ptr = (char*)path;
- }
-
- /* handle invalid cwd path */
- /* mintlib produces these on plain TOS systems: */
- if( strncmp( (char*)work_ptr, "/dev/", 5) == 0 ){
- work_ptr += 4;
- }
-
- /* make TOS compatible path, step 1: */
- l = strlen( work_ptr);
- if( l > 1 ){
- if( *work_ptr == '/' || *work_ptr == 0x5C ){
- rpath[0] = work_ptr[1];
- rpath[1] = ':';
- strncat( rpath, &work_ptr[2], PATH_MAX-2 );
- } else {
- strncpy( rpath, work_ptr, PATH_MAX );
- }
-
- /* step 2, perform seperator conversion: */
- l = strlen( rpath );
- rpath[PATH_MAX-1]=0;
- work_ptr = rpath;
- do{
- if( *work_ptr == '/' )
- *work_ptr = 0x5C;
- work_ptr++;
- } while( *work_ptr != 0 );
-
- if( rpath[l-1] == 0x5C || rpath[l-1] == '/' )
- rpath[l-1] = 0;
- } else {
- strncpy( rpath, work_ptr, PATH_MAX );
+ char * r; + +
+ if (rpath == NULL) {
+ return (NULL);
+ } + + // Check if the path is already absolute: + if(path[1] == ':'){ + strcpy(rpath, path); + return(rpath); }
- l = strlen( rpath );
- LOG(("gdos rpath out: %s\n", rpath));
- return( rpath );
+ + LOG(("realpath in: %s\n", path)); + r = realpath(path, work); + if (r != NULL) { + int e = unx2dos((const char *)r, rpath); + LOG(("realpath out: %s\n", rpath));
+ return(rpath); + } + else { + LOG(("realpath out: NULL!\n")); + } + return (NULL);
}
|