[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sysval and doc fixes [was: GNU M4 1.4.4b released (beta release)]
From: |
Andreas Büning |
Subject: |
Re: sysval and doc fixes [was: GNU M4 1.4.4b released (beta release)] |
Date: |
Tue, 20 Jun 2006 21:22:32 +0200 |
Eric Blake schrieb:
> > WEXITSTATUS is defined in sys/wait.h as
> > #define WEXITSTATUS(st) ((st) >> 8)
> > but I think it's not intended to be used with system().
>
> What is it for, if not system(), waitpid(), and pclose()? Those three
> functions each return a process's exit status, and POSIX has
> standardized that WEXITSTATUS should grab whatever bits out
> of the exit status make sense as the 8 bits that matter.
pclose() and waitpid(), yes but not system(). system() is Standard C
but even C99 doesn't seem to specify its return value except for
system(NULL), neither does POSIX.1. I did some research, and
http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf says:
[return value of system():] "Information may be returned from the called
program in two ways: through the implementation-defined return value
(in many implementations, the termination status code which is the
argument to the exit function is returned by the implementation to the
caller as the value returned by the system function.), and (most portably)
through data files."
AFAIK, the typical (failure) return value of /bin/sh is 1, so I would
expect that system() may also return 1 which is the case on OS/2.
The return value of system() is just the plain exit code of the called
program.
Best regards,
Andreas