Implement platform_get_argv0.

We are using autohell to put '-Wstrict-aliasing' into Makefile.am.

ok sthen@
This commit is contained in:
ajacoutot 2012-02-02 07:10:17 +00:00
parent ea6d4f3311
commit 9852adda0e
5 changed files with 102 additions and 17 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.149 2012/01/29 17:28:01 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.150 2012/02/02 07:10:17 ajacoutot Exp $
COMMENT-main= general-purpose utility library
COMMENT-docs= glib2 documentation
@ -10,7 +10,7 @@ EXTRACT_SUFX= .tar.xz
PKGNAME-main= glib2-${VERSION}
PKGNAME-docs= glib2-docs-${VERSION}
REVISION-main= 4
REVISION-main= 5
CATEGORIES= devel

View File

@ -0,0 +1,61 @@
$OpenBSD: patch-glib_goption_c,v 1.1 2012/02/02 07:10:18 ajacoutot Exp $
From e43a98c00091f5e293d2d9d72df2c04081802abe Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@gnome.org>
Date: Mon, 30 Jan 2012 15:17:06 +0000
Subject: goption: implement platform_get_argv0() for OpenBSD
--- glib/goption.c.orig Tue Aug 16 02:51:30 2011
+++ glib/goption.c Mon Jan 30 15:58:16 2012
@@ -139,6 +139,13 @@
#include <stdio.h>
#include <errno.h>
+#if defined __OpenBSD__
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
#include "goption.h"
#include "gprintf.h"
@@ -1665,7 +1672,7 @@ free_pending_nulls (GOptionContext *context,
static char *
platform_get_argv0 (void)
{
-#ifdef __linux
+#if defined __linux
char *cmdline;
char *base_arg0;
gsize len;
@@ -1683,6 +1690,28 @@ platform_get_argv0 (void)
* could be large.
*/
base_arg0 = g_path_get_basename (cmdline);
+ g_free (cmdline);
+ return base_arg0;
+#elif defined __OpenBSD__
+ char **cmdline = NULL;
+ char *base_arg0;
+ gsize len = PATH_MAX;
+
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
+
+ cmdline = (char **) realloc (cmdline, len);
+
+ if (sysctl (mib, nitems (mib), cmdline, &len, NULL, 0) == -1)
+ {
+ g_free (cmdline);
+ return NULL;
+ }
+
+ /* We could just return cmdline, but I think it's better
+ * to hold on to a smaller malloc block; the arguments
+ * could be large.
+ */
+ base_arg0 = g_path_get_basename (*cmdline);
g_free (cmdline);
return base_arg0;
#endif

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-glib_tests_Makefile_am,v 1.1 2012/02/02 07:10:18 ajacoutot Exp $
--- glib/tests/Makefile.am.orig Mon Jan 30 13:48:23 2012
+++ glib/tests/Makefile.am Mon Jan 30 13:48:51 2012
@@ -193,7 +193,7 @@ unix_nothreads_LDADD = $(progs_ldadd)
noinst_PROGRAMS += atomic
atomic_CFLAGS = $(INCLUDES)
if HAVE_GCC
-atomic_CFLAGS += -Wstrict-aliasing=2
+atomic_CFLAGS += -Wstrict-aliasing
endif
atomic_LDADD = $(progs_ldadd)

View File

@ -1,15 +0,0 @@
$OpenBSD: patch-glib_tests_Makefile_in,v 1.6 2011/09/25 16:45:07 naddy Exp $
-Wstrict-aliasing=2 is not available with gcc3.
--- glib/tests/Makefile.in.orig Sun Sep 25 16:55:42 2011
+++ glib/tests/Makefile.in Sun Sep 25 16:55:54 2011
@@ -41,7 +41,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile
noinst_PROGRAMS = $(am__EXEEXT_2) $(am__EXEEXT_3)
@OS_UNIX_TRUE@am__append_1 = unix unix-nothreads bitlock
@OS_UNIX_TRUE@am__append_2 = atomic
-@HAVE_GCC_TRUE@@OS_UNIX_TRUE@am__append_3 = -Wstrict-aliasing=2
+@HAVE_GCC_TRUE@@OS_UNIX_TRUE@am__append_3 = -Wstrict-aliasing
subdir = glib/tests
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4macros/gtk-doc.m4 \

View File

@ -0,0 +1,27 @@
$OpenBSD: patch-glib_tests_option-argv0_c,v 1.1 2012/02/02 07:10:18 ajacoutot Exp $
From e43a98c00091f5e293d2d9d72df2c04081802abe Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@gnome.org>
Date: Mon, 30 Jan 2012 15:17:06 +0000
Subject: goption: implement platform_get_argv0() for OpenBSD
--- glib/tests/option-argv0.c.orig Mon Jan 30 10:16:25 2012
+++ glib/tests/option-argv0.c Mon Jan 30 10:17:27 2012
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
-#ifdef __linux
+#if defined __linux || defined __OpenBSD__
static void
test_platform_argv0 (void)
{
@@ -55,7 +55,7 @@ main (int argc,
/* Note - we can't actually use g_test_* because g_test_init mutates
* g_get_prgname() which is exactly what we wanted to test =/
*/
-#ifdef __linux
+#if defined __linux || defined __OpenBSD__
g_print ("/option/argv0: ");
test_platform_argv0 ();
g_print ("OK\n");