user.c 464 B

123456789101112131415161718192021222324252627282930313233
  1. /* See LICENSE file for copyright and license details. */
  2. #include <pwd.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. #include "../util.h"
  7. const char *
  8. gid(void)
  9. {
  10. return bprintf("%d", getgid());
  11. }
  12. const char *
  13. username(void)
  14. {
  15. struct passwd *pw;
  16. if (!(pw = getpwuid(geteuid()))) {
  17. warn("getpwuid '%d':", geteuid());
  18. return NULL;
  19. }
  20. return bprintf("%s", pw->pw_name);
  21. }
  22. const char *
  23. uid(void)
  24. {
  25. return bprintf("%d", geteuid());
  26. }