xref: /original-bsd/usr.bin/mail/getname.c (revision 4ec22e22)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)getname.c	5.8 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 #include <sys/types.h>
13 #include <pwd.h>
14 
15 /*
16  * Getname / getuserid for those with
17  * hashed passwd data base).
18  *
19  */
20 
21 #include "rcv.h"
22 
23 /*
24  * Search the passwd file for a uid.  Return name through ref parameter
25  * if found, indicating success with 0 return.  Return -1 on error.
26  */
27 char *
28 getname(uid)
29 {
30 	struct passwd *pw;
31 
32 	if ((pw = getpwuid(uid)) == NULL)
33 		return NOSTR;
34 	return pw->pw_name;
35 }
36 
37 /*
38  * Convert the passed name to a user id and return it.  Return -1
39  * on error.
40  */
41 getuserid(name)
42 	char name[];
43 {
44 	struct passwd *pw;
45 
46 	if ((pw = getpwnam(name)) == NULL)
47 		return -1;
48 	return pw->pw_uid;
49 }
50