getlogin.c 1.2 KB

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