File.c 1.3 KB

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