]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
mkdir is really a mess on MinGW
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Mar 2015 14:26:52 +0000 (15:26 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Mar 2015 14:26:52 +0000 (15:26 +0100)
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.

CMakeLists.txt
html.c
include/config.h.in
include/defs.h
index.c
util.c

index 4012d6b1e02a73c546adb7b25a0dccd09665b2b8..6e35816e916d78be0e9ad3ecfb03d8d439c6dd98 100755 (executable)
@@ -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 958634b8980621f335708f85e973feef99d41ff9..efdede7005e6179b02b847001b17fc4294898d5d 100644 (file)
--- 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);
                        }
index f4d2d9598cc9cea07790f7478fd0cba97e38aa80..9c00b9ad984154cbc49b76b263747ef18840735d 100644 (file)
@@ -51,6 +51,7 @@
 #cmakedefine HAVE_FCNTL_H
 #cmakedefine HAVE_PCRE_H
 #cmakedefine HAVE_FNMATCH_H
+#cmakedefine HAVE_DIRECT_H
 
 #cmakedefine IBERTY_LIB
 
index 39c15971f7484befca58584daa765d1e42b2d125..8156606995eee5ab96be9c6f5f116da6b76c08ec 100755 (executable)
@@ -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 4fa7fca325994b1afb1e0d675872d3d120b822d3..675d16754bbf3628a90b74cb69d7b81757f93e1f 100644 (file)
--- 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 7f6990cbb7e7bc4185d4de232b3a7f6a02fe7ff9..9955e62271f3bf987c8f89c8b6afb3e418980499 100644 (file)
--- a/util.c
+++ b/util.c
 #include "include/conf.h"
 #include "include/defs.h"
 
+#if defined(__MINGW32__) && defined(HAVE_DIRECT_H)
+#define NO_OLDNAMES 1
+#include <direct.h>
+#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);
                }