dirname.c 762 B

123456789101112131415161718192021222324252627282930
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. */
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <libgen.h>
  10. #include <errno.h>
  11. #define REQ_PRINT_USAGE /* Require print_usage() from ../common/common.h */
  12. #define REQ_ERRPRINT /* Require errprint() from ../common/common.h */
  13. #define DESCRIPTION "Return directory portion of <string>."
  14. #define OPERANDS "string"
  15. #include "../common/common.h"
  16. int main(int argc, char *argv[]) {
  17. char *dirnamestr;
  18. if (argc != 2) {
  19. print_usage(argv[0], DESCRIPTION, OPERANDS, VERSION);
  20. return 1;
  21. }
  22. dirnamestr = dirname(argv[1]);
  23. printf("%s\n", dirnamestr);
  24. return errprint(argv[0], NULL, errno);
  25. }