getlogin.c 959 B

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