OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / getpwnam.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's "POSIX Programmer's Guide" (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\"
30 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 1996-05-27 by Martin Schulze (joey@linux.de)
32 .\" Modified 2003-11-15 by aeb
33 .\" 2008-11-07, mtk, Added an example program for getpwnam_r().
34 .\"
35 .\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka
36 .\"     all rights reserved.
37 .\" Translated 1997-12-18, HIROFUMI Nishizuka <nishi@rpts.cl.nec.co.jp>
38 .\" Updated & Modified 2004-01-06, Yuichi SATO <ysato444@yahoo.co.jp>
39 .\" Updated & Modified 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated & Modified 2005-10-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2008-12-24, Akihiro MOTOKI, LDP v3.14
42 .\"
43 .TH GETPWNAM 3  2009-03-30 "GNU" "Linux Programmer's Manual"
44 .\"O .SH NAME
45 .SH Ì¾Á°
46 .\"O getpwnam, getpwnam_r, getpwuid, getpwuid_r \- get password file entry
47 getpwnam, getpwnam_r, getpwuid, getpwuid_r \- ¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥È¥ê¤Î¼èÆÀ
48 .\"O .SH SYNOPSIS
49 .SH ½ñ¼°
50 .nf
51 .B #include <sys/types.h>
52 .B #include <pwd.h>
53 .sp
54 .BI "struct passwd *getpwnam(const char *" name );
55 .sp
56 .BI "struct passwd *getpwuid(uid_t " uid );
57 .sp
58 .BI "int getpwnam_r(const char *" name ", struct passwd *" pwd ,
59 .br
60 .BI "            char *" buf ", size_t " buflen ", struct passwd **" result );
61 .sp
62 .BI "int getpwuid_r(uid_t " uid ", struct passwd *" pwd ,
63 .br
64 .BI "            char *" buf ", size_t " buflen ", struct passwd **" result );
65 .fi
66 .sp
67 .in -4n
68 .\"O Feature Test Macro Requirements for glibc (see
69 .\"O .BR feature_test_macros (7)):
70 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
71 .RB ( feature_test_macros (7)
72 »²¾È):
73 .in
74 .sp
75 .ad l
76 .BR getpwnam_r (),
77 .BR getpwuid_r ():
78 .RS 4
79 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
80 _SVID_SOURCE || _POSIX_SOURCE
81 .RE
82 .ad b
83 .\"O .SH DESCRIPTION
84 .SH ÀâÌÀ
85 .\"O The
86 .\"O .BR getpwnam ()
87 .\"O function returns a pointer to a structure containing
88 .\"O the broken-out fields of the record in the password database
89 .\"O (e.g., the local password file
90 .\"O .IR /etc/passwd ,
91 .\"O NIS, and LDAP)
92 .\"O that matches the username
93 .\"O .IR name .
94 .BR getpwnam ()
95 ´Ø¿ô¤Ï¡¢¥æ¡¼¥¶Ì¾
96 .I name
97 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
98 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹
99 (¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÎã:
100 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë
101 .IR /etc/passwd ,
102 NIS, LDAP)¡£
103 .PP
104 .\"O The
105 .\"O .BR getpwuid ()
106 .\"O function returns a pointer to a structure containing
107 .\"O the broken-out fields of the record in the password database
108 .\"O that matches the user ID
109 .\"O .IR uid .
110 .BR getpwuid ()
111 ´Ø¿ô¤Ï¡¢¥æ¡¼¥¶ ID
112 .I uid
113 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
114 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
115 .PP
116 .\"O The
117 .\"O .BR getpwnam_r ()
118 .\"O and
119 .\"O .BR getpwuid_r ()
120 .\"O functions obtain the same information, but store the retrieved
121 .\"O .I passwd
122 .\"O structure in the space pointed to by
123 .\"O .IR pwd .
124 .BR getpwnam_r ()
125 ¤È
126 .BR getpwuid_r ()
127 ´Ø¿ô¤Ï (¾åµ­¤Î´Ø¿ô¤È) Æ±¤¸¾ðÊó¤ò¼èÆÀ¤¹¤ë¤¬¡¢
128 ¼èÆÀ¤·¤¿
129 .I passwd
130 ¹½Â¤ÂΤò
131 .I pwd
132 ¤¬»Ø¤¹Îΰè¤Ë³ÊǼ¤¹¤ë¡£
133 .\"O This
134 .\"O .I passwd
135 .\"O structure contains pointers to strings, and these strings
136 .\"O are stored in the buffer
137 .\"O .I buf
138 .\"O of size
139 .\"O .IR buflen .
140 ¤³¤Î
141 .I passwd
142 ¹½Â¤ÂΤˤÏʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬´Þ¤Þ¤ì¡¢
143 ¤³¤ì¤é¤Îʸ»úÎó¤Ï¥µ¥¤¥º
144 .I buflen
145 ¤Î¥Ð¥Ã¥Õ¥¡
146 .I buf
147 ¤Ë³ÊǼ¤µ¤ì¤ë¡£
148 .\"O A pointer to the result (in case of success) or NULL (in case no entry
149 .\"O was found or an error occurred) is stored in
150 .\"O .IR *result .
151 À®¸ù¤·¤¿¾ì¹ç
152 .I *result
153 ¤Ë¤Ï·ë²Ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬³ÊǼ¤µ¤ì¤ë¡£
154 ¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤Ï
155 .I *result
156 ¤Ë¤Ï NULL ¤¬Æþ¤ë¡£
157 .PP
158 .\"O The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
159 \fIpasswd\fP ¹½Â¤ÂΤϡ¢\fI<pwd.h>\fP ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
160 .sp
161 .in +4n
162 .nf
163 struct passwd {
164 .\"O     char   *pw_name;       /* username */
165 .\"O     char   *pw_passwd;     /* user password */
166 .\"O     uid_t   pw_uid;        /* user ID */
167 .\"O     gid_t   pw_gid;        /* group ID */
168 .\"O     char   *pw_gecos;      /* real name */
169 .\"O     char   *pw_dir;        /* home directory */
170 .\"O     char   *pw_shell;      /* shell program */
171     char   *pw_name;       /* ¥æ¡¼¥¶Ì¾ */
172     char   *pw_passwd;     /* ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É */
173     uid_t   pw_uid;        /* ¥æ¡¼¥¶ ID */
174     gid_t   pw_gid;        /* ¥°¥ë¡¼¥× ID */
175     char   *pw_gecos;      /* ¼Â̾ */
176     char   *pw_dir;        /* ¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê */
177     char   *pw_shell;      /* ¥·¥§¥ë¥×¥í¥°¥é¥à */
178 };
179 .fi
180 .in
181 .PP
182 .\"O The maximum needed size for
183 .\"O .I buf
184 .\"O can be found using
185 .\"O .BR sysconf (3)
186 .\"O with the argument
187 .\"O .BR _SC_GETPW_R_SIZE_MAX .
188 .I buf
189 ¤ËºÇÂçɬÍפʥµ¥¤¥º¤Ï¡¢
190 .BR sysconf (3)
191 ¤Ë°ú¤­¿ô
192 .B _SC_GETPW_R_SIZE_MAX
193 ¤ò»ØÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤³¤È¤Çʬ¤«¤ë¡£
194 .\"O .SH "RETURN VALUE"
195 .SH ÊÖ¤êÃÍ
196 .\"O The
197 .\"O .BR getpwnam ()
198 .\"O and
199 .\"O .BR getpwuid ()
200 .\"O functions return a pointer to a
201 .\"O .I passwd
202 .\"O structure, or NULL if the matching entry is not found or
203 .\"O an error occurs.
204 .BR getpwnam ()
205 ¤È
206 .BR getpwuid ()
207 ´Ø¿ô¤Ï¡¢
208 .I passwd
209 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
210 °ìÃפ¹¤ë¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£
211 .\"O If an error occurs,
212 .\"O .I errno
213 .\"O is set appropriately.
214 .\"O If one wants to check
215 .\"O .I errno
216 .\"O after the call, it should be set to zero before the call.
217 ¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¾ì¹ç¡¢
218 .I errno
219 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
220 ¸Æ¤Ó½Ð¤·¤Î¸å¤Ç
221 .I errno
222 ¤ò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
223 ¸Æ¤Ó½Ð¤·¤ÎÁ°¤Ë (¤³¤ÎÃͤò) 0 ¤ËÀßÄꤷ¤Æ¤ª¤¯¤Ù¤­¤Ç¤¢¤ë¡£
224 .LP
225 .\"O The return value may point to a static area, and may be overwritten
226 .\"O by subsequent calls to
227 .\"O .BR getpwent (3),
228 .\"O .BR getpwnam (),
229 .\"O or
230 .\"O .BR getpwuid ().
231 .\"O (Do not pass the returned pointer to
232 .\"O .BR free (3).)
233 ÊÖ¤êÃͤÏÀÅŪ¤ÊÎΰè¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤½¤Î¸å¤Î
234 .BR getpwent (3),
235 .BR getpwnam (),
236 .BR getpwuid ()
237 ¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤­¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
238 (ÊÖ¤µ¤ì¤¿¥Ý¥¤¥ó¥¿¤ò
239 .BR free (3)
240 ¤ËÅϤµ¤Ê¤¤¤³¤È¡£)
241 .LP
242 .\"O On success,
243 .\"O .BR getpwnam_r ()
244 .\"O and
245 .\"O .BR getpwuid_r ()
246 .\"O return zero, and set
247 .\"O .IR *result
248 .\"O to
249 .\"O .IR pwd .
250 .\"O If no matching password record was found,
251 .\"O these functions return 0 and store NULL in
252 .\"O .IR *result .
253 .\"O In case of error, an error number is returned, and NULL is stored in
254 .\"O .IR *result .
255 À®¸ù¤¹¤ë¤È¡¢
256 .BR getpwnam_r ()
257 ¤È
258 .BR getpwuid_r ()
259 ¤Ï 0 ¤òÊÖ¤·¡¢
260 .I *result
261 ¤Ë
262 .I pwd
263 ¤òÀßÄꤹ¤ë¡£
264 ¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
265 0 ¤òÊÖ¤·¡¢
266 .I *result
267 ¤Ë NULL ¤òÀßÄꤹ¤ë¡£
268 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤·¡¢
269 .I *result
270 ¤Ë NULL ¤òÀßÄꤹ¤ë¡£
271 .\"O .SH ERRORS
272 .SH ¥¨¥é¡¼
273 .TP
274 .\"O .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
275 .BR 0 " ¤Þ¤¿¤Ï " ENOENT " ¤Þ¤¿¤Ï " ESRCH " ¤Þ¤¿¤Ï " EBADF " ¤Þ¤¿¤Ï " EPERM " ¤Þ¤¿¤Ï ... "
276 .\"O The given
277 .\"O .I name
278 .\"O or
279 .\"O .I uid
280 .\"O was not found.
281 »ØÄꤵ¤ì¤¿
282 .I name
283 ¤Þ¤¿¤Ï
284 .I uid
285 ¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
286 .TP
287 .B EINTR
288 .\"O A signal was caught.
289 ¥·¥°¥Ê¥ë¤¬¥­¥ã¥Ã¥Á¤µ¤ì¤¿¡£
290 .TP
291 .B EIO
292 .\"O I/O error.
293 I/O ¥¨¥é¡¼¡£
294 .TP
295 .B EMFILE
296 .\"O The maximum number
297 .\"O .RB ( OPEN_MAX )
298 .\"O of files was open already in the calling process.
299 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Ë¤ª¤¤¤Æ¡¢
300 ´û¤ËºÇÂç¿ô (OPEN_MAX) ¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
301 .TP
302 .B ENFILE
303 .\"O The maximum number of files was open already in the system.
304 ¥·¥¹¥Æ¥à¾å¤Ç´û¤ËºÇÂç¿ô¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
305 .TP
306 .B ENOMEM
307 .\" not in POSIX
308 .\"O Insufficient memory to allocate
309 .\"O .I passwd
310 .\"O structure.
311 .\"O .\" This structure is static, allocated 0 or 1 times. No memory leak. (libc45)
312 .\" POSIX ¤Ë¤Ï¤Ê¤¤¡£
313 .I passwd
314 ¹½Â¤ÂΤò³ä¤êÅö¤Æ¤ë¤¿¤á¤Î¥á¥â¥ê¤¬ÉÔ½½Ê¬¡£
315 .\" ¤³¤Î¹½Â¤ÂΤÏÀÅŪ¤Ç¤¢¤ê¡¢0 ²ó¤Þ¤¿¤Ï 1 ²ó³ä¤êÅö¤Æ¤é¤ì¤ë¡£
316 .\" ¥á¥â¥ê¥ê¡¼¥¯¤Ï̵¤¤¡£(libc45)
317 .TP
318 .B ERANGE
319 .\"O Insufficient buffer space supplied.
320 Í¿¤¨¤é¤ì¤¿¥Ð¥Ã¥Õ¥¡¶õ´Ö¤¬ÉÔ½½Ê¬¤Ç¤¢¤ë¡£
321 .\"O .SH FILES
322 .SH ¥Õ¥¡¥¤¥ë
323 .TP
324 .I /etc/passwd
325 .\"O local password database file
326 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë
327 .\"O .SH "CONFORMING TO"
328 .SH ½àµò
329 SVr4, 4.3BSD, POSIX.1-2001.
330 .\"O .SH NOTES
331 .SH Ãí°Õ
332 .\"O The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
333 ¾åµ­¤Î¡ÖÊÖ¤êÃ͡װʲ¼¤Îµ­½Ò¤Ï POSIX.1-2001 ¤Ëµò¤ë¡£
334 .\"O It does not call "not found" an error, and hence does not specify what value
335 .\"O .I errno
336 .\"O might have in this situation.
337 .\"O But that makes it impossible to recognize
338 .\"O errors.
339 .\"O One might argue that according to POSIX
340 .\"O .I errno
341 .\"O should be left unchanged if an entry is not found.
342 .\"O Experiments on various
343 .\"O UNIX-like systems show that lots of different values occur in this
344 .\"O situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
345 ¤³¤Îɸ½à¤Ï¡Ö(¥¨¥ó¥È¥ê¤¬) ¸«¤Ä¤«¤é¤Ê¤¤¤³¤È¡×¤ò¥¨¥é¡¼¤È¤·¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢
346 ¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë
347 .I errno
348 ¤¬¤É¤Î¤è¤¦¤ÊÃͤˤʤ뤫¤òÄê¤á¤Æ¤¤¤Ê¤¤¡£
349 ¤½¤Î¤¿¤á¡¢¥¨¥é¡¼¤òǧ¼±¤¹¤ë¤³¤È¤ÏÉÔ²Äǽ¤Ç¤¢¤ë¡£
350 POSIX ¤Ë½àµò¤·¤Æ¡¢¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï
351 .I errno
352 ¤òÊѹ¹¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡¢¤È¼çÄ¥¤¹¤ë¿Í¤â¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
353 ÍÍ¡¹¤Ê UNIX ·Ï¤Î¥·¥¹¥Æ¥à¤Ç»î¤·¤Æ¤ß¤ë¤È¡¢¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë¤Ï
354 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM ¤È¤¤¤Ã¤¿ÍÍ¡¹¤ÊÃͤ¬ÊÖ¤µ¤ì¤ë¡£
355 ¾¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
356 .\"O .\" more precisely:
357 .\"O .\" AIX 5.1 - gives ESRCH
358 .\"O .\" OSF1 4.0g - gives EWOULDBLOCK
359 .\"O .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
360 .\"O .\" glibc since version 2.7 - give 0
361 .\"O .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
362 .\"O .\" SunOS 5.8 - gives EBADF
363 .\"O .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
364 .\" ¤è¤êÀµ³Î¤Ë¤Ï:
365 .\" AIX 5.1 ¤Ï ESRCH ¤òÊÖ¤¹¡£
366 .\" OSF1 4.0g ¤Ï EWOULDBLOCK ¤òÊÖ¤¹¡£
367 .\" libc, glibc (¥Ð¡¼¥¸¥ç¥ó 2.6 ¤Þ¤Ç), Irix 6.5 ¤Ï ENOENT ¤òÊÖ¤¹¡£
368 .\" glibc (¥Ð¡¼¥¸¥ç¥ó 2.7 °Ê¹ß) ¤Ï 0 ¤òÊÖ¤¹¡£
369 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 ¤Ï EPERM ¤òÊÖ¤¹¡£
370 .\" SunOS 5.8 ¤Ï EBADF ¤òÊÖ¤¹¡£
371 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 ¤Ï 0 ¤òÊÖ¤¹¡£
372
373 .\"O The
374 .\"O .I pw_dir
375 .\"O field contains the name of the initial working directory of the user.
376 ¥Õ¥£¡¼¥ë¥É
377 .I pw_dir
378 ¤Ë¤Ï¡¢¥æ¡¼¥¶¤Îºî¶È¥Ç¥£¥ì¥¯¥È¥ê̾¤Î½é´üÃͤ¬³ÊǼ¤µ¤ì¤ë¡£
379 .\"O Login programs use the value of this field to initialize the
380 .\"O .B HOME
381 .\"O environment variable for the login shell.
382 .\"O An application that wants to determine its user's home directory
383 .\"O should inspect the value of
384 .\"O .B HOME
385 .\"O (rather than the value
386 .\"O .IR getpwuid(getuid())\->pw_dir )
387 .\"O since this allows the user to modify their notion of
388 .\"O "the home directory" during a login session.
389 .\"O To determine the (initial) home directory of another user,
390 .\"O it is necessary to use
391 .\"O .I getpwnam("username")\->pw_dir
392 .\"O or similar.
393 ¥í¥°¥¤¥ó¥×¥í¥»¥¹¤Ï¡¢¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÎÃͤò»È¤Ã¤Æ¡¢
394 ¥í¥°¥¤¥ó¥·¥§¥ë¤Î
395 .B HOME
396 ´Ä¶­ÊÑ¿ô¤ò½é´ü²½¤¹¤ë¡£
397 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¡¢¥æ¡¼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¤ò·èÄꤹ¤ë¾ì¹ç¤Ë¤Ï¡¢
398 .RI ( getpwuid(getuid())\->pw_dir
399 ¤ÎÃͤǤϤʤ¯)
400 .B HOME
401 ¤ÎÃͤò¸¡ºº¤¹¤ë¤è¤¦¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
402 ¤Ê¤¼¤Ê¤é¡¢¤³¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¡¢¥æ¡¼¥¶¤¬¥í¥°¥¤¥ó¡¦¥»¥Ã¥·¥ç¥óÃæ¤Ç
403 ¡Ö¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¡×¤Î°ÕÌ£¤òÊѹ¹¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¤«¤é¤Ç¤¢¤ë¡£
404 Ê̤Υ桼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê (¤Î½é´üÃÍ) ¤òÃΤë¤Ë¤Ï
405 .I getpwnam("username")\->pw_dir
406 ¤«Æ±ÍͤÎÊýË¡¤ò»È¤¦É¬Íפ¬¤¢¤ë¡£
407 .\"O .SH EXAMPLE
408 .SH Îã
409 .\"O The program below demonstrates the use of
410 .\"O .BR getpwnam_r ()
411 .\"O to find the full username and user ID for the username
412 .\"O supplied as a command-line argument.
413 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï
414 .BR getpwnam_r ()
415 ¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤ÇÅϤµ¤ì¤¿¥æ¡¼¥¶Ì¾¤ËÂФ¹¤ë
416 ´°Á´¤Ê¥æ¡¼¥¶Ì¾¤È¥æ¡¼¥¶ ID ¤òõ¤¹¤â¤Î¤Ç¤¢¤ë¡£
417
418 .nf
419 #include <pwd.h>
420 #include <stdio.h>
421 #include <stdlib.h>
422 #include <unistd.h>
423 #include <errno.h>
424
425 int
426 main(int argc, char *argv[])
427 {
428     struct passwd pwd;
429     struct passwd *result;
430     char *buf;
431     size_t bufsize;
432     int s;
433
434     if (argc != 2) {
435         fprintf(stderr, "Usage: %s username\\n", argv[0]);
436         exit(EXIT_FAILURE);
437     }
438
439     bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
440 .\"O     if (bufsize == \-1)          /* Value was indeterminate */
441 .\"O         bufsize = 16384;        /* Should be more than enough */
442     if (bufsize == \-1)          /* Ãͤò·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿ */
443         bufsize = 16384;        /* ½½Ê¬Â礭¤ÊÃͤˤ¹¤Ù¤­ */
444
445     buf = malloc(bufsize);
446     if (buf == NULL) {
447         perror("malloc");
448         exit(EXIT_FAILURE);
449     }
450
451     s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
452     if (result == NULL) {
453         if (s == 0)
454             printf("Not found\\n");
455         else {
456             errno = s;
457             perror("getpwnam_r");
458         }
459         exit(EXIT_FAILURE);
460     }
461
462     printf("Name: %s; UID: %ld\\n", pwd.pw_gecos, (long) pwd.pw_uid);
463     exit(EXIT_SUCCESS);
464 }
465 .fi
466 .\"O .SH "SEE ALSO"
467 .SH ´ØÏ¢¹àÌÜ
468 .BR endpwent (3),
469 .BR fgetpwent (3),
470 .BR getgrnam (3),
471 .BR getpw (3),
472 .BR getpwent (3),
473 .BR getspnam (3),
474 .BR putpwent (3),
475 .BR setpwent (3),
476 .BR passwd (5)