From: Frederic Marchal Date: Thu, 5 Mar 2015 14:26:52 +0000 (+0100) Subject: mkdir is really a mess on MinGW X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a9d0965d388bfd1246bfb2518d87b47a755dde0;p=thirdparty%2Fsarg.git mkdir is really a mess on MinGW mkdir with one argument produces an error as the macro requires two arguments. I couldn't find which macro it is! mkdir with two arguments doesn't work as _mkdir isn't defined without direct.h. _mkdir isn't defined without direct.h and direct.h cannot be included unless NO_OLDNAMES is defined to mask the mkdir macro which conflict with the definition in io.h. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4012d6b..6e35816 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Windows") CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H) CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H) CHECK_INCLUDE_FILE(ws2tcpip.h HAVE_WS2TCPIP_H) + CHECK_INCLUDE_FILE(direct.h HAVE_DIRECT_H) FIND_LIBRARY(WSOCK_LIB NAMES wsock32 DOC "The winsock library") IF(WSOCK_LIB) diff --git a/html.c b/html.c index 958634b..efdede7 100644 --- a/html.c +++ b/html.c @@ -128,7 +128,7 @@ void htmlrel(void) } if (access(warea, R_OK) != 0) { - if (mkdir(warea,0755)) { + if (PortableMkDir(warea,0755)) { debuga(_("Cannot create directory %s - %s\n"),warea,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/include/config.h.in b/include/config.h.in index f4d2d95..9c00b9a 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -51,6 +51,7 @@ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_PCRE_H #cmakedefine HAVE_FNMATCH_H +#cmakedefine HAVE_DIRECT_H #cmakedefine IBERTY_LIB diff --git a/include/defs.h b/include/defs.h index 39c1597..8156606 100755 --- a/include/defs.h +++ b/include/defs.h @@ -391,6 +391,7 @@ void version(void); int vercode(const char *code); void load_excludecodes(const char *ExcludeCodes); void free_excludecodes(void); +int PortableMkDir(const char *path,int mode); void my_mkdir(const char *name); int testvaliduserchar(const char *user); char *strlow(char *string); diff --git a/index.c b/index.c index 4fa7fca..675d167 100644 --- a/index.c +++ b/index.c @@ -874,7 +874,7 @@ static void file_index_to_date_index(const char *entry) m2=conv_month(sm2); ndirlen=sprintf(newdir,"%s%04d",outdir,y1); if (access(newdir, R_OK) != 0) { - if (mkdir(newdir,0755)) { + if (PortableMkDir(newdir,0755)) { debuga(_("Cannot create directory %s - %s\n"),newdir,strerror(errno)); exit(EXIT_FAILURE); } @@ -882,7 +882,7 @@ static void file_index_to_date_index(const char *entry) if(m1 != m2) ndirlen+=sprintf(newdir+ndirlen,"/%02d-%02d",m1,m2); else ndirlen+=sprintf(newdir+ndirlen,"/%02d",m1); if (access(newdir, R_OK) != 0) { - if (mkdir(newdir,0755)) { + if (PortableMkDir(newdir,0755)) { debuga(_("Cannot create directory %s - %s\n"),newdir,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/util.c b/util.c index 7f6990c..9955e62 100644 --- a/util.c +++ b/util.c @@ -30,6 +30,11 @@ #include "include/conf.h" #include "include/defs.h" +#if defined(__MINGW32__) && defined(HAVE_DIRECT_H) +#define NO_OLDNAMES 1 +#include +#endif + #if defined(HAVE_BACKTRACE) #define USE_GETWORD_BACKTRACE 1 #else @@ -388,6 +393,17 @@ int is_absolute(const char *path) return(0); } +int PortableMkDir(const char *path,int mode) +{ +#if defined(__linux__) + int mkerror=mkdir(path,mode); +#else //mingw + (void)mode; + int mkerror=_mkdir(path); +#endif + return(mkerror); +} + void my_mkdir(const char *name) { char w0[MAXLEN]; @@ -408,7 +424,7 @@ void my_mkdir(const char *name) if (chars>0 && name[i] == '/') { w0[i] = '\0'; if (access(w0, R_OK) != 0) { - if (mkdir(w0,0755)) { + if (PortableMkDir(w0,0755)) { debuga(_("Cannot create directory %s - %s\n"),w0,strerror(errno)); exit(EXIT_FAILURE); } @@ -419,7 +435,7 @@ void my_mkdir(const char *name) } if (access(name, R_OK) != 0) { - if (mkdir(name,0755)) { + if (PortableMkDir(name,0755)) { debuga(_("Cannot create directory %s - %s\n"),name,strerror(errno)); exit(EXIT_FAILURE); } @@ -1048,7 +1064,7 @@ static void copy_images(void) exit(EXIT_FAILURE); } if (access(images,R_OK)!=0) { - if (mkdir(images,0755)) { + if (PortableMkDir(images,0755)) { debuga(_("Cannot create directory %s - %s\n"),images,strerror(errno)); exit(EXIT_FAILURE); }