This is the mail archive of the
mailing list for the Cygwin project.
Re: Fw: 1.5.11 bug in WEXITSTATUS() macro (wait.h)
- From: Christopher Faylor <cgf-no-personal-reply-please at cygwin dot com>
- To: cygwin at cygwin dot com
- Date: Sat, 25 Sep 2004 15:20:40 -0400
- Subject: Re: Fw: 1.5.11 bug in WEXITSTATUS() macro (wait.h)
- References: <00f001c4a32f$d724a570$0200000a@donpedro>
- Reply-to: cygwin at cygwin dot com
On Sat, Sep 25, 2004 at 08:45:33PM +0200, Peter Dons Tychsen wrote:
>The WEXITSTATUS is a bit buggy. (wait.h)
>The macro extracts information gained from a call to waitpid() (and others).
>The information it extracts is the status of the completed process (8 bit
>The problem is that the macro does not cast the value to a signed integer
>(like other systems do), which can cause the value to be incorrectly
>interpreted (breaks some programs).
>The following fails:
>// Wait for processes to complete
>if(waitpid(pid, &status, 0) == pid)
> // Check return value for failure (-1)
> if(WEXITSTATUS(status) == -1)
> /* We will never get here, as the macro returns 255 if the process
>exited with -1 */
Did you try this on linux?
I wrote the following simple test case (tm), (R), (C) and it does not
print a negative number.
main (int argc, char **argv)
int pid = fork ();
int *zero = 0;
if (argc > 1)
*zero = 1; // boom
if (waitpid(pid, &status, 0) == pid)
if (WEXITSTATUS(status) == -1)
puts ("it is negative");
puts ("it is not negative");
printf ("%d\n", WEXITSTATUS(status));
The reason for this is that the definition of WEXITSTATUS on linux is this:
#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
which would not return a negative number.
The linux man page also has this to say:
evaluates to the least significant eight bits of the return code
of the child which terminated, which may have been set as the
argument to a call to exit() or _exit() or as the argument for a
return statement in the main program. This macro can only be
evaluated if WIFEXITED returned true.
So, it seems like if there is a problem with cygwin it is in the fact
that there is no assurance that only eight bits are being returned.
In short, I don't see how this could be a bug.
Christopher Faylor spammer? -> email@example.com
Cygwin Co-Project Leader firstname.lastname@example.org
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html