On 9/30/06, Paul Stoeber <[EMAIL PROTECTED]> wrote:
On Fri, 29 Sep 2006 05:30:35 +0000 I wrote:
> Should a userland program be allowed to depend on errno==0 on entry
> to main()?  (At least one in the tree does.)

That claim is unfounded, because usr.bin/head/head.c (which I
failed to mention; apologies) is not an example.

Actually, it is an example, though it's hardly serious.  strtol()
doesn't set errno on success, even when success has the same return
value as failure (LONG_{MAX,MIN}).  So, to demonstrate the problem
requires both an LD_PRELOAD and passing LONG_MAX as the count
argument:

$ gcc -fPIC -o foo.so -shared foo.c
$ LD_PRELOAD=./foo.so head -2147483647 foo.c
head: illegal line count -- 2147483647: Result too large
$ head -2147483647 foo.c
#include <errno.h>

void foo(void) __attribute__ ((constructor));
void foo(void)
{
       errno = ERANGE;
}
$

Your proposed crt0.c change should prevent that.


Philip Guenther

Reply via email to