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: wilde@146: char * wilde@146: port_realpath(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: }