[seed] Add os.getgroups
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Add os.getgroups
- Date: Mon, 13 Apr 2009 21:15:58 -0400 (EDT)
commit 0c856b68768797d1534222b0af6ae6a221218db8
Author: Robert Carr <racarr mireia (none)>
Date: Mon Apr 13 20:48:41 2009 -0400
Add os.getgroups
---
modules/os/os.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/modules/os/os.c b/modules/os/os.c
index 7cf4ce1..1ef5809 100644
--- a/modules/os/os.c
+++ b/modules/os/os.c
@@ -2,6 +2,7 @@
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
+#include <errno.h>
SeedObject os_namespace;
@@ -185,17 +186,32 @@ seed_os_getgroups (SeedContext ctx,
const SeedValue arguments[],
SeedException * exception)
{
- SeedValue seed_ret;
+ SeedValue ret;
+ SeedValue *groups;
gid_t *group_list;
- guint num_groups;
+ guint num_groups, i;
if (argument_count != 0)
{
EXPECTED_EXCEPTION("os.geteuid", "no arguments");
}
- ret = getuid ();
+ num_groups = getgroups(0, NULL);
+ group_list = g_alloca (num_groups * sizeof(gid_t));
+ groups = g_alloca (num_groups * sizeof(SeedValue));
+ if (getgroups (num_groups, group_list) < 0)
+ {
+ // TODO: Decide on how to handle exceptions for things like this...
+ // Investigate python
+ return seed_make_null (ctx);
+ }
+
+ for (i = 0; i < num_groups; i++)
+ {
+ groups[i] = seed_value_from_long (ctx, (glong) group_list[i], exception);
+ }
+ ret = seed_make_array (ctx, groups, num_groups, exception);
- return seed_value_from_long (ctx, (glong) ret, exception);
+ return ret;
}
seed_static_function os_funcs[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]