summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@hadrons.org>2011-07-05 23:27:31 +0200
committerGuillem Jover <guillem@hadrons.org>2012-05-29 04:36:23 +0200
commitb5cc17d66498c3da0aa862a517f630b4aa5d5dc6 (patch)
tree452a6a278b2f9c66b0664d186011554fb42ddd2e
parentabf14c3940a5ec08bb9fce9ddfb7375309a4d97f (diff)
Use getexecname() if available for getprogname()
This function is present on Solaris.
-rw-r--r--configure.ac1
-rw-r--r--src/progname.c6
2 files changed, 6 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 06a02b7..c9cf0a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,7 @@ AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions.
+AC_CHECK_FUNCS([getexecname])
AC_CONFIG_FILES([
Makefile
diff --git a/src/progname.c b/src/progname.c
index f24071a..b5132d8 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2006 Robert Millan
- * Copyright © 2010-2011 Guillem Jover
+ * Copyright © 2010-2012 Guillem Jover <guillem@hadrons.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,6 +41,10 @@ getprogname(void)
#ifdef __GLIBC__
if (__progname == NULL)
__progname = program_invocation_short_name;
+#elif defined(HAVE_GETEXECNAME)
+ /* getexecname(3) returns an absolute pathname, normalize it. */
+ if (__progname == NULL)
+ setprogname(getexecname());
#endif
return __progname;