platform_get_argv0: drop unneeded headers for OpenBSD
authorAntoine Jacoutot <ajacoutot@gnome.org>
Wed, 16 Apr 2014 08:27:09 +0000 (10:27 +0200)
committerAntoine Jacoutot <ajacoutot@gnome.org>
Sun, 20 Apr 2014 21:16:59 +0000 (23:16 +0200)
And properly set the size of len.
There is also no need for realloc(), g_malloc0 will do just fine.

https://bugzilla.gnome.org/show_bug.cgi?id=728280

glib/goption.c

index 31bbf16..a11971f 100644 (file)
 #include <errno.h>
 
 #if defined __OpenBSD__
-#include <sys/types.h>
 #include <unistd.h>
-#include <sys/param.h>
 #include <sys/sysctl.h>
 #endif
 
@@ -1763,13 +1761,16 @@ platform_get_argv0 (void)
   g_free (cmdline);
   return base_arg0;
 #elif defined __OpenBSD__
-  char **cmdline = NULL;
+  char **cmdline;
   char *base_arg0;
-  gsize len = PATH_MAX;
+  gsize len;
 
   int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
 
-  cmdline = (char **) realloc (cmdline, len);
+  if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+      return NULL;
+
+  cmdline = g_malloc0 (len);
 
   if (sysctl (mib, G_N_ELEMENTS (mib), cmdline, &len, NULL, 0) == -1)
     {