getlogin.c 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /* uClibc makes it policy to not mess with the utmp file whenever
  12. * possible, since I consider utmp a complete waste of time. Since
  13. * getlogin() should never be used for security purposes, we kindly let
  14. * the user specify whatever they want via the LOGNAME environment
  15. * variable, or we return NULL if getenv() fails to find anything */
  16. char * getlogin(void)
  17. {
  18. return (getenv("LOGNAME"));
  19. }
  20. libc_hidden_def(getlogin)
  21. int getlogin_r(char *name, size_t len)
  22. {
  23. char * foo = getenv("LOGNAME");
  24. if (! foo)
  25. return -1;
  26. strncpy(name, foo, len);
  27. name[len-1] = '\0';
  28. return 0;
  29. }
  30. char *cuserid(char *s)
  31. {
  32. char *name = getlogin();
  33. if (s) {
  34. return(strcpy(s, name ? name : ""));
  35. }
  36. return name;
  37. }