logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

symbolize_mode.c (908B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #define _POSIX_C_SOURCE 200809L
  5. #include "../lib/mode.h"
  6. #include <assert.h>
  7. #include <stdio.h> // printf
  8. #include <string.h> // strcmp
  9. int counter = 0;
  10. int err = 0;
  11. static void
  12. t_symbolize_mode(mode_t mode, const char *expected)
  13. {
  14. char str[11] = "";
  15. symbolize_mode(mode, str);
  16. if(strcmp(str, expected) == 0)
  17. {
  18. printf("ok %d - %7o -> %s\n", ++counter, mode, expected);
  19. return;
  20. }
  21. err = 1;
  22. printf("not ok %d - %7o -> %s\n", ++counter, mode, expected);
  23. printf("# Got: %s\n", str);
  24. }
  25. int
  26. main(void)
  27. {
  28. int plan = 3;
  29. printf("1..%d\n", plan);
  30. t_symbolize_mode(0040000, "d---------");
  31. t_symbolize_mode(0040755, "drwxr-xr-x");
  32. t_symbolize_mode(0020644, "crw-r--r--");
  33. assert(counter == plan);
  34. return err;
  35. }