On QNX using the following testdir:

    $ gnulib-tool --create-testdir --dir testdir1 getprogname

I see the following:

    $ ./configure | grep getprogname
    checking for getprogname... yes
    $ make
    [...]
    gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -DGNULIB_STRICT_CHECKING=1 
-DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib  -Wno-error 
-Wno-error  -I/usr/include -D_QNX_SOURCE --sysroot=/ -MT test-getprogname.o -MD 
-MP -MF $depbase.Tpo -c -o test-getprogname.o test-getprogname.c &&\
    mv -f $depbase.Tpo $depbase.Po
    test-getprogname.c: In function 'main':
    test-getprogname.c:33:19: warning: implicit declaration of function 
'getprogname' [-Wimplicit-function-declaration]
       33 |   char const *p = getprogname ();
          |                   ^~~~~~~~~~~
    test-getprogname.c:33:19: warning: initialization of 'const char *' from 
'int' makes pointer from integer without a cast [-Wint-conversion]
    [...]

This is because QNX declares it in sys/process.h which is not included
[1].

The copyright header on that file only lists 2018, so I don't think
older QNX versions have it. Therefore, I think a check is needed for it.

I haven't pushed the attached patch yet since I am not 100% sure I wrote
the include in stdlib.in.h correctly. I think the GNULIB_POSIXCHECK is
needed so we can define the warning even when the module is not used, is
that correct?

Collin

[1] 
https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.lib_ref/topic/g/getprogname.html

>From 23462c65bf46f0873a0a53744a10c25644b2327d Mon Sep 17 00:00:00 2001
Message-ID: <23462c65bf46f0873a0a53744a10c25644b2327d.1767248778.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Wed, 31 Dec 2025 22:25:46 -0800
Subject: [PATCH] getprogname: Fix missing declaration on QNX.

* lib/stdlib.in.h [@GNULIB_GETPROGNAME@ && @HAVE_SYS_PROCESS_H@]:
Include sys/process.h.
* m4/getprogname.m4 (gl_FUNC_GETPROGNAME): Check for sys/process.h.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_SYS_PROCESS_H
to zero.
* modules/stdlib-h (Makefile.am): Substitute HAVE_SYS_PROCESS_H.
---
 ChangeLog         | 8 ++++++++
 lib/stdlib.in.h   | 5 +++++
 m4/getprogname.m4 | 8 +++++++-
 m4/stdlib_h.m4    | 3 ++-
 modules/stdlib-h  | 1 +
 5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fd4314ef8b..7f06949378 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2025-12-31  Collin Funk  <[email protected]>
 
+	getprogname: Fix missing declaration on QNX.
+	* lib/stdlib.in.h [@GNULIB_GETPROGNAME@ && @HAVE_SYS_PROCESS_H@]:
+	Include sys/process.h.
+	* m4/getprogname.m4 (gl_FUNC_GETPROGNAME): Check for sys/process.h.
+	* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_SYS_PROCESS_H
+	to zero.
+	* modules/stdlib-h (Makefile.am): Substitute HAVE_SYS_PROCESS_H.
+
 	inet_ntop, inet_pton: Fix a link error on QNX.
 	* m4/inet_ntop.m4 (gl_FUNC_INET_NTOP): Also check for inet_ntop in
 	libsocket.
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index b5ad275e5d..737675a999 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -70,6 +70,11 @@
 # include <sys/loadavg.h>
 #endif
 
+/* QNX declares getprogname() in <sys/process.h>.  */
+#if (@GNULIB_GETPROGNAME@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_PROCESS_H@
+# include <sys/process.h>
+#endif
+
 /* Native Windows platforms declare _mktemp() in <io.h>.  */
 #if defined _WIN32 && !defined __CYGWIN__
 # include <io.h>
diff --git a/m4/getprogname.m4 b/m4/getprogname.m4
index 90f34c7439..4de888e10a 100644
--- a/m4/getprogname.m4
+++ b/m4/getprogname.m4
@@ -1,5 +1,5 @@
 # getprogname.m4
-# serial 8
+# serial 9
 dnl Copyright (C) 2016-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,6 +12,12 @@ AC_DEFUN([gl_FUNC_GETPROGNAME]
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_CHECK_HEADERS_ONCE([sys/process.h])
+  if test $ac_cv_header_sys_process_h = yes; then
+    HAVE_SYS_PROCESS_H=1
+  else
+    HAVE_SYS_PROCESS_H=0
+  fi
   gl_CHECK_FUNCS_ANDROID([getprogname], [[#include <stdlib.h>]])
   if test $ac_cv_func_getprogname = no; then
     HAVE_GETPROGNAME=0
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index ab2e87019b..139626be7b 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -1,5 +1,5 @@
 # stdlib_h.m4
-# serial 85
+# serial 86
 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -223,6 +223,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS]
   HAVE_STRTOULL=1;           AC_SUBST([HAVE_STRTOULL])
   HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
   HAVE_SYS_LOADAVG_H=0;      AC_SUBST([HAVE_SYS_LOADAVG_H])
+  HAVE_SYS_PROCESS_H=0;      AC_SUBST([HAVE_SYS_PROCESS_H])
   HAVE_UNLOCKPT=1;           AC_SUBST([HAVE_UNLOCKPT])
   HAVE_DECL_UNSETENV=1;      AC_SUBST([HAVE_DECL_UNSETENV])
   REPLACE__EXIT=0;           AC_SUBST([REPLACE__EXIT])
diff --git a/modules/stdlib-h b/modules/stdlib-h
index 7f479d000c..bc1958d529 100644
--- a/modules/stdlib-h
+++ b/modules/stdlib-h
@@ -135,6 +135,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
 	      -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
 	      -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
 	      -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
+	      -e 's|@''HAVE_SYS_PROCESS_H''@|$(HAVE_SYS_PROCESS_H)|g' \
 	      -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
 	      -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
 	      < $@-t1 > $@-t2
-- 
2.52.0

Reply via email to