---
luxio.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/luxio.c b/luxio.c
index 5013106..d9b0ce9 100644
--- a/luxio.c
+++ b/luxio.c
@@ -694,7 +694,39 @@ luxio_setgid(lua_State *L) /* 4.2.2 */
return 2;
}
-/* TODO: getgroups() 4.2.3 */
+/*** Get list of supplementary group IDs.
+
+Return the supplementary group IDs of the calling process.
+
+@treturn number return value
+@treturn table|errno group IDs, or errno.
+@function getgroups
+*/
+static int
+luxio_getgroups(lua_State *L)
+{
+ int ngroups;
+ long ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
+ gid_t groups[ngroups_max];
+
+ ngroups = getgroups(ngroups_max, groups);
+ if (ngroups == -1) {
+ lua_pushinteger(L, -1);
+ lua_pushinteger(L, errno);
+
+ return 2;
+ }
+
+ lua_pushinteger(L, ngroups);
+ lua_newtable(L);
+ for (size_t i = 0; i < ngroups; i++) {
+ lua_pushinteger(L, i + 1);
+ lua_pushinteger(L, groups[i]);
+ lua_settable(L, -3);
+ }
+
+ return 2;
+}
/*** Get username.
@@ -4502,6 +4534,7 @@ luxio_functions[] = {
{ "getppid", luxio_getppid },
{ "getpgrp", luxio_getpgrp },
+ { "getgroups", luxio_getgroups },
{ "getuid", luxio_getuid },
{ "geteuid", luxio_geteuid },
--
2.11.0