tst-hasmntopt.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (C) 2020 by Yann Sionneau <yann@sionneau.net> */
  2. #include <stdio.h>
  3. #include <mntent.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. static int
  7. do_test (void)
  8. {
  9. char *res;
  10. struct mntent m;
  11. /* check that "ro" does not match "erROr" */
  12. m.mnt_opts = "error";
  13. res = hasmntopt (&m, MNTOPT_RO);
  14. if (res != NULL) {
  15. puts ("error: hasmntopt() picked up non existing option");
  16. exit (1);
  17. }
  18. /* check that "ro" does not match "remount-ro" */
  19. m.mnt_opts = "rw,relatime,errors=remount-ro";
  20. res = hasmntopt (&m, MNTOPT_RO);
  21. if (res != NULL) {
  22. puts ("error: hasmntopt() picked up non existing option");
  23. exit (1);
  24. }
  25. /* check that "ro" does match "ro" */
  26. m.mnt_opts = "noatime,ro";
  27. res = hasmntopt (&m, MNTOPT_RO);
  28. if (res == NULL) {
  29. puts ("error: hasmntopt() did not pick up an existing option");
  30. exit (1);
  31. }
  32. if (strncmp(res, "ro", 2) != 0) {
  33. puts ("error: hasmntopt() did not return a pointer to corresponding option");
  34. exit (1);
  35. }
  36. return 0;
  37. }
  38. #define TEST_FUNCTION do_test ()
  39. #include "../test-skeleton.c"