logname.c 567 B

12345678910111213141516171819202122
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2018 K. Lange
  5. *
  6. * logname - Effectively the same as whoami, but for compliance
  7. * with POSIX, this uses getlogin().
  8. */
  9. #include <unistd.h>
  10. #include <stdio.h>
  11. int main(int argc, char ** argv) {
  12. char * name = getlogin();
  13. if (!name) {
  14. fprintf(stderr, "%s: failed to determine login name\n", argv[0]);
  15. return 1;
  16. }
  17. fprintf(stdout, "%s\n", name);
  18. return 0;
  19. }