# HG changeset patch # User Mike Becker # Date 1377248647 -7200 # Node ID c9d37bb97ea850cf45e8f2b364d951eb334f39fc # Parent 59cdf7b7316f93bced306550de0bb15d1ca3bbfa mingw support diff -r 59cdf7b7316f -r c9d37bb97ea8 Makefile --- 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 # diff -r 59cdf7b7316f -r c9d37bb97ea8 dav/config.c --- 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 #include #include -#include #include #include #include @@ -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); diff -r 59cdf7b7316f -r c9d37bb97ea8 dav/main.c --- 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 #include #include -#include #include #include @@ -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; } diff -r 59cdf7b7316f -r c9d37bb97ea8 dav/utils.c --- 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; diff -r 59cdf7b7316f -r c9d37bb97ea8 dav/utils.h --- 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 #include #include +#include +#ifdef _WIN32 +#include +#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);