summaryrefslogtreecommitdiff
path: root/atari/osspec.c
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2013-10-26 17:24:09 +0200
committerOle Loots <ole@monochrom.net>2013-10-26 17:24:09 +0200
commit77129038ee8aa8ccdf8f4a264fd1189459e69326 (patch)
treedacbbc96fb24b913b9daa57626b5ce253bf993d5 /atari/osspec.c
parent164571aa98871d47f2efda842d75507f9bd03150 (diff)
downloadnetsurf-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/osspec.c')
-rw-r--r--atari/osspec.c103
1 files changed, 28 insertions, 75 deletions
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);
}