]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/unix/getgr.c
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / unix / getgr.c
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 /***********************************************************************/
13
14 /* $Id: getgr.c 4144 2001-12-07 13:41:02Z xleroy $ */
15
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>
23
24 static value alloc_group_entry(struct group *entry)
25 {
26   value res;
27   value name = Val_unit, pass = Val_unit, mem = Val_unit;
28
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;
40 }
41
42 CAMLprim value unix_getgrnam(value name)
43 {
44   struct group * entry;
45   entry = getgrnam(String_val(name));
46   if (entry == NULL) raise_not_found();
47   return alloc_group_entry(entry);
48 }
49
50 CAMLprim value unix_getgrgid(value gid)
51 {
52   struct group * entry;
53   entry = getgrgid(Int_val(gid));
54   if (entry == NULL) raise_not_found();
55   return alloc_group_entry(entry);
56 }