[libdispatch-dev] [PATCH] dispatch_getprogname()

Mark Heily mark at heily.com
Thu Dec 24 21:29:09 PST 2009


Robert Watson wrote:
> 
> On Mon, 21 Dec 2009, Mark Heily wrote:
> 
>> 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.
> 
> Could you tweak the approach slightly to:
> 
> - Add a src/shims/getprogname.[ch], implementing getprogname() there if 
> it's
>   not available?
> - Directly test for program_invocation_short_name using configure and 
> use the
>   resulting HAVE_ ifdef as needed?
> 

See below for the revised patch.

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 program_invocation_short_name])

  AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
    [have_posix_spawn_start_suspended=true],
Index: src/shims/getprogname.h
===================================================================
--- src/shims/getprogname.h     (revision 0)
+++ src/shims/getprogname.h     (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#ifndef __DISPATCH_SHIMS_GETPROGNAME__
+#define __DISPATCH_SHIMS_GETPROGNAME__
+
+#ifndef HAVE_GETPROGNAME
+static inline char *
+getprogname(void)
+{
+# if HAVE_PROGRAM_INVOCATION_SHORT_NAME
+    return program_invocation_short_name;
+# else
+#   error getprogname(3) is not available on this platform
+# endif
+}
+#endif /* HAVE_GETPROGNAME */
+
+#endif /* __DISPATCH_SHIMS_GETPROGNAME__ */
Index: src/os_shims.h
===================================================================
--- src/os_shims.h      (revision 174)
+++ src/os_shims.h      (working copy)
@@ -46,6 +46,7 @@
  #define        FD_COPY(f, t)   (void)(*(t) = *(f))
  #endif

+#include "shims/getprogname.h"
  #include "shims/malloc_zone.h"
  #include "shims/tsd.h"
  #include "shims/perfmon.h"



More information about the libdispatch-dev mailing list