File.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /* This Hello World simply print out "Hello World" */
  4. #include "pal.h"
  5. #include "pal_debug.h"
  6. #define file_uri "file:test.txt"
  7. char str[12];
  8. int main (int argc, char ** argv, char ** envp)
  9. {
  10. pal_printf("Enter Main Thread\n");
  11. PAL_HANDLE out = DkStreamOpen(file_uri, PAL_ACCESS_RDWR,
  12. PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_R,
  13. PAL_CREAT_TRY, 0);
  14. if (out == NULL) {
  15. pal_printf("DkStreamOpen failed\n");
  16. return -1;
  17. }
  18. str[0] = 'H';
  19. str[1] = 'e';
  20. str[2] = 'l';
  21. str[3] = 'l';
  22. str[4] = 'o';
  23. str[5] = ' ';
  24. str[6] = 'W';
  25. str[7] = 'o';
  26. str[8] = 'r';
  27. str[9] = 'l';
  28. str[10] = 'd';
  29. str[11] = 0;
  30. int bytes = DkStreamWrite(out, 0, 11, str, NULL);
  31. if (!bytes) {
  32. pal_printf("DkStreamWrite failed\n");
  33. return -1;
  34. }
  35. DkObjectClose(out);
  36. PAL_HANDLE in = DkStreamOpen(file_uri, PAL_ACCESS_RDONLY, 0, 0, 0);
  37. bytes = DkStreamRead(in, 0, 20, str, NULL, 0);
  38. if (!bytes) {
  39. pal_printf("DkStreamRead failed\n");
  40. return -1;
  41. }
  42. pal_printf("%s\n", str);
  43. DkStreamDelete(in, 0);
  44. PAL_HANDLE del = DkStreamOpen(file_uri, PAL_ACCESS_RDWR, 0, 0, 0);
  45. if (del) {
  46. pal_printf("DkStreamDelete failed\n");
  47. return -1;
  48. }
  49. pal_printf("Leave Main Thread\n");
  50. return 0;
  51. }