Directory.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "api.h"
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. int main(int argc, char** argv, char** envp) {
  5. /* test regular directory opening */
  6. PAL_HANDLE dir1 = DkStreamOpen("dir:dir_exist.tmp", PAL_ACCESS_RDONLY, 0, 0, 0);
  7. if (dir1) {
  8. pal_printf("Directory Open Test 1 OK\n");
  9. PAL_STREAM_ATTR attr1;
  10. if (DkStreamAttributesQueryByHandle(dir1, &attr1))
  11. pal_printf("Query by Handle: type = %d\n", attr1.handle_type);
  12. char buffer[80];
  13. int bytes = DkStreamRead(dir1, 0, 80, buffer, NULL, 0);
  14. if (bytes) {
  15. for (char* c = buffer; c < buffer + bytes; c += strlen(c) + 1)
  16. if (strlen(c))
  17. pal_printf("Read Directory: %s\n", c);
  18. }
  19. DkObjectClose(dir1);
  20. }
  21. PAL_HANDLE dir2 = DkStreamOpen("dir:./dir_exist.tmp", PAL_ACCESS_RDONLY, 0, 0, 0);
  22. if (dir2) {
  23. pal_printf("Directory Open Test 2 OK\n");
  24. DkObjectClose(dir2);
  25. }
  26. PAL_HANDLE dir3 = DkStreamOpen("dir:../regression/dir_exist.tmp", PAL_ACCESS_RDONLY, 0, 0, 0);
  27. if (dir3) {
  28. pal_printf("Directory Open Test 3 OK\n");
  29. DkObjectClose(dir3);
  30. }
  31. PAL_STREAM_ATTR attr2;
  32. if (DkStreamAttributesQuery("dir:dir_exist.tmp", &attr2))
  33. pal_printf("Query: type = %d\n", attr2.handle_type);
  34. /* test regular directory creation */
  35. PAL_HANDLE dir4 = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY,
  36. PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X,
  37. PAL_CREATE_TRY | PAL_CREATE_ALWAYS, 0);
  38. if (dir4) {
  39. pal_printf("Directory Creation Test 1 OK\n");
  40. DkObjectClose(dir4);
  41. }
  42. PAL_HANDLE dir5 = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY,
  43. PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X,
  44. PAL_CREATE_TRY | PAL_CREATE_ALWAYS, 0);
  45. if (dir5) {
  46. DkObjectClose(dir5);
  47. } else {
  48. pal_printf("Directory Creation Test 2 OK\n");
  49. }
  50. PAL_HANDLE dir6 = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDWR,
  51. PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_TRY, 0);
  52. if (dir6) {
  53. pal_printf("Directory Creation Test 3 OK\n");
  54. DkObjectClose(dir6);
  55. }
  56. PAL_HANDLE dir7 = DkStreamOpen("dir:dir_delete.tmp", PAL_ACCESS_RDONLY, 0, 0, 0);
  57. if (dir7) {
  58. DkStreamDelete(dir7, 0);
  59. DkObjectClose(dir7);
  60. }
  61. return 0;
  62. }