[libdispatch-dev] [PATCH] dispatch_getprogname()

Mark Heily mark at heily.com
Mon Dec 21 20:54:37 PST 2009


When compiling a libdispatch debug build on Linux, I found that
getprogname(3) is not available. Here is a patch that implements a wrapper
function.

Regards,

  - Mark


Index: configure.ac
===================================================================
--- configure.ac	(revision 174)
+++ configure.ac	(working copy)
@@ -192,7 +192,7 @@
  AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
  AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
  AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include
<sys/mount.h>]])
-AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time
malloc_create_zone sysconf])
+AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time
malloc_create_zone sysconf getprogname])

  AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
    [have_posix_spawn_start_suspended=true],
Index: src/queue.c
===================================================================
--- src/queue.c	(revision 174)
+++ src/queue.c	(working copy)
@@ -1786,6 +1786,18 @@
  	va_end(ap);
  }

+static char *
+dispatch_getprogname(void)
+{
+#if HAVE_GETPROGNAME
+    return getprogname();
+#elif __linux__
+    return program_invocation_short_name;
+#else
+#error getprogname() is not available on this platform
+#endif
+}
+
  void
  _dispatch_logv(const char *msg, va_list ap)
  {
@@ -1806,7 +1818,8 @@
  			struct timeval tv;
  			gettimeofday(&tv, NULL);
  			fprintf(logfile, "=== log file opened for %s[%u] at %ld.%06u ===\n",
-					getprogname() ?: "", getpid(), tv.tv_sec, tv.tv_usec);
+                    dispatch_getprogname() ?: "",
+                    getpid(), tv.tv_sec, tv.tv_usec);
  		}
  	}
  	vfprintf(logfile, newbuf, ap);



More information about the libdispatch-dev mailing list