PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/local/sccscmds/sccscmds.2/util/username.c

https://bitbucket.org/okuoku/csrg
C | 31 lines | 21 code | 2 blank | 8 comment | 6 complexity | 0bdeefd75a374c14764e0b3fd9f60c80 MD5 | raw file
Possible License(s): MPL-2.0, LGPL-2.0
  1. static char Sccsid[] = "@(#)username.c 1.2 02/15/87";
  2. /*
  3. Gets user's login name.
  4. Note that the argument must be an integer.
  5. Returns pointer to login name on success,
  6. pointer to string representation of used ID on failure.
  7. Remembers user ID and login name for subsequent calls.
  8. */
  9. username(uid)
  10. register int uid;
  11. {
  12. char pw[200];
  13. static int ouid;
  14. static char lnam[9], *lptr;
  15. register int i;
  16. if (ouid!=uid || ouid==0) {
  17. if (getpw(uid,pw))
  18. sprintf(lnam,"%d",uid);
  19. else {
  20. for (i=0; i<8; i++)
  21. if ((lnam[i] = pw[i])==':') break;
  22. lnam[i] = '\0';
  23. }
  24. lptr = lnam;
  25. ouid = uid;
  26. }
  27. return(lptr);
  28. }