logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

pwd.c (586B)


  1. // Collection of Unix tools, comparable to coreutils
  2. // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #define _POSIX_C_SOURCE 200809L
  5. #include <stdio.h> /* puts, perror, printf */
  6. #include <unistd.h> /* getcwd() */
  7. int
  8. main(int argc, char *argv[])
  9. {
  10. char pwd[BUFSIZ];
  11. if(argc != 1)
  12. {
  13. fprintf(stderr, "usage: pwd\n");
  14. return 1;
  15. }
  16. if(getcwd(pwd, sizeof(pwd)) == NULL)
  17. {
  18. perror("pwd: getcwd");
  19. return 1;
  20. }
  21. else
  22. {
  23. if(puts(pwd) < 0)
  24. {
  25. return 1;
  26. }
  27. else
  28. {
  29. return 0;
  30. }
  31. }
  32. }