logo

utils

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

dirname.c (527B)


  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. #include <libgen.h> // dirname()
  5. #include <stdio.h> // puts()
  6. #include <string.h> // strcmp()
  7. int
  8. main(int argc, char *argv[])
  9. {
  10. if(argc != 2)
  11. {
  12. if((argc == 3) && (strcmp(argv[1], "--") == 0))
  13. {
  14. argv++;
  15. argc--;
  16. }
  17. else
  18. {
  19. fputs("usage: dirname string\n", stderr);
  20. return 1;
  21. }
  22. }
  23. puts(dirname(argv[1]));
  24. return 0;
  25. }