summaryrefslogtreecommitdiff
path: root/atari/osspec.c
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2011-04-23 20:09:24 +0000
committerOle Loots <ole@monochrom.net>2011-04-23 20:09:24 +0000
commit45778bbb369e73bc0bc3cabadaabd91560a748e2 (patch)
tree28edf125f507554bc112c88d129847dc0150eff8 /atari/osspec.c
parent8d2bb4bd3a5eacbc355fd7ce98c8865f0bcb44e0 (diff)
downloadnetsurf-45778bbb369e73bc0bc3cabadaabd91560a748e2.tar.gz
netsurf-45778bbb369e73bc0bc3cabadaabd91560a748e2.tar.bz2
Improved path conversion for DOS Filesystems.
svn path=/trunk/netsurf/; revision=12236
Diffstat (limited to 'atari/osspec.c')
-rw-r--r--atari/osspec.c109
1 files changed, 85 insertions, 24 deletions
diff --git a/atari/osspec.c b/atari/osspec.c
index 4f412a33f..a67e6f164 100644
--- a/atari/osspec.c
+++ b/atari/osspec.c
@@ -42,6 +42,7 @@ unsigned short _systype (void)
_systype_v |= SYS_XAAES;
}
}
+ LOG(("Detected OS: %d\n", _systype_v ));
return _systype_v;
}
@@ -104,32 +105,92 @@ int tos_getcookie(long tag, long * value)
return( C_NOTFOUND );
}
-/* convert nonsense getcwd path (returned by mintlib getcwd on plain TOS) */
-void fix_path(char * path)
-{
- char npath[PATH_MAX];
- /* only apply fix to paths that contain /dev/ */
- if( strlen(path) < 6 ){
- return;
- }
- if( strncmp(path, "/dev/", 5) != 0 ) {
- /* path is okay, nothing to fix: */
- return;
- }
- strncpy((char*)&npath, path, PATH_MAX);
- npath[0] = path[5];
- npath[1] = ':';
- npath[2] = 0;
- strcat((char*)&npath, &path[6]);
- strcpy(path, (char*)&npath);
- LOG(("fixed path: %s\n", path ));
-}
-
/*
a fixed version of realpath() which returns valid
paths for TOS which have no root fs. (/ , U: )
*/
-char * gdos_realpath(const char * path, char * rpath)
+
+char * gemdos_realpath(const char * path, char * rpath)
+{
+ char work[PATH_MAX+1];
+ char * work_ptr;
+ size_t l;
+
+ printf("gdos rpath in: %s\n", path);
+
+ if( rpath == NULL ){
+ return( NULL );
+ }
+ if( sys_type() & SYS_MINT ){
+ return( realpath(path, rpath) );
+ }
+
+ 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 {
+ strcpy( rpath, work_ptr );
+ }
+ l = strlen( rpath );
+ printf("gdos rpath out: %s\n", rpath);
+ return( rpath );
+}
+
+char * gemdos_realpathX(const char * path, char * rpath)
{
size_t l;
size_t i;
@@ -141,12 +202,12 @@ char * gdos_realpath(const char * path, char * rpath)
if( sys_type() & SYS_MINT ){
return( realpath(path, rpath) );
}
-
+
if( path[0] != '/' && path[0] != 0x5c && path[1] != ':') {
/* it is not an absolute path */
char cwd[PATH_MAX];
getcwd((char*)&cwd, PATH_MAX);
- fix_path((char*)&cwd);
+ //fix_path((char*)&cwd);
strcpy(rpath, (char*)&cwd);
l = strlen(rpath);
/* append path seperator if needed: */