Add copyright notices and new function String.chomp
[ocaml.git] / otherlibs / unix / getgroups.c
blob4d34d5be90d009565e1c0ab13e213cb9527351f0
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
6 /* */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
11 /* */
12 /***********************************************************************/
14 /* $Id$ */
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <fail.h>
20 #ifdef HAS_GETGROUPS
22 #include <sys/types.h>
23 #ifdef HAS_UNISTD
24 #include <unistd.h>
25 #endif
26 #include <limits.h>
27 #include "unixsupport.h"
29 CAMLprim value unix_getgroups(value unit)
31 gid_t gidset[NGROUPS_MAX];
32 int n;
33 value res;
34 int i;
36 n = getgroups(NGROUPS_MAX, gidset);
37 if (n == -1) uerror("getgroups", Nothing);
38 res = alloc_tuple(n);
39 for (i = 0; i < n; i++)
40 Field(res, i) = Val_int(gidset[i]);
41 return res;
44 #else
46 CAMLprim value unix_getgroups(value unit)
47 { invalid_argument("getgroups not implemented"); }
49 #endif