3 dnl Copyright (C) 2016-2024 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.
8 # Check for getprogname or replacements for it
10 AC_DEFUN([gl_FUNC_GETPROGNAME],
12 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 gl_CHECK_FUNCS_ANDROID([getprogname], [[#include <stdlib.h>]])
15 if test $ac_cv_func_getprogname = no; then
17 case "$gl_cv_onwards_func_getprogname" in
18 future*) REPLACE_GETPROGNAME=1 ;;
21 AC_CHECK_DECLS([program_invocation_name],
23 [HAVE_DECL_PROGRAM_INVOCATION_NAME=0],
24 [[#include <errno.h>]])
27 AC_DEFUN([gl_PREREQ_GETPROGNAME],
29 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
30 AC_CHECK_FUNCS_ONCE([getexecname])
32 AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
34 AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
36 AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
38 # Incur the cost of this test only if none of the above worked.
39 if test $ac_found = 0; then
40 # On OpenBSD 5.1, using the global __progname variable appears to be
41 # the only way to implement getprogname.
42 AC_CACHE_CHECK([whether __progname is defined in default libraries],
43 [gl_cv_var___progname],
48 [[extern char *__progname;]],
49 [[return *__progname;]]
51 [gl_cv_var___progname=yes]
55 if test "$gl_cv_var___progname" = yes; then
56 AC_DEFINE([HAVE_VAR___PROGNAME], 1,
57 [Define if you have a global __progname variable])