Debian Codegraph @

m4/getprogname.m4

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