mingw support

Fri, 23 Aug 2013 11:04:07 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 23 Aug 2013 11:04:07 +0200
changeset 32
c9d37bb97ea8
parent 31
59cdf7b7316f
child 33
0bbbb0341606

mingw support

Makefile file | annotate | diff | comparison | revisions
dav/config.c file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
dav/utils.c file | annotate | diff | comparison | revisions
dav/utils.h file | annotate | diff | comparison | revisions
--- a/Makefile	Thu Aug 22 14:27:58 2013 +0200
+++ b/Makefile	Fri Aug 23 11:04:07 2013 +0200
@@ -31,7 +31,7 @@
 # available configurations:
 #   gcc
 #   suncc
-#   windows
+#   mingw
 #   osx
 #
 
--- a/dav/config.c	Thu Aug 22 14:27:58 2013 +0200
+++ b/dav/config.c	Fri Aug 23 11:04:07 2013 +0200
@@ -30,7 +30,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <ucx/map.h>
 #include <errno.h>
 #include <libxml/tree.h>
@@ -40,13 +39,19 @@
 
 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
 
+#ifdef _WIN32
+#define ENV_HOME getenv("USERPROFILE")
+#else
+#define ENV_HOME getenv("HOME")
+#endif /* _WIN32 */
+
 static UcxMap *repos;
 static UcxMap *keys;
 
 int check_config_dir() {
-    char *file = util_concat_path(getenv("HOME"), ".dav");
+    char *file = util_concat_path(ENV_HOME, ".dav");
     int ret = 0;
-    if(mkdir(file, S_IRWXU)) {
+    if(util_mkdir(file, S_IRWXU)) {
         if(errno != EEXIST) {
             ret = 1;
         }
@@ -62,7 +67,7 @@
         return;
     }
     
-    char *file = util_concat_path(getenv("HOME"), ".dav/config.xml");
+    char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
     xmlDoc *doc = xmlReadFile(file, NULL, 0);
     if(!doc) {
         doc = xmlNewDoc(BAD_CAST "1.0");
@@ -200,7 +205,7 @@
     if(filename[0] == '/') {
         file = fopen(filename, "r");
     } else {
-        char *path = util_concat_path(getenv("HOME"), ".dav/");
+        char *path = util_concat_path(ENV_HOME, ".dav/");
         char *p2 = util_concat_path(path, filename);
         file = fopen(p2, "r");
         free(path);
--- a/dav/main.c	Thu Aug 22 14:27:58 2013 +0200
+++ b/dav/main.c	Fri Aug 23 11:04:07 2013 +0200
@@ -34,7 +34,6 @@
 #include <time.h>
 #include <libxml/xmlerror.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <ucx/string.h>
 #include <dirent.h>
 
@@ -280,8 +279,13 @@
     struct tm t;
     struct tm n;
     time_t now = time(NULL);
+#ifdef _WIN32
+    memcpy(&t, localtime(&tm), sizeof(struct tm));
+    memcpy(&n, localtime(&now), sizeof(struct tm));
+#else
     localtime_r(&tm, &t);
     localtime_r(&now, &n);
+#endif /* _WIN32 */
     char *str = malloc(16);
     if(t.tm_year == n.tm_year) {
         strftime(str, 16, "%b %d %H:%M", &t);
@@ -521,7 +525,7 @@
         // create directory
         if(outlen != 0) {
             mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
-            int ret = mkdir(out, mode);
+            int ret = util_mkdir(out, mode);
             if(ret != 0 && errno != EEXIST) {
                 return 1;
             }
--- a/dav/utils.c	Thu Aug 22 14:27:58 2013 +0200
+++ b/dav/utils.c	Fri Aug 23 11:04:07 2013 +0200
@@ -120,6 +120,14 @@
     return name;
 }
 
+int util_mkdir(char *path, mode_t mode) {
+#ifdef _WIN32
+    return mkdir(path);
+#else
+    return mkdir(path, mode);
+#endif
+}
+
 char* util_concat_path(char *url_base, char *p) {
     sstr_t base = sstr(url_base);
     sstr_t path;
--- a/dav/utils.h	Thu Aug 22 14:27:58 2013 +0200
+++ b/dav/utils.h	Fri Aug 23 11:04:07 2013 +0200
@@ -32,6 +32,18 @@
 #include <sys/types.h>
 #include <libxml/tree.h>
 #include <ucx/string.h>
+#include <sys/stat.h>
+#ifdef _WIN32
+#include <io.h>
+#define S_IRWXG 070
+#define S_IRGRP 040
+#define S_IWGRP 020
+#define S_IXGRP 010
+#define S_IRWXO  07
+#define S_IROTH  04
+#define S_IWOTH  02
+#define S_IXOTH  01
+#endif /* _WIN32 */
 
 #ifdef	__cplusplus
 extern "C" {
@@ -40,6 +52,8 @@
 time_t util_parse_creationdate(char *str);
 time_t util_parse_lastmodified(char *str);
 
+int util_mkdir(char *path, mode_t mode);
+
 char* util_url_path(char *url);
 char* util_resource_name(char *url);
 char* util_concat_path(char *url_base, char *path);

mercurial