OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
79 _SVID_SOURCE || _POSIX_SOURCE
80 .ad b
81 .\"O .SH DESCRIPTION
82 .SH ÀâÌÀ
83 .\"O The
84 .\"O .BR getpwnam ()
85 .\"O function returns a pointer to a structure containing
86 .\"O the broken-out fields of the record in the password database
87 .\"O (e.g., the local password file
88 .\"O .IR /etc/passwd ,
89 .\"O NIS, and LDAP)
90 .\"O that matches the username
91 .\"O .IR name .
92 .BR getpwnam ()
93 ´Ø¿ô¤Ï¡¢¥æ¡¼¥¶Ì¾
94 .I name
95 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
96 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹
97 (¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÎã:
98 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë
99 .IR /etc/passwd ,
100 NIS, LDAP)¡£
101 .PP
102 .\"O The
103 .\"O .BR getpwuid ()
104 .\"O function returns a pointer to a structure containing
105 .\"O the broken-out fields of the record in the password database
106 .\"O that matches the user ID
107 .\"O .IR uid .
108 .BR getpwuid ()
109 ´Ø¿ô¤Ï¡¢¥æ¡¼¥¶ ID
110 .I uid
111 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
112 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
113 .PP
114 .\"O The
115 .\"O .BR getpwnam_r ()
116 .\"O and
117 .\"O .BR getpwuid_r ()
118 .\"O functions obtain the same information, but store the retrieved
119 .\"O .I passwd
120 .\"O structure in the space pointed to by
121 .\"O .IR pwd .
122 .BR getpwnam_r ()
123 ¤È
124 .BR getpwuid_r ()
125 ´Ø¿ô¤Ï (¾åµ­¤Î´Ø¿ô¤È) Æ±¤¸¾ðÊó¤ò¼èÆÀ¤¹¤ë¤¬¡¢
126 ¼èÆÀ¤·¤¿
127 .I passwd
128 ¹½Â¤ÂΤò
129 .I pwd
130 ¤¬»Ø¤¹Îΰè¤Ë³ÊǼ¤¹¤ë¡£
131 .\"O This
132 .\"O .I passwd
133 .\"O structure contains pointers to strings, and these strings
134 .\"O are stored in the buffer
135 .\"O .I buf
136 .\"O of size
137 .\"O .IR buflen .
138 ¤³¤Î
139 .I passwd
140 ¹½Â¤ÂΤˤÏʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬´Þ¤Þ¤ì¡¢
141 ¤³¤ì¤é¤Îʸ»úÎó¤Ï¥µ¥¤¥º
142 .I buflen
143 ¤Î¥Ð¥Ã¥Õ¥¡
144 .I buf
145 ¤Ë³ÊǼ¤µ¤ì¤ë¡£
146 .\"O A pointer to the result (in case of success) or NULL (in case no entry
147 .\"O was found or an error occurred) is stored in
148 .\"O .IR *result .
149 À®¸ù¤·¤¿¾ì¹ç
150 .I *result
151 ¤Ë¤Ï·ë²Ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬³ÊǼ¤µ¤ì¤ë¡£
152 ¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤Ï
153 .I *result
154 ¤Ë¤Ï NULL ¤¬Æþ¤ë¡£
155 .PP
156 .\"O The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
157 \fIpasswd\fP ¹½Â¤ÂΤϡ¢\fI<pwd.h>\fP ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
158 .sp
159 .in +4n
160 .nf
161 struct passwd {
162 .\"O     char   *pw_name;       /* username */
163 .\"O     char   *pw_passwd;     /* user password */
164 .\"O     uid_t   pw_uid;        /* user ID */
165 .\"O     gid_t   pw_gid;        /* group ID */
166 .\"O     char   *pw_gecos;      /* real name */
167 .\"O     char   *pw_dir;        /* home directory */
168 .\"O     char   *pw_shell;      /* shell program */
169     char   *pw_name;       /* ¥æ¡¼¥¶Ì¾ */
170     char   *pw_passwd;     /* ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É */
171     uid_t   pw_uid;        /* ¥æ¡¼¥¶ ID */
172     gid_t   pw_gid;        /* ¥°¥ë¡¼¥× ID */
173     char   *pw_gecos;      /* ¼Â̾ */
174     char   *pw_dir;        /* ¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê */
175     char   *pw_shell;      /* ¥·¥§¥ë¥×¥í¥°¥é¥à */
176 };
177 .fi
178 .in
179 .PP
180 .\"O The maximum needed size for
181 .\"O .I buf
182 .\"O can be found using
183 .\"O .BR sysconf (3)
184 .\"O with the argument
185 .\"O .BR _SC_GETPW_R_SIZE_MAX .
186 .I buf
187 ¤ËºÇÂçɬÍפʥµ¥¤¥º¤Ï¡¢
188 .BR sysconf (3)
189 ¤Ë°ú¤­¿ô
190 .B _SC_GETPW_R_SIZE_MAX
191 ¤ò»ØÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤³¤È¤Çʬ¤«¤ë¡£
192 .\"O .SH "RETURN VALUE"
193 .SH ÊÖ¤êÃÍ
194 .\"O The
195 .\"O .BR getpwnam ()
196 .\"O and
197 .\"O .BR getpwuid ()
198 .\"O functions return a pointer to a
199 .\"O .I passwd
200 .\"O structure, or NULL if the matching entry is not found or
201 .\"O an error occurs.
202 .BR getpwnam ()
203 ¤È
204 .BR getpwuid ()
205 ´Ø¿ô¤Ï¡¢
206 .I passwd
207 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
208 °ìÃפ¹¤ë¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£
209 .\"O If an error occurs,
210 .\"O .I errno
211 .\"O is set appropriately.
212 .\"O If one wants to check
213 .\"O .I errno
214 .\"O after the call, it should be set to zero before the call.
215 ¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¾ì¹ç¡¢
216 .I errno
217 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
218 ¸Æ¤Ó½Ð¤·¤Î¸å¤Ç
219 .I errno
220 ¤ò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
221 ¸Æ¤Ó½Ð¤·¤ÎÁ°¤Ë (¤³¤ÎÃͤò) 0 ¤ËÀßÄꤷ¤Æ¤ª¤¯¤Ù¤­¤Ç¤¢¤ë¡£
222 .LP
223 .\"O The return value may point to a static area, and may be overwritten
224 .\"O by subsequent calls to
225 .\"O .BR getpwent (3),
226 .\"O .BR getpwnam (),
227 .\"O or
228 .\"O .BR getpwuid ().
229 .\"O (Do not pass the returned pointer to
230 .\"O .BR free (3).)
231 ÊÖ¤êÃͤÏÀÅŪ¤ÊÎΰè¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤½¤Î¸å¤Î
232 .BR getpwent (3),
233 .BR getpwnam (),
234 .BR getpwuid ()
235 ¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤­¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
236 (ÊÖ¤µ¤ì¤¿¥Ý¥¤¥ó¥¿¤ò
237 .BR free (3)
238 ¤ËÅϤµ¤Ê¤¤¤³¤È¡£)
239 .LP
240 .\"O On success,
241 .\"O .BR getpwnam_r ()
242 .\"O and
243 .\"O .BR getpwuid_r ()
244 .\"O return zero, and set
245 .\"O .IR *result
246 .\"O to
247 .\"O .IR pwd .
248 .\"O If no matching password record was found,
249 .\"O these functions return 0 and store NULL in
250 .\"O .IR *result .
251 .\"O In case of error, an error number is returned, and NULL is stored in
252 .\"O .IR *result .
253 À®¸ù¤¹¤ë¤È¡¢
254 .BR getpwnam_r ()
255 ¤È
256 .BR getpwuid_r ()
257 ¤Ï 0 ¤òÊÖ¤·¡¢
258 .I *result
259 ¤Ë
260 .I pwd
261 ¤òÀßÄꤹ¤ë¡£
262 ¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
263 0 ¤òÊÖ¤·¡¢
264 .I *result
265 ¤Ë NULL ¤òÀßÄꤹ¤ë¡£
266 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤·¡¢
267 .I *result
268 ¤Ë NULL ¤òÀßÄꤹ¤ë¡£
269 .\"O .SH ERRORS
270 .SH ¥¨¥é¡¼
271 .TP
272 .\"O .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
273 .BR 0 " ¤Þ¤¿¤Ï " ENOENT " ¤Þ¤¿¤Ï " ESRCH " ¤Þ¤¿¤Ï " EBADF " ¤Þ¤¿¤Ï " EPERM " ¤Þ¤¿¤Ï ... "
274 .\"O The given
275 .\"O .I name
276 .\"O or
277 .\"O .I uid
278 .\"O was not found.
279 »ØÄꤵ¤ì¤¿
280 .I name
281 ¤Þ¤¿¤Ï
282 .I uid
283 ¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
284 .TP
285 .B EINTR
286 .\"O A signal was caught.
287 ¥·¥°¥Ê¥ë¤¬¥­¥ã¥Ã¥Á¤µ¤ì¤¿¡£
288 .TP
289 .B EIO
290 .\"O I/O error.
291 I/O ¥¨¥é¡¼¡£
292 .TP
293 .B EMFILE
294 .\"O The maximum number
295 .\"O .RB ( OPEN_MAX )
296 .\"O of files was open already in the calling process.
297 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Ë¤ª¤¤¤Æ¡¢
298 ´û¤ËºÇÂç¿ô (OPEN_MAX) ¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
299 .TP
300 .B ENFILE
301 .\"O The maximum number of files was open already in the system.
302 ¥·¥¹¥Æ¥à¾å¤Ç´û¤ËºÇÂç¿ô¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
303 .TP
304 .B ENOMEM
305 .\" not in POSIX
306 .\"O Insufficient memory to allocate
307 .\"O .I passwd
308 .\"O structure.
309 .\"O .\" This structure is static, allocated 0 or 1 times. No memory leak. (libc45)
310 .\" POSIX ¤Ë¤Ï¤Ê¤¤¡£
311 .I passwd
312 ¹½Â¤ÂΤò³ä¤êÅö¤Æ¤ë¤¿¤á¤Î¥á¥â¥ê¤¬ÉÔ½½Ê¬¡£
313 .\" ¤³¤Î¹½Â¤ÂΤÏÀÅŪ¤Ç¤¢¤ê¡¢0 ²ó¤Þ¤¿¤Ï 1 ²ó³ä¤êÅö¤Æ¤é¤ì¤ë¡£
314 .\" ¥á¥â¥ê¥ê¡¼¥¯¤Ï̵¤¤¡£(libc45)
315 .TP
316 .B ERANGE
317 .\"O Insufficient buffer space supplied.
318 Í¿¤¨¤é¤ì¤¿¥Ð¥Ã¥Õ¥¡¶õ´Ö¤¬ÉÔ½½Ê¬¤Ç¤¢¤ë¡£
319 .\"O .SH FILES
320 .SH ¥Õ¥¡¥¤¥ë
321 .TP
322 .I /etc/passwd
323 .\"O local password database file
324 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë
325 .\"O .SH "CONFORMING TO"
326 .SH ½àµò
327 SVr4, 4.3BSD, POSIX.1-2001.
328 .\"O .SH NOTES
329 .SH Ãí°Õ
330 .\"O The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
331 ¾åµ­¤Î¡ÖÊÖ¤êÃ͡װʲ¼¤Îµ­½Ò¤Ï POSIX.1-2001 ¤Ëµò¤ë¡£
332 .\"O It does not call "not found" an error, and hence does not specify what value
333 .\"O .I errno
334 .\"O might have in this situation.
335 .\"O But that makes it impossible to recognize
336 .\"O errors.
337 .\"O One might argue that according to POSIX
338 .\"O .I errno
339 .\"O should be left unchanged if an entry is not found.
340 .\"O Experiments on various
341 .\"O Unix-like systems show that lots of different values occur in this
342 .\"O situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
343 ¤³¤Îɸ½à¤Ï¡Ö(¥¨¥ó¥È¥ê¤¬) ¸«¤Ä¤«¤é¤Ê¤¤¤³¤È¡×¤ò¥¨¥é¡¼¤È¤·¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢
344 ¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë
345 .I errno
346 ¤¬¤É¤Î¤è¤¦¤ÊÃͤˤʤ뤫¤òÄê¤á¤Æ¤¤¤Ê¤¤¡£
347 ¤½¤Î¤¿¤á¡¢¥¨¥é¡¼¤òǧ¼±¤¹¤ë¤³¤È¤ÏÉÔ²Äǽ¤Ç¤¢¤ë¡£
348 POSIX ¤Ë½àµò¤·¤Æ¡¢¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï
349 .I errno
350 ¤òÊѹ¹¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡¢¤È¼çÄ¥¤¹¤ë¿Í¤â¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
351 ÍÍ¡¹¤Ê Unix ·Ï¤Î¥·¥¹¥Æ¥à¤Ç»î¤·¤Æ¤ß¤ë¤È¡¢¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë¤Ï
352 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM ¤È¤¤¤Ã¤¿ÍÍ¡¹¤ÊÃͤ¬ÊÖ¤µ¤ì¤ë¡£
353 ¾¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
354 .\"O .\" more precisely:
355 .\"O .\" AIX 5.1 - gives ESRCH
356 .\"O .\" OSF1 4.0g - gives EWOULDBLOCK
357 .\"O .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
358 .\"O .\" glibc since version 2.7 - give 0
359 .\"O .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
360 .\"O .\" SunOS 5.8 - gives EBADF
361 .\"O .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
362 .\" ¤è¤êÀµ³Î¤Ë¤Ï:
363 .\" AIX 5.1 ¤Ï ESRCH ¤òÊÖ¤¹¡£
364 .\" OSF1 4.0g ¤Ï EWOULDBLOCK ¤òÊÖ¤¹¡£
365 .\" libc, glibc (¥Ð¡¼¥¸¥ç¥ó 2.6 ¤Þ¤Ç), Irix 6.5 ¤Ï ENOENT ¤òÊÖ¤¹¡£
366 .\" glibc (¥Ð¡¼¥¸¥ç¥ó 2.7 °Ê¹ß) ¤Ï 0 ¤òÊÖ¤¹¡£
367 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 ¤Ï EPERM ¤òÊÖ¤¹¡£
368 .\" SunOS 5.8 ¤Ï EBADF ¤òÊÖ¤¹¡£
369 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 ¤Ï 0 ¤òÊÖ¤¹¡£
370
371 .\"O The
372 .\"O .I pw_dir
373 .\"O field contains the name of the initial working directory of the user.
374 ¥Õ¥£¡¼¥ë¥É
375 .I pw_dir
376 ¤Ë¤Ï¡¢¥æ¡¼¥¶¤Îºî¶È¥Ç¥£¥ì¥¯¥È¥ê̾¤Î½é´üÃͤ¬³ÊǼ¤µ¤ì¤ë¡£
377 .\"O Login programs use the value of this field to initialize the
378 .\"O .B HOME
379 .\"O environment variable for the login shell.
380 .\"O An application that wants to determine its user's home directory
381 .\"O should inspect the value of
382 .\"O .B HOME
383 .\"O (rather than the value
384 .\"O .IR getpwuid(getuid())\->pw_dir )
385 .\"O since this allows the user to modify their notion of
386 .\"O "the home directory" during a login session.
387 .\"O To determine the (initial) home directory of another user,
388 .\"O it is necessary to use
389 .\"O .I getpwnam("username")\->pw_dir
390 .\"O or similar.
391 ¥í¥°¥¤¥ó¥×¥í¥»¥¹¤Ï¡¢¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÎÃͤò»È¤Ã¤Æ¡¢
392 ¥í¥°¥¤¥ó¥·¥§¥ë¤Î
393 .B HOME
394 ´Ä¶­ÊÑ¿ô¤ò½é´ü²½¤¹¤ë¡£
395 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¡¢¥æ¡¼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¤ò·èÄꤹ¤ë¾ì¹ç¤Ë¤Ï¡¢
396 .RI ( getpwuid(getuid())\->pw_dir
397 ¤ÎÃͤǤϤʤ¯)
398 .B HOME
399 ¤ÎÃͤò¸¡ºº¤¹¤ë¤è¤¦¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
400 ¤Ê¤¼¤Ê¤é¡¢¤³¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¡¢¥æ¡¼¥¶¤¬¥í¥°¥¤¥ó¡¦¥»¥Ã¥·¥ç¥óÃæ¤Ç
401 ¡Ö¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¡×¤Î°ÕÌ£¤òÊѹ¹¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¤«¤é¤Ç¤¢¤ë¡£
402 Ê̤Υ桼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê (¤Î½é´üÃÍ) ¤òÃΤë¤Ë¤Ï
403 .I getpwnam("username")\->pw_dir
404 ¤«Æ±ÍͤÎÊýË¡¤ò»È¤¦É¬Íפ¬¤¢¤ë¡£
405 .\"O .SH EXAMPLE
406 .SH Îã
407 .\"O The program below demonstrates the use of
408 .\"O .BR getpwnam_r ()
409 .\"O to find the full username and user ID for the username
410 .\"O supplied as a command-line argument.
411 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï
412 .BR getpwnam_r ()
413 ¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤ÇÅϤµ¤ì¤¿¥æ¡¼¥¶Ì¾¤ËÂФ¹¤ë
414 ´°Á´¤Ê¥æ¡¼¥¶Ì¾¤È¥æ¡¼¥¶ ID ¤òõ¤¹¤â¤Î¤Ç¤¢¤ë¡£
415
416 .nf
417 #include <pwd.h>
418 #include <stdio.h>
419 #include <stdlib.h>
420 #include <unistd.h>
421 #include <errno.h>
422
423 int
424 main(int argc, char *argv[])
425 {
426     struct passwd pwd;
427     struct passwd *result;
428     char *buf;
429     size_t bufsize;
430     int s;
431
432     if (argc != 2) {
433         fprintf(stderr, "Usage: %s username\\n", argv[0]);
434         exit(EXIT_FAILURE);
435     }
436
437     bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
438 .\"O     if (bufsize == \-1)          /* Value was indeterminate */
439 .\"O         bufsize = 16384;        /* Should be more than enough */
440     if (bufsize == \-1)          /* Ãͤò·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿ */
441         bufsize = 16384;        /* ½½Ê¬Â礭¤ÊÃͤˤ¹¤Ù¤­ */
442
443     buf = malloc(bufsize);
444     if (buf == NULL) {
445         perror("malloc");
446         exit(EXIT_FAILURE);
447     }
448
449     s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
450     if (result == NULL) {
451         if (s == 0)
452             printf("Not found\\n");
453         else {
454             errno = s;
455             perror("getpwnam_r");
456         }
457         exit(EXIT_FAILURE);
458     }
459
460     printf("Name: %s; UID: %ld\\n", pwd.pw_gecos, (long) pwd.pw_uid);
461     exit(EXIT_SUCCESS);
462 }
463 .fi
464 .\"O .SH "SEE ALSO"
465 .SH ´ØÏ¢¹àÌÜ
466 .BR endpwent (3),
467 .BR fgetpwent (3),
468 .BR getgrnam (3),
469 .BR getpw (3),
470 .BR getpwent (3),
471 .BR getspnam (3),
472 .BR putpwent (3),
473 .BR setpwent (3),
474 .BR passwd (5)