git: 3131e7a41725 - stable/14 - csu: C standard requires errno on main() entry
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 29 Jun 2025 00:30:02 UTC
The branch stable/14 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=3131e7a41725acd53d7612da8cb9de278f81e244
commit 3131e7a41725acd53d7612da8cb9de278f81e244
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-06-23 23:46:43 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-06-29 00:29:12 +0000
csu: C standard requires errno on main() entry
(cherry picked from commit 64584008139f73b07fa7c7979c41780be458b8cc)
---
lib/libc/csu/libc_start1.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lib/libc/csu/libc_start1.c b/lib/libc/csu/libc_start1.c
index f0e708e405ce..a1887a2c28c0 100644
--- a/lib/libc/csu/libc_start1.c
+++ b/lib/libc/csu/libc_start1.c
@@ -28,6 +28,7 @@
#include <sys/param.h>
#include <sys/elf.h>
#include <sys/elf_common.h>
+#include <errno.h>
#include <stdlib.h>
#include "libc_private.h"
@@ -154,6 +155,13 @@ __libc_start1(int argc, char *argv[], char *env[], void (*cleanup)(void),
}
handle_static_init(argc, argv, env);
+
+ /*
+ * C17 4.3 paragraph 3:
+ * The value of errno in the initial thread is zero at program
+ * startup.
+ */
+ errno = 0;
exit(mainX(argc, argv, env));
}
@@ -182,5 +190,6 @@ __libc_start1_gcrt(int argc, char *argv[], char *env[],
monstartup(eprolp, etextp);
handle_static_init(argc, argv, env);
+ errno = 0;
exit(mainX(argc, argv, env));
}