Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: cuserid(3) Message-ID: <399@uvicctr.UUCP> Date: 5 May 88 06:51:26 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 113 EFTH Minix report #6 - May 1988 - cuserid(3) This is an implementation of cuserid(3) that we wrote for Minix. Please consider this a public domain program. A "man" page is included. echo x - cuserid.3 gres '^X' '' > cuserid.3 << '/' XNAME X cuserid(3) - get the current real user name X XSYNOPSIS X char *cuserid( buffer ) X char *buffer; X XDESCRIPTION X The current user name is copied to "buffer". It will be NULL X terminated. If "buffer" is NULL then an internal static X buffer is used. In either case, the value of this call is X a pointer to the real user's login name. X X On error conditions NULL is returned and *buffer is set X to '\0' (if it is not NULL itself). X XFILES X /etc/passwd user login names X XSEE ALSO X whoami(1) / echo x - cuserid.c gres '^X' '' > cuserid.c << '/' X/****************************************************************/ X/* */ X/* cuserid.c */ X/* */ X/* Get the current user name. */ X/* */ X/****************************************************************/ X/* origination 1987-Sep-18 T. Holm */ X/****************************************************************/ X X X#include X#include X X X#define USERID_SIZE 20 X X Xstruct passwd *getpwuid(); X X Xstatic char _userid[ USERID_SIZE ]; X X X X/****************************************************************/ X/* */ X/* cuserid( buffer ) */ X/* */ X/* The current user name is copied to "buffer". */ X/* It will be NULL terminated. If "buffer" is */ X/* NULL then an internal static buffer is used. */ X/* */ X/* In either case, the value of this call is */ X/* a pointer to the user's login name. */ X/* */ X/* On error conditions NULL is returned and */ X/* *buffer is set to '\0' (if it is not NULL). */ X/* */ X/* Note that there is no /etc/utmp file under */ X/* Minix, so the password file is used to */ X/* determine the name. The only restriction this */ X/* imposes is that users must have unique id */ X/* numbers (not really a restriction). */ X/* */ X/****************************************************************/ X X Xchar *cuserid( buffer ) X char *buffer; X X { X struct passwd *pw_entry; X X if ( buffer == NULL ) X buffer = _userid; X X pw_entry = getpwuid( getuid() ); X X if ( pw_entry == NULL ) X { X *buffer = '\0'; X return( NULL ); X } X X strcpy( buffer, pw_entry->pw_name ); X X return( buffer ); X } / -------------------------------------------------------------------- Edwin L. Froese uw-beaver!ubc-vision!mprg!handel!froese Terrence W. Holm uw-beaver!uvicctr!sirius!tholm