Directory.c 2.8 KB

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