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.

The question remains unsettled and has no immediate importance.

Consider this patch, which would have to be done similarly on
the other platforms.

Index: src/lib/csu/i386/crt0.c
===================================================================
RCS file: /cvs/src/lib/csu/i386/crt0.c,v
retrieving revision 1.13
diff -u -r1.13 crt0.c
--- src/lib/csu/i386/crt0.c     4 Aug 2005 16:33:05 -0000       1.13
+++ src/lib/csu/i386/crt0.c     30 Sep 2006 11:08:36 -0000
@@ -35,6 +35,7 @@
 #include <sys/param.h>
 #include <sys/exec.h>
 #include <stdlib.h>
+#include <errno.h>
 
 static char    *_strrchr(char *, char);
 
@@ -96,6 +97,7 @@
 
        __init();
 
+       errno = 0;
        exit(main(argc, argv, environ));
 }

Reply via email to