1 /* vi: set sw=4 ts=4: */ 2 /* 3 * getlogin for uClibc 4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org> 5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 6 */ 7 8 #include <stdlib.h> 9 #include <string.h> 10 #include <unistd.h> 11 #include <stdio.h> 12 13 14 /* uClibc makes it policy to not mess with the utmp file whenever 15 * possible, since I consider utmp a complete waste of time. Since 16 * getlogin() should never be used for security purposes, we kindly let 17 * the user specify whatever they want via the LOGNAME environment 18 * variable, or we return NULL if getenv() fails to find anything */ 19 getlogin(void)20char * getlogin(void) 21 { 22 return (getenv("LOGNAME")); 23 } libc_hidden_def(getlogin)24libc_hidden_def(getlogin) 25 26 int getlogin_r(char *name, size_t len) 27 { 28 char * foo = getenv("LOGNAME"); 29 30 if (! foo) 31 return -1; 32 33 strncpy(name, foo, len); 34 name[len-1] = '\0'; 35 return 0; 36 } 37 cuserid(char * s)38char *cuserid(char *s) 39 { 40 char *name = getlogin(); 41 if (s) { 42 return(strcpy(s, name ? name : "")); 43 } 44 return name; 45 } 46