Directory.c 2.9 KB

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