getlogin.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include <stdlib.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <stdio.h>
  11. libc_hidden_proto(strcpy)
  12. libc_hidden_proto(strncpy)
  13. libc_hidden_proto(getenv)
  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. libc_hidden_proto(getlogin)
  20. char * getlogin(void)
  21. {
  22. return (getenv("LOGNAME"));
  23. }
  24. libc_hidden_def(getlogin)
  25. int getlogin_r(char *name, size_t len)
  26. {
  27. char * foo = getenv("LOGNAME");
  28. if (! foo)
  29. return -1;
  30. strncpy(name, foo, len);
  31. name[len-1] = '\0';
  32. return 0;
  33. }
  34. char *cuserid(char *s)
  35. {
  36. char *name = getlogin();
  37. if (s) {
  38. return(strcpy(s, name ? name : ""));
  39. }
  40. return name;
  41. }