90-readdir.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <mes/lib.h>
  21. #include <dirent.h>
  22. #include <errno.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. int dot_seen = 0;
  26. int dot_dot_seen = 0;
  27. int dir_seen = 0;
  28. int file_seen = 0;
  29. int link_seen = 0;
  30. void
  31. check_seen (char const* name)
  32. {
  33. if (!strcmp (name, "."))
  34. dot_seen = 1;
  35. if (!strcmp (name, ".."))
  36. dot_dot_seen = 1;
  37. if (!strcmp (name, "dir"))
  38. dir_seen = 1;
  39. if (!strcmp (name, "file"))
  40. file_seen = 1;
  41. if (!strcmp (name, "link"))
  42. link_seen = 1;
  43. }
  44. int
  45. main ()
  46. {
  47. DIR *d = opendir ("../lib/tests/dirent/readdir-fu");
  48. if (d)
  49. return 1;
  50. if (errno != ENOENT)
  51. return 2;
  52. d = opendir ("../lib/tests/dirent/90-readdir.c");
  53. if (d)
  54. return 3;
  55. if (errno != ENOTDIR)
  56. return 4;
  57. errno = 0;
  58. d = opendir ("../lib/tests/dirent/readdir.dir");
  59. if (!d)
  60. return 5;
  61. if (errno)
  62. return 6;
  63. int i = 0;
  64. struct dirent *entry = readdir (d);
  65. if (!entry)
  66. return 7;
  67. oputs (entry->d_name);
  68. oputs ("\n");
  69. check_seen (entry->d_name);
  70. entry = readdir (d);
  71. if (!entry)
  72. return 8;
  73. oputs (entry->d_name);
  74. oputs ("\n");
  75. check_seen (entry->d_name);
  76. entry = readdir (d);
  77. if (!entry)
  78. return 9;
  79. oputs (entry->d_name);
  80. oputs ("\n");
  81. check_seen (entry->d_name);
  82. entry = readdir (d);
  83. if (!entry)
  84. return 10;
  85. oputs (entry->d_name);
  86. oputs ("\n");
  87. check_seen (entry->d_name);
  88. entry = readdir (d);
  89. if (!entry)
  90. return 11;
  91. oputs (entry->d_name);
  92. oputs ("\n");
  93. check_seen (entry->d_name);
  94. entry = readdir (d);
  95. if (entry)
  96. return 12;
  97. if (!dot_seen)
  98. return 13;
  99. if (!dot_dot_seen)
  100. return 14;
  101. if (!dir_seen)
  102. return 15;
  103. if (!file_seen)
  104. return 16;
  105. if (!link_seen)
  106. return 17;
  107. return 0;
  108. }