From 5f62669c20c3c79d5bb3b427a996533e1e376b0c Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Mon, 10 Jan 2011 23:51:52 +0000 Subject: Added realpath() for plain TOS systems. svn path=/trunk/netsurf/; revision=11282 --- atari/findfile.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) mode change 100644 => 100755 atari/findfile.c (limited to 'atari/findfile.c') diff --git a/atari/findfile.c b/atari/findfile.c old mode 100644 new mode 100755 index befe0eeb5..995865c9f --- a/atari/findfile.c +++ b/atari/findfile.c @@ -57,6 +57,59 @@ char *url_to_path(const char *url) return path; } + +#ifdef PLAIN_TOS +#undef realpath +#undef access +#define access(f,m) (0) +#define PATH_SEP '/' +char * realpath(const char * path, char * rpath) +{ + size_t l; + size_t i; + char old; + char new = PATH_SEP; + + if( rpath == NULL ){ + return( NULL ); + } + + if( PATH_SEP == '/') { + /* replace '\' with / */ + old = 0x2F; /* / */ + } else { + /* replace '/' with \ */ + old = '/'; + } + + if( path[0] == 0x2F || path[0] == '/' ){ + strcpy(rpath, "U:"); + strcat(rpath, path); + } + else if( path[0] == '.') { + char cwd[PATH_MAX]; + getcwd((char*)&cwd, PATH_MAX); + strcpy(rpath, (char*)&cwd); + if( (path[1] == '/' || path[1] == 0x27 ) ) { + strcat(rpath, &path[1]); + } else { + strcat(rpath, "/"); + strcat(rpath, path); + } + } else { + strcpy(rpath, path); + } + /* convert path seperator to configured value: */ + l = strlen(rpath); + for( i = 0; i