git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	GIT Mailing-list <git@vger.kernel.org>
Subject: [PATCH] compat/mingw.[ch]: Change return type of exec functions to int
Date: Thu, 05 Apr 2012 18:48:46 +0100	[thread overview]
Message-ID: <4F7DDAFE.1060902@ramsay1.demon.co.uk> (raw)


The POSIX standard specifies a return type of int for all six exec
functions. In addition, all exec functions return -1 on error, and
simply do not return on success. However, the current emulation of
the exec functions on mingw are declared with a void return type.

This would cause a problem should any code attempt to call the
exec function in a non-void context. In particular, if an exec
function were used in a conditional it would fail to compile.

In order to improve the fidelity of the emulation, we change the
return type of the mingw_execv[p] functions to int and return -1
on error.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---

Hi Jeff,

Since commit b0984f82 ("run-command: treat inaccessible directories
as ENOENT", 30-03-2012), the mingw build fails as follows:

        CC run-command.o
    run-command.c: In function 'sane_execvp':
    run-command.c:124: error: invalid use of void expression
    make: *** [run-command.o] Error 1

My first reaction was to simply remove the conditional since, if execvp()
returns at all, the result will always be -1 and so the condition will
always be false. ie. the conditional is pointless.

However, I found the incorrect return type of the mingw_execv[p]() to be
a gratuitous incompatibility, so ... :-P

Could you (or Junio?) add this patch prior to your patch on this branch ?
Thanks in advance!

I will let you decide if you want to remove the conditional as well ...

ATB,
Ramsay Jones

 compat/mingw.c |    6 ++++--
 compat/mingw.h |    4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0ac487..afc892d 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1003,7 +1003,7 @@ static void mingw_execve(const char *cmd, char *const *argv, char *const *env)
 	}
 }
 
-void mingw_execvp(const char *cmd, char *const *argv)
+int mingw_execvp(const char *cmd, char *const *argv)
 {
 	char **path = get_path_split();
 	char *prog = path_lookup(cmd, path, 0);
@@ -1015,11 +1015,13 @@ void mingw_execvp(const char *cmd, char *const *argv)
 		errno = ENOENT;
 
 	free_path_split(path);
+	return -1;
 }
 
-void mingw_execv(const char *cmd, char *const *argv)
+int mingw_execv(const char *cmd, char *const *argv)
 {
 	mingw_execve(cmd, argv, environ);
+	return -1;
 }
 
 int mingw_kill(pid_t pid, int sig)
diff --git a/compat/mingw.h b/compat/mingw.h
index 0ff1e04..ef5b150 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -274,9 +274,9 @@ int mingw_utime(const char *file_name, const struct utimbuf *times);
 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
 		     const char *dir,
 		     int fhin, int fhout, int fherr);
-void mingw_execvp(const char *cmd, char *const *argv);
+int mingw_execvp(const char *cmd, char *const *argv);
 #define execvp mingw_execvp
-void mingw_execv(const char *cmd, char *const *argv);
+int mingw_execv(const char *cmd, char *const *argv);
 #define execv mingw_execv
 
 static inline unsigned int git_ntohl(unsigned int x)
-- 
1.7.9

             reply	other threads:[~2012-04-05 17:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-05 17:48 Ramsay Jones [this message]
2012-04-05 18:16 ` [PATCH] compat/mingw.[ch]: Change return type of exec functions to int Jonathan Nieder
2012-04-05 22:06   ` Jeff King
2012-04-05 22:34     ` Jonathan Nieder
2012-04-06  0:24       ` Jeff King
2012-04-06  0:42         ` Jonathan Nieder
2012-04-06  0:44           ` Jeff King
2012-04-06  1:00             ` Junio C Hamano

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=4F7DDAFE.1060902@ramsay1.demon.co.uk \
    --to=ramsay@ramsay1.demon.co.uk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).