Mercurial > trustbridge
diff common/portpath.c @ 188:a3bde2aaabd9
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 09:12:10 +0100 |
parents | 70d627e9e801 |
children | 17e1c8f37d72 |
line wrap: on
line diff
--- a/common/portpath.c Wed Mar 26 09:10:46 2014 +0100 +++ b/common/portpath.c Wed Mar 26 09:12:10 2014 +0100 @@ -4,6 +4,9 @@ #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> char * @@ -12,10 +15,18 @@ #ifndef _WIN32 return dirname(path); #else - fprintf(stderr, "Windows Suport missing!"); - abort(); + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + _splitpath(path, drive, dir, NULL, NULL); + size_t dlen = strlen(dir); + if ((dlen > 0) && + ((dir[dlen-1] == '/') || (dir[dlen-1] == '\\'))) + dir[dlen-1] = '\0'; + /* We assume: drive + dir is shorter than + * drive + dir + fname + ext */ + sprintf(path, "%s%s", drive, dir); + return path; #endif - } char * @@ -24,7 +35,46 @@ #ifndef _WIN32 return realpath(path, NULL); #else - fprintf(stderr, "Windows Suport missing!"); - abort(); + char *fp = _fullpath(NULL, path, 0); + if (port_fileexits(fp)) + return fp; + else + return NULL; #endif } + +bool +port_fileexits(char *path) +{ + int ret; +#ifndef _WIN32 + struct stat sb; + ret = stat(path, &sb); +#else + struct _stat sb; + ret = _stat(path, &sb); +#endif + + if (ret == 0) + return true; + else + return false; +} + +bool +port_isdir(char *path) +{ + int ret; +#ifndef _WIN32 + struct stat sb; + ret = stat(path, &sb); +#else + struct _stat sb; + ret = _stat(path, &sb); +#endif + + if ((ret == 0) && S_ISDIR(sb.st_mode)) + return true; + else + return false; +}