Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

308 lines
4.9 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <string.h>
  4. #include <signal.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include <sys/wait.h>
  8. #include <unistd.h>
  9. #include <dirent.h>
  10. #include <fcntl.h>
  11. #include "tsttmp.h" // defines DbgPrint as printf
  12. extern int errno;
  13. VOID dir0(char *);
  14. VOID dir1(char *);
  15. VOID dir2(char *);
  16. VOID dir3(char *);
  17. VOID dir4(char *);
  18. VOID dir5(char *);
  19. int
  20. main(int argc, char *argv[])
  21. {
  22. DbgPrint("argc = %d, argv[1] = %s\n", argc, argv[1]);
  23. if (argc != 2) {
  24. DbgPrint("Usage: 'tstdir basedirectory' (basedirectory is usually /psx/test)\n");
  25. return 1;
  26. }
  27. dir0(argv[1]);
  28. dir1(argv[1]);
  29. dir2(argv[1]);
  30. dir3(argv[1]);
  31. dir4(argv[1]);
  32. dir5(argv[1]);
  33. return 1;
  34. }
  35. VOID
  36. dir0(char *f)
  37. {
  38. int rc;
  39. DIR *dir;
  40. struct dirent *dirent;
  41. DbgPrint("dir0:++ %s\n",f);
  42. dir = opendir(f);
  43. ASSERT(dir != NULL);
  44. errno = 0;
  45. dirent = readdir(dir);
  46. while( dirent ) {
  47. DbgPrint("%s\n",&dirent->d_name);
  48. dirent = readdir(dir);
  49. }
  50. ASSERT(errno == 0);
  51. rc = closedir(dir);
  52. ASSERT(rc==0);
  53. rc = closedir(dir);
  54. ASSERT(rc==-1 && errno == EBADF);
  55. DbgPrint("dir0:--\n");
  56. }
  57. VOID
  58. dir1(char *f)
  59. {
  60. int rc,i;
  61. DIR *dir;
  62. char buf1[256],buf2[256];
  63. struct dirent *dirent;
  64. DbgPrint("dir1:++ %s\n",f);
  65. dir = opendir(f);
  66. ASSERT(dir != NULL);
  67. //
  68. // Get Two Directory entries.
  69. //
  70. i = 0;
  71. errno = 0;
  72. dirent = readdir(dir);
  73. if ( dirent ) {
  74. strcpy(buf1,(char *)&dirent->d_name);
  75. i++;
  76. }
  77. dirent = readdir(dir);
  78. if ( dirent ) {
  79. strcat(buf1,(char *)&dirent->d_name);
  80. i++;
  81. }
  82. //
  83. // Go past a few entries
  84. //
  85. dirent = readdir(dir);
  86. if ( dirent ) {
  87. dirent = readdir(dir);
  88. }
  89. //
  90. // Rewind the directory stream and then read into a new buffer
  91. // and compare results
  92. //
  93. rewinddir(dir);
  94. buf2[0]='\0';
  95. while(i--) {
  96. dirent = readdir(dir);
  97. ASSERT(dirent);
  98. strcat(buf2,(char *)&dirent->d_name);
  99. }
  100. ASSERT(strcmp(buf1,buf2) == 0);
  101. rc = closedir(dir);
  102. ASSERT(rc==0);
  103. rc = closedir(dir);
  104. ASSERT(rc==-1 && errno == EBADF);
  105. DbgPrint("dir1:--\n");
  106. }
  107. VOID
  108. dir2(char *f)
  109. {
  110. int rc;
  111. char buf[256], *b;
  112. DbgPrint("dir2:++ %s\n",f);
  113. rc = chdir(f);
  114. ASSERT(rc==0);
  115. b = getcwd(buf,256);
  116. ASSERT(b);
  117. b = getcwd(buf,-1);
  118. ASSERT(b==NULL && errno == EINVAL);
  119. b = getcwd(buf,1);
  120. ASSERT(b==NULL && errno == ERANGE);
  121. rc = chdir("/psx/test/tstdirs");
  122. ASSERT(rc==0);
  123. b = getcwd(buf,256);
  124. ASSERT(b);
  125. b = getcwd(buf,-1);
  126. ASSERT(b==NULL && errno == EINVAL);
  127. b = getcwd(buf,1);
  128. ASSERT(b==NULL && errno == ERANGE);
  129. DbgPrint("dir2:--\n");
  130. }
  131. VOID
  132. dir3(char *f)
  133. {
  134. int rc;
  135. DIR *dir;
  136. struct dirent *dirent;
  137. DbgPrint("dir3:++ %s\n",f);
  138. rc = chdir(f);
  139. ASSERT(rc==0);
  140. dir = opendir(".");
  141. ASSERT(dir != NULL);
  142. errno = 0;
  143. dirent = readdir(dir);
  144. while( dirent ) {
  145. DbgPrint("%s\n",&dirent->d_name);
  146. dirent = readdir(dir);
  147. }
  148. ASSERT(errno == 0);
  149. rc = closedir(dir);
  150. ASSERT(rc==0);
  151. rc = chdir("/psx/test/tstdirs");
  152. ASSERT(rc==0);
  153. dir = opendir(".");
  154. ASSERT(dir != NULL);
  155. errno = 0;
  156. dirent = readdir(dir);
  157. while( dirent ) {
  158. DbgPrint("%s\n",&dirent->d_name);
  159. dirent = readdir(dir);
  160. }
  161. ASSERT(errno == 0);
  162. rc = closedir(dir);
  163. ASSERT(rc==0);
  164. DbgPrint("dir3:--\n");
  165. }
  166. VOID
  167. dir4(char *f)
  168. {
  169. int rc;
  170. DIR *dir;
  171. struct dirent *dirent;
  172. DbgPrint("dir4:++ %s\n",f);
  173. dir = opendir(f);
  174. ASSERT(dir != NULL);
  175. if ( fork() == 0 ) {
  176. sleep(10);
  177. errno = 0;
  178. dirent = readdir(dir);
  179. while( dirent ) {
  180. DbgPrint("%s\n",&dirent->d_name);
  181. dirent = readdir(dir);
  182. }
  183. ASSERT(errno == 0);
  184. rc = closedir(dir);
  185. ASSERT(rc==0);
  186. rc = closedir(dir);
  187. ASSERT(rc==-1 && errno == EBADF);
  188. _exit(0);
  189. }
  190. rc = closedir(dir);
  191. ASSERT(rc==0);
  192. rc = closedir(dir);
  193. ASSERT(rc==-1 && errno == EBADF);
  194. wait(NULL);
  195. DbgPrint("dir4:--\n");
  196. }
  197. VOID
  198. dir5(char *f)
  199. {
  200. int rc;
  201. char buf[256], *b;
  202. PCH Arg[3], Env[4];
  203. DbgPrint("dir5:++ %s\n",f);
  204. rc = chdir(f);
  205. ASSERT(rc==0);
  206. b = getcwd(buf,256);
  207. ASSERT(b);
  208. b = getcwd(buf,-1);
  209. ASSERT(b==NULL && errno == EINVAL);
  210. b = getcwd(buf,1);
  211. ASSERT(b==NULL && errno == ERANGE);
  212. rc = chdir("/psx/test/tstdirs");
  213. ASSERT(rc==0);
  214. b = getcwd(buf,256);
  215. ASSERT(b);
  216. b = getcwd(buf,-1);
  217. ASSERT(b==NULL && errno == EINVAL);
  218. b = getcwd(buf,1);
  219. ASSERT(b==NULL && errno == ERANGE);
  220. Arg[0]="tsthello.xxx";
  221. Arg[1]=(PCH)NULL;
  222. Env[0]="NTUSER=ELLENA";
  223. Env[1]=(PCH)NULL;
  224. execve("\\DosDevices\\D:\\PSX\\TSTHELLO.exe",Arg,Env);
  225. ASSERT(FALSE);
  226. DbgPrint("dir5:--\n");
  227. }