comparison 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
comparison
equal deleted inserted replaced
187:0c06a608e15f 188:a3bde2aaabd9
2 2
3 #include <libgen.h> 3 #include <libgen.h>
4 #include <limits.h> 4 #include <limits.h>
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <sys/stat.h>
8 #include <sys/types.h>
9 #include <unistd.h>
7 10
8 11
9 char * 12 char *
10 port_dirname(char *path) 13 port_dirname(char *path)
11 { 14 {
12 #ifndef _WIN32 15 #ifndef _WIN32
13 return dirname(path); 16 return dirname(path);
14 #else 17 #else
15 fprintf(stderr, "Windows Suport missing!"); 18 char drive[_MAX_DRIVE];
16 abort(); 19 char dir[_MAX_DIR];
20 _splitpath(path, drive, dir, NULL, NULL);
21 size_t dlen = strlen(dir);
22 if ((dlen > 0) &&
23 ((dir[dlen-1] == '/') || (dir[dlen-1] == '\\')))
24 dir[dlen-1] = '\0';
25 /* We assume: drive + dir is shorter than
26 * drive + dir + fname + ext */
27 sprintf(path, "%s%s", drive, dir);
28 return path;
17 #endif 29 #endif
18
19 } 30 }
20 31
21 char * 32 char *
22 port_realpath(char *path) 33 port_realpath(char *path)
23 { 34 {
24 #ifndef _WIN32 35 #ifndef _WIN32
25 return realpath(path, NULL); 36 return realpath(path, NULL);
26 #else 37 #else
27 fprintf(stderr, "Windows Suport missing!"); 38 char *fp = _fullpath(NULL, path, 0);
28 abort(); 39 if (port_fileexits(fp))
40 return fp;
41 else
42 return NULL;
29 #endif 43 #endif
30 } 44 }
45
46 bool
47 port_fileexits(char *path)
48 {
49 int ret;
50 #ifndef _WIN32
51 struct stat sb;
52 ret = stat(path, &sb);
53 #else
54 struct _stat sb;
55 ret = _stat(path, &sb);
56 #endif
57
58 if (ret == 0)
59 return true;
60 else
61 return false;
62 }
63
64 bool
65 port_isdir(char *path)
66 {
67 int ret;
68 #ifndef _WIN32
69 struct stat sb;
70 ret = stat(path, &sb);
71 #else
72 struct _stat sb;
73 ret = _stat(path, &sb);
74 #endif
75
76 if ((ret == 0) && S_ISDIR(sb.st_mode))
77 return true;
78 else
79 return false;
80 }

http://wald.intevation.org/projects/trustbridge/