Merge branch 'pu'
[jungerl.git] / lib / posix_drv / c_src / my-posix.c
bloba60f2fd6e21b36783f846b4f3ffbde4e0b4b494d
1 /*
2 ** Copyright (c) 2003, Scott Lystig Fritchie. All rights reserved.
3 ** See the file "../LICENSE" for license details.
4 */
6 #include <stdio.h>
7 #include <string.h>
8 #include <grp.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 /* BSD-specific? (for NGROUPS_MAX) #include <sys/syslimits.h> */
12 #include <sys/stat.h>
14 #ifndef NGROUPS_MAX
15 #define NGROUPS_MAX 64 /* Big, but we'll be safe */
16 #endif /* !NGROUPS_MAX */
18 #include <erl_driver.h>
19 #include <erl_driver_tk.h>
20 #include <posix_drv.h>
21 #include <my-posix.h>
23 int
24 my_getgroups(gid_t *gidset)
26 return getgroups(NGROUPS_MAX, gidset);
29 int
30 make_getgroups_list(struct descriptor *desc, callstate_t *c,
31 ErlDrvTermData *msg, int *members, int *msgcount)
33 int i;
35 for (i = 0; i < c->o.ret_int; i++) {
36 *msgcount = LOAD_INT(msg, *msgcount, c->o.gidset[i]);
38 *msgcount = LOAD_NIL(msg, *msgcount);
39 *msgcount = LOAD_LIST(msg, *msgcount, c->o.ret_int + 1); /* include the NIL! */
41 *members = 1;
42 return 1;
45 int
46 make_groups_list(struct descriptor *desc, callstate_t *c,
47 ErlDrvTermData *msg, int *members, int *msgcount)
49 int i;
50 char **g;
51 int len;
52 char *gcopy;
54 g = c->o.ret_grptr->gr_mem;
55 for (i = 0; g != NULL && *g != NULL; g++, i++) {
56 len = strlen(*g);
57 if ((gcopy = edtk_driver_alloc_wrapper(len + 1)) == NULL) {
58 return 0;
60 strcpy(gcopy, *g);
61 *msgcount = LOAD_BINARY(msg, *msgcount,
62 edtk_alloced_ptr2ErlDrvBinary(gcopy), 0, len);
64 *msgcount = LOAD_NIL(msg, *msgcount);
65 *msgcount = LOAD_LIST(msg, *msgcount, i + 1); /* include the NIL! */
67 *members = 1;
68 return 1;