1 # getprogname.m4 - check for getprogname or replacements for it
3 # Copyright (C) 2016-2020 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.
10 AC_DEFUN([gl_FUNC_GETPROGNAME],
12 AC_CHECK_FUNCS_ONCE([getprogname getexecname])
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
17 AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
19 AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
21 # Incur the cost of this test only if none of the above worked.
22 if test $ac_found = 0; then
23 # On OpenBSD 5.1, using the global __progname variable appears to be
24 # the only way to implement getprogname.
25 AC_CACHE_CHECK([whether __progname is defined in default libraries],
26 [gl_cv_var___progname],
31 [[extern char *__progname;]],
32 [[return *__progname;]]
34 [gl_cv_var___progname=yes]
38 if test "$gl_cv_var___progname" = yes; then
39 AC_DEFINE([HAVE_VAR___PROGNAME], 1,
40 [Define if you have a global __progname variable])