File: getgrouplist.3

package info (click to toggle)
manpages-ja 0.5.0.0.20050315-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,620 kB
  • ctags: 4
  • sloc: sh: 12,675; perl: 157; makefile: 106
file content (83 lines) | stat: -rw-r--r-- 2,044 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
.\" Copyright 2002 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
.\" Distributed under GPL
.\" Thanks to glibc info pages
.\"
.\" Modified 2003-11-18, aeb: glibc is broken
.\"
.\" Japanese Version Copyright (c) 2004 Yuichi SATO
.\"         all rights reserved.
.\" Translated Sat Aug  7 07:39:48 JST 2004
.\"         by Yuichi SATO <ysato444@yahoo.co.jp>
.\"
.TH GETGROUPLIST 3 2003-11-18 "GNU" "Linux Programmer's Manual"
.SH ̾
getgrouplist \-  桼°륰롼פΥꥹ
.SH 
.sp 
.B #include <grp.h>
.sp
.BI "int getgrouplist (const char *" user ", gid_t " group ,
.in 25
.BI "gid_t *" groups ", int *" ngroups );
.SH 
.B getgrouplist()
ؿ
.I user
°ƤΥ롼פ򥰥롼ץǡ١Ĵ٤롣
롼 ID
.RI * ngroups
ޤǤб륰롼פ
.I groups
˳Ǽ;
δؿ֤ͤϡºݤ˳Ǽ줿롼 ID οǤ롣
.I group

.B getgroup\%list()
֤륰롼פΥꥹȤ˼ưŪ˴ޤ롣
.SH ֤
ĤäƤΥ롼פο
.RI * ngroups 
.B getgrouplist()
 `-1' ֤
⡢Ԥ⡢ºݤΥ롼פο
.RI * ngroups
˳Ǽ롣
.SH Х
δؿ glibc 2.3.2 Ǥμϴְ㤨Ƥ:
ºݤΥ롼פο
.RI * ngroups
礭硢񤭤Ƥޤ
.SH 
δؿ glibc 2.2.4 ¸ߤ롣
.SH 
.nf
/*  glibc 2.3.2 Ǥϥå夹롣*/
#include <stdio.h>
#include <stdlib.h>
#include <grp.h>
#include <pwd.h>

int main() {
        int i, ng = 0;
        char *user = "who";	/* 桼̾򤳤˽񤯡*/
        gid_t *groups = NULL;
        struct passwd *pw = getpwnam(user);
        if (pw == NULL)
                return 0;

        if (getgrouplist(user, pw->pw_gid, NULL, &ng) < 0) {
                groups = (gid_t *) malloc(ng * sizeof (gid_t));
                getgrouplist(user, pw->pw_gid, groups, &ng);
        }

        for(i = 0; i < ng; i++)
                printf("%d\en", groups[i]);

        return 0;
}
.fi
.SH Ϣ
.BR getgroups (3),
.BR setgroups (3)