home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/1/91 DJB baseline public domain
- */
-
- /*
-
- See groupname.c for documentation.
-
- */
-
- #include <pwd.h>
- #include "username.h"
- #include "numeric.h"
-
- /*XXX: cache */
-
- int uid2username(uid,unp)
- int uid;
- char **unp;
- {
- struct passwd *pw;
- static char un[20];
-
- if (pw = getpwuid(uid))
- {
- *unp = pw->pw_name;
- return 0;
- }
- sprintf(un,"%d",uid);
- *unp = un;
- return 1;
- }
-
- int username2uid(un,uid)
- char *un;
- int *uid;
- {
- struct passwd *pw;
-
- if (numeric(un))
- {
- *uid = atoi(un);
- return 1;
- }
- pw = getpwnam(un);
- if (!pw)
- return -1; /*XXX*/
- *uid = pw->pw_uid;
- return 0;
- }
-