>From 624d15bd5d2d06035abc17415127a7cf37b5f981 Mon Sep 17 00:00:00 2001
From: Stepan Kasal <ka...@ucw.cz>
Date: Thu, 5 Jun 2014 09:17:17 +0200

mingw.c defines several wrapper functions, e.g., mingw_unlink().
These wrappers are deployed by macros like this:
        #define unlink mingw_unlink
The mingw_foo() wrapper often calls the original function, so it has
to be #undef'ed at that place.

But for the rest of mingw.c, if the function is used, the user probably
meant the fixed functionality.  So it is safer to redefine the macro
back.

Nonetheless, it is preferable to call mingw_foo() explicitly throughout
mingw.c itself.

Signed-off-by: Stepan Kasal <ka...@ucw.cz>
---
 compat/mingw.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..ee83211 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)
               ret = unlink(pathname);
        return ret;
 }
+#define unlink mingw_unlink
 
 static int is_dir_empty(const char *path)
 {
@@ -279,6 +280,7 @@ int mingw_rmdir(const char *pathname)
               ret = rmdir(pathname);
        return ret;
 }
+#define rmdir mingw_rmdir
 
 #undef open
 int mingw_open (const char *filename, int oflags, ...)
@@ -303,6 +305,7 @@ int mingw_open (const char *filename, int oflags, ...)
        }
        return fd;
 }
+#define open mingw_open
 
 static BOOL WINAPI ctrl_ignore(DWORD type)
 {
@@ -328,6 +331,7 @@ int mingw_fgetc(FILE *stream)
        SetConsoleCtrlHandler(ctrl_ignore, FALSE);
        return ch;
 }
+#define fgetc mingw_fgetc
 
 #undef fopen
 FILE *mingw_fopen (const char *filename, const char *otype)
@@ -336,6 +340,7 @@ FILE *mingw_fopen (const char *filename, const char *otype)
                filename = "nul";
        return fopen(filename, otype);
 }
+#define fopen mingw_fopen
 
 #undef freopen
 FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
@@ -344,6 +349,7 @@ FILE *mingw_freopen (const char *filename, const char 
*otype, FILE *stream)
                filename = "nul";
        return freopen(filename, otype, stream);
 }
+#define freopen mingw_freopen
 
 #undef fflush
 int mingw_fflush(FILE *stream)
@@ -366,6 +372,7 @@ int mingw_fflush(FILE *stream)
 
        return ret;
 }
+#define fflush mingw_fflush
 
 /*
  * The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
@@ -525,7 +532,7 @@ int mingw_utime (const char *file_name, const struct 
utimbuf *times)
                SetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY);
        }
 
-       if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) {
+       if ((fh = mingw_open(file_name, O_RDWR | O_BINARY)) < 0) {
                rc = -1;
                goto revert_attrs;
        }
@@ -564,7 +571,7 @@ int mkstemp(char *template)
        char *filename = mktemp(template);
        if (filename == NULL)
                return -1;
-       return open(filename, O_RDWR | O_CREAT, 0600);
+       return mingw_open(filename, O_RDWR | O_CREAT, 0600);
 }
 
 int gettimeofday(struct timeval *tv, void *tz)
@@ -629,6 +636,7 @@ char *mingw_getcwd(char *pointer, int len)
                        pointer[i] = '/';
        return ret;
 }
+#define getcwd mingw_getcwd
 
 /*
  * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
@@ -700,7 +708,7 @@ static const char *parse_interpreter(const char *cmd)
        if (n >= 4 && !strcasecmp(cmd+n-4, ".exe"))
                return NULL;
 
-       fd = open(cmd, O_RDONLY);
+       fd = mingw_open(cmd, O_RDONLY);
        if (fd < 0)
                return NULL;
        n = read(fd, buf, sizeof(buf)-1);
@@ -1183,6 +1191,7 @@ char *mingw_getenv(const char *name)
        }
        return result;
 }
+#define getenv mingw_getenv
 
 /*
  * Note, this isn't a complete replacement for getaddrinfo. It assumes
@@ -1199,7 +1208,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, 
const char *service,
        struct sockaddr_in *sin;
 
        if (node) {
-               h = gethostbyname(node);
+               h = mingw_gethostbyname(node);
                if (!h)
                        return WSAGetLastError();
        }
@@ -1366,6 +1375,7 @@ int mingw_gethostname(char *name, int namelen)
     ensure_socket_initialization();
     return gethostname(name, namelen);
 }
+#define gethostname mingw_gethostname
 
 #undef gethostbyname
 struct hostent *mingw_gethostbyname(const char *host)
@@ -1373,6 +1383,7 @@ struct hostent *mingw_gethostbyname(const char *host)
        ensure_socket_initialization();
        return gethostbyname(host);
 }
+#define gethostbyname mingw_gethostbyname
 
 void mingw_freeaddrinfo(struct addrinfo *res)
 {
@@ -1429,6 +1440,7 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t 
sz)
        SOCKET s = (SOCKET)_get_osfhandle(sockfd);
        return connect(s, sa, sz);
 }
+#define connect mingw_connect
 
 #undef bind
 int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
@@ -1436,6 +1448,7 @@ int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
        SOCKET s = (SOCKET)_get_osfhandle(sockfd);
        return bind(s, sa, sz);
 }
+#define bind mingw_bind
 
 #undef setsockopt
 int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int 
optlen)
@@ -1443,6 +1456,7 @@ int mingw_setsockopt(int sockfd, int lvl, int optname, 
void *optval, int optlen)
        SOCKET s = (SOCKET)_get_osfhandle(sockfd);
        return setsockopt(s, lvl, optname, (const char*)optval, optlen);
 }
+#define setsockopt mingw_setsockopt
 
 #undef shutdown
 int mingw_shutdown(int sockfd, int how)
@@ -1450,6 +1464,7 @@ int mingw_shutdown(int sockfd, int how)
        SOCKET s = (SOCKET)_get_osfhandle(sockfd);
        return shutdown(s, how);
 }
+#define shutdown mingw_shutdown
 
 #undef listen
 int mingw_listen(int sockfd, int backlog)
@@ -1457,6 +1472,7 @@ int mingw_listen(int sockfd, int backlog)
        SOCKET s = (SOCKET)_get_osfhandle(sockfd);
        return listen(s, backlog);
 }
+#define listen mingw_listen
 
 #undef accept
 int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
@@ -1475,6 +1491,7 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, 
socklen_t *sz)
        }
        return sockfd2;
 }
+#define accept mingw_accept
 
 #undef rename
 int mingw_rename(const char *pold, const char *pnew)
@@ -1530,6 +1547,7 @@ repeat:
        errno = EACCES;
        return -1;
 }
+#define rename mingw_rename
 
 /*
  * Note that this doesn't return the actual pagesize, but
@@ -1684,6 +1702,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
 
        return old;
 }
+#define signal mingw_signal
 
 #undef raise
 int mingw_raise(int sig)
@@ -1709,6 +1728,7 @@ int mingw_raise(int sig)
                return raise(sig);
        }
 }
+#define raise mingw_raise
 
 
 static const char *make_backslash_path(const char *path)
-- 
2.0.0.9635.g0be03cb

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to