Mercurial > trustbridge > trustbridge
view common/portpath.c @ 169:701b7036c5dc
Windows implementation of port_realpath: NULL if file does not exist.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Tue, 25 Mar 2014 13:20:23 +0100 |
parents | f100861dad8f |
children | 3343ddf43f42 |
line wrap: on
line source
#include "portpath.h" #include <libgen.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> char * port_dirname(char *path) { #ifndef _WIN32 return dirname(path); #else char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; _splitpath(path, drive, dir, NULL, NULL); /* We assume: drive + dir is shorter than * drive + dir + fname + ext */ sprintf(path, "%s%s", drive, dir); return path; #endif } char * port_realpath(char *path) { #ifndef _WIN32 return realpath(path, NULL); #else 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; }