git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stepan Kasal <kasal@ucw.cz>
To: Karsten Blees <karsten.blees@gmail.com>
Cc: Johannes Sixt <j6t@kdbg.org>,
	GIT Mailing-list <git@vger.kernel.org>,
	msysGit <msysgit@googlegroups.com>
Subject: [PATCH v2] mingw: redefine the wrapper macro after the corresponding function
Date: Fri, 6 Jun 2014 10:41:22 +0200	[thread overview]
Message-ID: <20140606084122.GC1303@camelia.ucw.cz> (raw)
In-Reply-To: <20140606083233.GB1303@camelia.ucw.cz>

>From 624d15bd5d2d06035abc17415127a7cf37b5f981 Mon Sep 17 00:00:00 2001
From: Stepan Kasal <kasal@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 <kasal@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

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2014-06-06  8:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05  8:05 [PATCH] mingw: redefine the wrapper macro after the corresponding function Stepan Kasal
2014-06-05 14:51 ` Karsten Blees
2014-06-05 15:13   ` [msysGit] " Stepan Kasal
2014-06-05 22:12     ` Karsten Blees
2014-06-05 16:56 ` [msysGit] " Johannes Sixt
2014-06-05 22:00   ` Karsten Blees
2014-06-06  8:32     ` Stepan Kasal
2014-06-06  8:41       ` Stepan Kasal [this message]
2014-06-06  9:43       ` Karsten Blees
2014-06-06 11:10         ` Stepan Kasal
2014-06-06 18:20           ` Karsten Blees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140606084122.GC1303@camelia.ucw.cz \
    --to=kasal@ucw.cz \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=karsten.blees@gmail.com \
    --cc=msysgit@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).