1GETPWNAM(3P)               POSIX Programmer's Manual              GETPWNAM(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       getpwnam, getpwnam_r - search user database for a name
13

SYNOPSIS

15       #include <pwd.h>
16
17       struct passwd *getpwnam(const char *name);
18
19
20       int getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
21              size_t bufsize, struct passwd **result);
22
23

DESCRIPTION

25       The getpwnam() function shall search the user  database  for  an  entry
26       with a matching name.
27
28       The  getpwnam()  function need not be reentrant. A function that is not
29       required to be reentrant is not required to be thread-safe.
30
31       Applications wishing to check for error situations should set errno  to
32       0  before  calling getpwnam(). If getpwnam() returns a null pointer and
33       errno is non-zero, an error occurred.
34
35       The getpwnam_r() function shall update the passwd structure pointed  to
36       by pwd and store a pointer to that structure at the location pointed to
37       by result. The structure shall contain an entry from the user  database
38       with  a matching name. Storage referenced by the structure is allocated
39       from the memory provided with the buffer parameter,  which  is  bufsize
40       bytes  in  size.  The maximum size needed for this buffer can be deter‐
41       mined with  the  {_SC_GETPW_R_SIZE_MAX}  sysconf()  parameter.  A  NULL
42       pointer shall be returned at the location pointed to by result on error
43       or if the requested entry is not found.
44

RETURN VALUE

46       The getpwnam() function shall return a pointer to a struct passwd  with
47       the  structure  as defined in <pwd.h> with a matching entry if found. A
48       null pointer shall be returned if the requested entry is not found,  or
49       an error occurs. On error, errno shall be set to indicate the error.
50
51       The  return  value may point to a static area which is overwritten by a
52       subsequent call to getpwent(), getpwnam(), or getpwuid().
53
54       If successful, the getpwnam_r() function shall return zero;  otherwise,
55       an error number shall be returned to indicate the error.
56

ERRORS

58       The getpwnam() and getpwnam_r() functions may fail if:
59
60       EIO    An I/O error has occurred.
61
62       EINTR  A signal was caught during getpwnam().
63
64       EMFILE {OPEN_MAX}  file  descriptors  are currently open in the calling
65              process.
66
67       ENFILE The maximum allowable number of files is currently open  in  the
68              system.
69
70
71       The getpwnam_r() function may fail if:
72
73       ERANGE Insufficient storage was supplied via buffer and bufsize to con‐
74              tain the data to be referenced by the  resulting  passwd  struc‐
75              ture.
76
77
78       The following sections are informative.
79

EXAMPLES

81   Getting an Entry for the Login Name
82       The  following  example uses the getlogin() function to return the name
83       of the user who logged in; this information is passed to the getpwnam()
84       function to get the user database entry for that user.
85
86
87              #include <sys/types.h>
88              #include <pwd.h>
89              #include <unistd.h>
90              #include <stdio.h>
91              #include <stdlib.h>
92              ...
93              char *lgn;
94              struct passwd *pw;
95              ...
96              if ((lgn = getlogin()) == NULL || (pw = getpwnam(lgn)) == NULL) {
97                  fprintf(stderr, "Get of user information failed.\n"); exit(1);
98              }
99              ...
100

APPLICATION USAGE

102       Three names associated with the current process can be determined: get‐
103       pwuid( geteuid()) returns the name associated with the  effective  user
104       ID of the process; getlogin() returns the name associated with the cur‐
105       rent login activity; and getpwuid( getuid()) returns the  name  associ‐
106       ated with the real user ID of the process.
107
108       The  getpwnam_r() function is thread-safe and returns values in a user-
109       supplied buffer instead of possibly using a static data area  that  may
110       be overwritten by each call.
111

RATIONALE

113       None.
114

FUTURE DIRECTIONS

116       None.
117

SEE ALSO

119       getpwuid(),  the Base Definitions volume of IEEE Std 1003.1-2001, <lim‐
120       its.h>, <pwd.h>, <sys/types.h>
121
123       Portions of this text are reprinted and reproduced in  electronic  form
124       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
125       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
126       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
127       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
128       event of any discrepancy between this version and the original IEEE and
129       The Open Group Standard, the original IEEE and The Open Group  Standard
130       is  the  referee document. The original Standard can be obtained online
131       at http://www.opengroup.org/unix/online.html .
132
133
134
135IEEE/The Open Group                  2003                         GETPWNAM(3P)
Impressum