xref: /netbsd-src/lib/libcompat/4.4/cuserid.3 (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     from: @(#)ctermid.3	5.2 (Berkeley) 4/19/91
33.\"	$NetBSD: cuserid.3,v 1.8 2002/02/07 07:00:35 ross Exp $
34.\"
35.Dd November 28, 1993
36.Dt CUSERID 3
37.Os
38.Sh NAME
39.Nm cuserid
40.Nd get user name
41.Sh LIBRARY
42.Lb libcompat
43.Sh SYNOPSIS
44.Fd #include \*[Lt]stdio.h\*[Gt]
45.Ft char *
46.Fn cuserid "char *buf"
47.Sh DESCRIPTION
48.Bf -symbolic
49This interface is available from the compatibility library, libcompat and
50has been obsoleted by
51.Xr getlogin 2
52.Ef
53.Pp
54The
55.Fn cuserid
56function returns a character string representation of the user name
57associated with the effective user ID of the calling process.
58.Pp
59If
60.Fa buf
61is not the
62.Dv NULL
63pointer, the user name is copied into the memory referenced by
64.Fa buf .
65The argument
66.Fa buf
67is assumed to point to an array at least
68.Dv L_cuserid
69(as defined in the include
70file
71.Aq Pa stdio.h )
72bytes long.
73Otherwise, the user name is copied to a static buffer.
74.Sh RETURN VALUES
75If
76.Fa buf
77is not the
78.Dv NULL
79pointer,
80.Fa buf
81is returned;
82otherwise the address of the static buffer is returned.
83.Pp
84If the user name could not be determined, if
85.Fa buf
86is not the
87.Dv NULL
88pointer, the null character
89.Sq \e0
90will be stored at
91.Fa *buf ;
92otherwise
93the
94.Dv NULL
95pointer is returned.
96.Sh SEE ALSO
97.Xr getlogin 2 ,
98.Xr getpwent 3
99.Sh STANDARDS
100The
101.Fn cuserid
102function conforms to
103.St -p1003.1-88 .
104.Sh BUGS
105Due to irreconcilable differences in historic implementations,
106.Fn cuserid
107was removed from the
108.St -p1003.1-90
109standard.
110This implementation exists purely for compatibility with existing programs.
111New programs should use one of the following three alternatives to
112obtain the user name:
113.Pp
114.Bl -enum -offset indent -compact
115.It
116.Fn getlogin
117to return the user's login name.
118.It
119.Nm getpwuid Ns Pq Fn geteuid
120to return the user name associated with the calling process' effective user ID.
121.It
122.Nm getpwuid Ns Pq Fn getuid
123to return the user name associated with the calling process' real user ID.
124.El
125.Pp
126The
127.Fn cuserid
128function uses
129.Fn getpwuid ;
130thus the results of a user's call to
131.Fn getpwent ,
132.Fn getpwnam
133or
134.Fn getpwuid
135will be overwritten by subsequent calls to
136.Fn cuserid .
137