user.c 733 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* See LICENSE file for copyright and license details. */
  2. #include <err.h>
  3. #include <pwd.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include "../lib/util.h"
  8. void
  9. gid(char *out,
  10. const char __unused *_a,
  11. uint32_t __unused _i,
  12. void __unused *_p)
  13. {
  14. bprintf(out, "%u", getgid());
  15. }
  16. void
  17. uid(char *out,
  18. const char __unused *_a,
  19. uint32_t __unused _i,
  20. void __unused *_p)
  21. {
  22. bprintf(out, "%u", getuid());
  23. }
  24. void
  25. username(char *out,
  26. const char __unused *_a,
  27. uint32_t __unused _i,
  28. void __unused *_p)
  29. {
  30. struct passwd *pw;
  31. uid_t uid = getuid();
  32. if (!(pw = getpwuid(uid))) {
  33. warn("getpwuid(%u)", uid);
  34. ERRRET(out);
  35. }
  36. bprintf(out, "%s", pw->pw_name);
  37. }