| 1 |
# getprogname.m4 |
| 2 |
# serial 9 |
| 3 |
dnl Copyright (C) 2016-2026 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# Check for getprogname or replacements for it |
| 10 |
|
| 11 |
AC_DEFUN([gl_FUNC_GETPROGNAME], |
| 12 |
[ |
| 13 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 14 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 15 |
AC_CHECK_HEADERS_ONCE([sys/process.h]) |
| 16 |
if test $ac_cv_header_sys_process_h = yes; then |
| 17 |
HAVE_SYS_PROCESS_H=1 |
| 18 |
else |
| 19 |
HAVE_SYS_PROCESS_H=0 |
| 20 |
fi |
| 21 |
gl_CHECK_FUNCS_ANDROID([getprogname], [[#include <stdlib.h>]]) |
| 22 |
if test $ac_cv_func_getprogname = no; then |
| 23 |
HAVE_GETPROGNAME=0 |
| 24 |
case "$gl_cv_onwards_func_getprogname" in |
| 25 |
future*) REPLACE_GETPROGNAME=1 ;; |
| 26 |
esac |
| 27 |
fi |
| 28 |
AC_CHECK_DECLS([program_invocation_name], |
| 29 |
[], |
| 30 |
[HAVE_DECL_PROGRAM_INVOCATION_NAME=0], |
| 31 |
[[#include <errno.h>]]) |
| 32 |
]) |
| 33 |
|
| 34 |
AC_DEFUN([gl_PREREQ_GETPROGNAME], |
| 35 |
[ |
| 36 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 37 |
AC_CHECK_FUNCS_ONCE([getexecname]) |
| 38 |
ac_found=0 |
| 39 |
AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [], |
| 40 |
[#include <errno.h>]) |
| 41 |
AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [], |
| 42 |
[#include <errno.h>]) |
| 43 |
AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>]) |
| 44 |
|
| 45 |
# Incur the cost of this test only if none of the above worked. |
| 46 |
if test $ac_found = 0; then |
| 47 |
# On OpenBSD 5.1, using the global __progname variable appears to be |
| 48 |
# the only way to implement getprogname. |
| 49 |
AC_CACHE_CHECK([whether __progname is defined in default libraries], |
| 50 |
[gl_cv_var___progname], |
| 51 |
[ |
| 52 |
gl_cv_var___progname= |
| 53 |
AC_LINK_IFELSE( |
| 54 |
[AC_LANG_PROGRAM( |
| 55 |
[[extern char *__progname;]], |
| 56 |
[[return *__progname;]] |
| 57 |
)], |
| 58 |
[gl_cv_var___progname=yes] |
| 59 |
) |
| 60 |
] |
| 61 |
) |
| 62 |
if test "$gl_cv_var___progname" = yes; then |
| 63 |
AC_DEFINE([HAVE_VAR___PROGNAME], 1, |
| 64 |
[Define if you have a global __progname variable]) |
| 65 |
fi |
| 66 |
fi |
| 67 |
]) |