diff options
author | Antoine Jacoutot <ajacoutot@gnome.org> | 2014-04-16 10:27:09 +0200 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@gnome.org> | 2014-04-20 23:16:59 +0200 |
commit | 58abc1fc198a8579667ea2164c33964b250a0435 (patch) | |
tree | 7e359717b7a580e7a95bc11397a7499a46510795 /glib | |
parent | 9352cdb5f4f7dffa983d411625e874110b81cb35 (diff) |
platform_get_argv0: drop unneeded headers for OpenBSD
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
Diffstat (limited to 'glib')
-rw-r--r-- | glib/goption.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/glib/goption.c b/glib/goption.c index 31bbf164f..a11971fe9 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -185,9 +185,7 @@ #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) { |