1*37086Skfall /* 2*37086Skfall * Copyright (c) 1988 The Regents of the University of California. 3*37086Skfall * All rights reserved. 4*37086Skfall * 5*37086Skfall * Redistribution and use in source and binary forms are permitted 6*37086Skfall * provided that the above copyright notice and this paragraph are 7*37086Skfall * duplicated in all such forms and that any documentation, 8*37086Skfall * advertising materials, and other materials related to such 9*37086Skfall * distribution and use acknowledge that the software was developed 10*37086Skfall * by the University of California, Berkeley. The name of the 11*37086Skfall * University may not be used to endorse or promote products derived 12*37086Skfall * from this software without specific prior written permission. 13*37086Skfall * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*37086Skfall * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*37086Skfall * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*37086Skfall */ 17*37086Skfall 1826558Sdonn #if defined(LIBC_SCCS) && !defined(lint) 19*37086Skfall static char sccsid[] = "@(#)getlogin.c 5.4 (Berkeley) 03/07/89"; 20*37086Skfall #endif /* LIBC_SCCS and not lint */ 219193Ssam 22*37086Skfall #include <sys/types.h> 23*37086Skfall #include <stdio.h> 24*37086Skfall #include <pwd.h> 259109Ssam #include <utmp.h> 269109Ssam 27*37086Skfall static char logname[UT_NAMESIZE+1]; 289109Ssam 299109Ssam char * 309109Ssam getlogin() 319109Ssam { 32*37086Skfall static int notcalled = 1; 339109Ssam 34*37086Skfall if (notcalled) { 35*37086Skfall if(getlogname(logname, sizeof(logname) - 1) < 0) 36*37086Skfall return((char *) 0); 37*37086Skfall notcalled = 0; 389193Ssam } 39*37086Skfall return(logname); 409109Ssam } 41*37086Skfall 42*37086Skfall uid_t geteuid(); 43*37086Skfall 44*37086Skfall char * 45*37086Skfall cuserid(s) 46*37086Skfall char *s; 47*37086Skfall { 48*37086Skfall register struct passwd *pwd; 49*37086Skfall 50*37086Skfall if((pwd = getpwuid(geteuid())) == NULL) { 51*37086Skfall if(s) 52*37086Skfall *s = '\0'; 53*37086Skfall return(NULL); 54*37086Skfall } 55*37086Skfall if(s) { 56*37086Skfall (void) strncpy(s, pwd->pw_name, L_cuserid); 57*37086Skfall return(s); 58*37086Skfall } 59*37086Skfall return(pwd->pw_name); 60*37086Skfall } 61