Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / otherlibs / unix / getgr.c
blobeefaa5979cdde8fc3ac84a22791df3487769d523
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 <fail.h>
18 #include <alloc.h>
19 #include <memory.h>
20 #include "unixsupport.h"
21 #include <stdio.h>
22 #include <grp.h>
24 static value alloc_group_entry(struct group *entry)
26 value res;
27 value name = Val_unit, pass = Val_unit, mem = Val_unit;
29 Begin_roots3 (name, pass, mem);
30 name = copy_string(entry->gr_name);
31 pass = copy_string(entry->gr_passwd);
32 mem = copy_string_array((const char**)entry->gr_mem);
33 res = alloc_small(4, 0);
34 Field(res,0) = name;
35 Field(res,1) = pass;
36 Field(res,2) = Val_int(entry->gr_gid);
37 Field(res,3) = mem;
38 End_roots();
39 return res;
42 CAMLprim value unix_getgrnam(value name)
44 struct group * entry;
45 entry = getgrnam(String_val(name));
46 if (entry == NULL) raise_not_found();
47 return alloc_group_entry(entry);
50 CAMLprim value unix_getgrgid(value gid)
52 struct group * entry;
53 entry = getgrgid(Int_val(gid));
54 if (entry == NULL) raise_not_found();
55 return alloc_group_entry(entry);