* lib/progname.c: Don’t include stdio.h or stdlib.h.
(set_program_name): Omit dynamic check that (with current glibc
optimization) drags in fwrite even when unlocked I/O is wanted.
The check was not all that useful in practice and we now have a
static one anyway (which admittedly is not that useful either).
Prefer memcmp to strncmp when equivalent, for clarity.
* lib/progname.h: Include arg-nonnull.h and declare
set_program_name with _GL_ARG_NONNULL.
* modules/progname (Depends-on): Add snippet/arg-nonnull.
2025-09-05 Paul Eggert <eggert@cs.ucla.edu>
+ progname: static check instead of dynamic
+ * lib/progname.c: Don’t include stdio.h or stdlib.h.
+ (set_program_name): Omit dynamic check that (with current glibc
+ optimization) drags in fwrite even when unlocked I/O is wanted.
+ The check was not all that useful in practice and we now have a
+ static one anyway (which admittedly is not that useful either).
+ Prefer memcmp to strncmp when equivalent, for clarity.
+ * lib/progname.h: Include arg-nonnull.h and declare
+ set_program_name with _GL_ARG_NONNULL.
+ * modules/progname (Depends-on): Add snippet/arg-nonnull.
+
propername-lite: simplify USE_MBRTOC32 away
* lib/propername-lite.c (USE_MBRTOC32): Remove.
Replace its use with HAVE_UCHAR_H.
#include "progname.h"
#include <errno.h> /* get program_invocation_name declaration */
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
But the name of the temporary executable is a detail that should not be
visible to the end user and to the test suite.
Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here. */
- const char *slash;
- const char *base;
-
- /* Sanity check. POSIX requires the invoking process to pass a non-NULL
- argv[0]. */
- if (argv0 == NULL)
- {
- /* It's a bug in the invoking program. Help diagnosing it. */
- fputs ("A NULL argv[0] was passed through an exec system call.\n",
- stderr);
- abort ();
- }
-
- slash = strrchr (argv0, '/');
- base = (slash != NULL ? slash + 1 : argv0);
- if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
+ char const *slash = strrchr (argv0, '/');
+ char const *base = slash ? slash + 1 : argv0;
+ if (7 <= base - argv0 && memcmp (base - 7, "/.libs/", 7) == 0)
{
argv0 = base;
if (strncmp (base, "lt-", 3) == 0)
set_program_name (argv[0]);
*/
+#include "arg-nonnull.h"
#ifdef __cplusplus
extern "C" {
/* Set program_name, based on argv[0].
argv0 must be a string allocated with indefinite extent, and must not be
modified after this call. */
-extern void set_program_name (const char *argv0);
+extern void set_program_name (const char *argv0)
+ _GL_ARG_NONNULL ((1));
#if ENABLE_RELOCATABLE
lib/progname.c
Depends-on:
+snippet/arg-nonnull
configure.ac:
AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])