From 21095adeffe6d053c29019f335ceb5c339a15e8b Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 12 Oct 2018 15:47:45 +0200 Subject: Properly detect availability of program_invocation_short_name and suppress compiler warning --- configure.ac | 18 ++++++++++++++++++ src/libusbmuxd.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index b6bb9fa..b719b96 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,24 @@ case ${host_os} in AC_MSG_RESULT([yes]) AX_PTHREAD([], [AC_MSG_ERROR([pthread is required to build libusbmuxd])]) AC_CHECK_LIB(pthread, [pthread_create, pthread_mutex_lock], [], [AC_MSG_ERROR([pthread is required to build libusbmuxd])]) + AC_CACHE_CHECK(for program_invocation_short_name, ac_cv_program_invocation_short_name,[ + AC_TRY_LINK([extern char* program_invocation_short_name;],[return program_invocation_short_name;], + [ac_cv_program_invocation_short_name=yes], + [ac_cv_program_invocation_short_name=no] + ) + ]) + if test "x$ac_cv_program_invocation_short_name" = "xyes"; then + AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME, 1, [Define if you have program_invocation_short_name]) + AC_CACHE_CHECK(if program_invocation_short_name is declared in errno.h, ac_cv_program_invocation_short_name_errno_h,[ + AC_TRY_LINK([#include ],[return program_invocation_short_name;], + [ac_cv_program_invocation_short_name_errno_h=yes], + [ac_cv_program_invocation_short_name_errno_h=no] + ) + ]) + if test "x$ac_cv_program_invocation_short_name_errno_h" = "xyes"; then + AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME_ERRNO_H, 1, [Define if program_invocation_short_name is declared in errno.h]) + fi + fi ;; esac AM_CONDITIONAL(WIN32, test x$win32 = xtrue) diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 39db216..712c362 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -59,7 +59,7 @@ #include #include #include -#ifdef _GNU_SOURCE +#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME) && !defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME_ERRNO_H) extern char *program_invocation_short_name; #endif #ifdef __APPLE__ @@ -521,7 +521,7 @@ static void get_prog_name() #endif } free(_pname); -#elif defined (_GNU_SOURCE) +#elif defined (HAVE_PROGRAM_INVOCATION_SHORT_NAME) char *pname = program_invocation_short_name; if (pname) { prog_name = strdup(pname); -- cgit v1.1-32-gdbae