From: Nikos Mavrogiannopoulos Date: Thu, 21 Nov 2013 19:44:46 +0000 (+0100) Subject: Added progname module which is used by error(). X-Git-Tag: gnutls_3_3_0pre0~566 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d787d8f755dd998831b9b61a42e14618cdbc7cf;p=thirdparty%2Fgnutls.git Added progname module which is used by error(). --- diff --git a/src/gl/Makefile.am b/src/gl/Makefile.am index d578a0d25e..c25328d129 100644 --- a/src/gl/Makefile.am +++ b/src/gl/Makefile.am @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --local-dir=src/gl/override --lib=libgnu_gpl --source-base=src/gl --m4-base=src/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=ggl --no-vc-files parse-datetime +# Reproduce by: gnulib-tool --import --dir=. --local-dir=src/gl/override --lib=libgnu_gpl --source-base=src/gl --m4-base=src/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=ggl --no-vc-files parse-datetime progname AUTOMAKE_OPTIONS = 1.9.6 gnits @@ -219,6 +219,12 @@ EXTRA_DIST += parse-datetime.h ## end gnulib module parse-datetime +## begin gnulib module progname + +libgnu_gpl_la_SOURCES += progname.h progname.c + +## end gnulib module progname + ## begin gnulib module setenv diff --git a/src/gl/m4/gnulib-cache.m4 b/src/gl/m4/gnulib-cache.m4 index 17ed03bba4..a16c7da91f 100644 --- a/src/gl/m4/gnulib-cache.m4 +++ b/src/gl/m4/gnulib-cache.m4 @@ -27,12 +27,13 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --local-dir=src/gl/override --lib=libgnu_gpl --source-base=src/gl --m4-base=src/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=ggl --no-vc-files parse-datetime +# gnulib-tool --import --dir=. --local-dir=src/gl/override --lib=libgnu_gpl --source-base=src/gl --m4-base=src/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=ggl --no-vc-files parse-datetime progname # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([src/gl/override]) gl_MODULES([ parse-datetime + progname ]) gl_AVOID([]) gl_SOURCE_BASE([src/gl]) diff --git a/src/gl/m4/gnulib-comp.m4 b/src/gl/m4/gnulib-comp.m4 index 6c287f2d59..9a35eedc3f 100644 --- a/src/gl/m4/gnulib-comp.m4 +++ b/src/gl/m4/gnulib-comp.m4 @@ -59,6 +59,7 @@ AC_DEFUN([ggl_EARLY], # Code from module msvc-nothrow: # Code from module multiarch: # Code from module parse-datetime: + # Code from module progname: # Code from module setenv: # Code from module snippet/_Noreturn: # Code from module snippet/arg-nonnull: @@ -139,6 +140,8 @@ AC_DEFUN([ggl_INIT], fi gl_MULTIARCH gl_PARSE_DATETIME + AC_CHECK_DECLS([program_invocation_name], [], [], [#include ]) + AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include ]) gl_FUNC_SETENV if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then AC_LIBOBJ([setenv]) @@ -346,6 +349,8 @@ AC_DEFUN([ggl_FILE_LIST], [ lib/msvc-nothrow.h lib/parse-datetime.h lib/parse-datetime.y + lib/progname.c + lib/progname.h lib/setenv.c lib/stdbool.in.h lib/stddef.in.h diff --git a/src/gl/progname.c b/src/gl/progname.c new file mode 100644 index 0000000000..0c195e521a --- /dev/null +++ b/src/gl/progname.c @@ -0,0 +1,92 @@ +/* Program name management. + Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +/* Specification. */ +#undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */ +#include "progname.h" + +#include /* get program_invocation_name declaration */ +#include +#include +#include + + +/* String containing name the program is called with. + To be initialized by main(). */ +const char *program_name = NULL; + +/* Set program_name, based on argv[0]. + argv0 must be a string allocated with indefinite extent, and must not be + modified after this call. */ +void +set_program_name (const char *argv0) +{ + /* libtool creates a temporary executable whose name is sometimes prefixed + with "lt-" (depends on the platform). It also makes argv[0] absolute. + But the name of the temporary executable is a detail that should not be + visible to the end user and to the test suite. + Remove this "/.libs/" or "/.libs/lt-" prefix here. */ + const char *slash; + const char *base; + + /* Sanity check. POSIX requires the invoking process to pass a non-NULL + argv[0]. */ + if (argv0 == NULL) + { + /* It's a bug in the invoking program. Help diagnosing it. */ + fputs ("A NULL argv[0] was passed through an exec system call.\n", + stderr); + abort (); + } + + slash = strrchr (argv0, '/'); + base = (slash != NULL ? slash + 1 : argv0); + if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0) + { + argv0 = base; + if (strncmp (base, "lt-", 3) == 0) + { + argv0 = base + 3; + /* On glibc systems, remove the "lt-" prefix from the variable + program_invocation_short_name. */ +#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + program_invocation_short_name = (char *) argv0; +#endif + } + } + + /* But don't strip off a leading / in general, because when the user + runs + /some/hidden/place/bin/cp foo foo + he should get the error message + /some/hidden/place/bin/cp: `foo' and `foo' are the same file + not + cp: `foo' and `foo' are the same file + */ + + program_name = argv0; + + /* On glibc systems, the error() function comes from libc and uses the + variable program_invocation_name, not program_name. So set this variable + as well. */ +#if HAVE_DECL_PROGRAM_INVOCATION_NAME + program_invocation_name = (char *) argv0; +#endif +} diff --git a/src/gl/progname.h b/src/gl/progname.h new file mode 100644 index 0000000000..b4f3c2778a --- /dev/null +++ b/src/gl/progname.h @@ -0,0 +1,62 @@ +/* Program name management. + Copyright (C) 2001-2004, 2006, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _PROGNAME_H +#define _PROGNAME_H + +/* Programs using this file should do the following in main(): + set_program_name (argv[0]); + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* String containing name the program is called with. */ +extern const char *program_name; + +/* Set program_name, based on argv[0]. + argv0 must be a string allocated with indefinite extent, and must not be + modified after this call. */ +extern void set_program_name (const char *argv0); + +#if ENABLE_RELOCATABLE + +/* Set program_name, based on argv[0], and original installation prefix and + directory, for relocatability. */ +extern void set_program_name_and_installdir (const char *argv0, + const char *orig_installprefix, + const char *orig_installdir); +#undef set_program_name +#define set_program_name(ARG0) \ + set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR) + +/* Return the full pathname of the current executable, based on the earlier + call to set_program_name_and_installdir. Return NULL if unknown. */ +extern char *get_full_program_name (void); + +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif /* _PROGNAME_H */