aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ wilde@146: #include "portpath.h" wilde@146: wilde@146: #include wilde@146: #include wilde@146: #include wilde@146: #include wilde@168: #include wilde@168: #include wilde@168: #include wilde@146: wilde@146: wilde@146: char * wilde@146: port_dirname(char *path) wilde@146: { wilde@146: #ifndef _WIN32 wilde@146: return dirname(path); wilde@146: #else wilde@164: char drive[_MAX_DRIVE]; wilde@164: char dir[_MAX_DIR]; wilde@164: _splitpath(path, drive, dir, NULL, NULL); wilde@170: size_t dlen = strlen(dir); wilde@170: if ((dlen > 0) && wilde@170: ((dir[dlen-1] == '/') || (dir[dlen-1] == '\\'))) wilde@170: dir[dlen-1] = '\0'; wilde@164: /* We assume: drive + dir is shorter than wilde@164: * drive + dir + fname + ext */ wilde@164: sprintf(path, "%s%s", drive, dir); wilde@164: return path; wilde@146: #endif wilde@146: } wilde@146: andre@975: bool andre@975: port_mkdir(const char *path) andre@975: { andre@975: #ifndef _WIN32 andre@975: return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0; andre@975: #else andre@975: /* TODO */ andre@975: printf("Should make path: %s\n", path); andre@975: return false; andre@975: #endif andre@975: } andre@975: wilde@146: char * andre@975: port_realpath(const char *path) wilde@146: { wilde@146: #ifndef _WIN32 wilde@146: return realpath(path, NULL); wilde@146: #else wilde@169: char *fp = _fullpath(NULL, path, 0); wilde@169: if (port_fileexits(fp)) wilde@169: return fp; wilde@169: else wilde@169: return NULL; wilde@146: #endif wilde@146: } wilde@168: wilde@168: bool wilde@168: port_fileexits(char *path) wilde@168: { wilde@168: int ret; wilde@168: #ifndef _WIN32 wilde@168: struct stat sb; wilde@168: ret = stat(path, &sb); wilde@168: #else wilde@168: struct _stat sb; wilde@168: ret = _stat(path, &sb); wilde@168: #endif wilde@168: wilde@168: if (ret == 0) wilde@168: return true; wilde@168: else wilde@168: return false; wilde@168: } wilde@176: wilde@176: bool wilde@176: port_isdir(char *path) wilde@176: { wilde@176: int ret; wilde@176: #ifndef _WIN32 wilde@176: struct stat sb; wilde@176: ret = stat(path, &sb); wilde@176: #else wilde@176: struct _stat sb; wilde@176: ret = _stat(path, &sb); wilde@176: #endif wilde@176: wilde@176: if ((ret == 0) && S_ISDIR(sb.st_mode)) wilde@176: return true; wilde@176: else wilde@176: return false; wilde@176: }