File.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. {
  8. pal_printf("Enter Main Thread\n");
  9. PAL_HANDLE out = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR,
  10. PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_R,
  11. PAL_CREATE_TRY, 0);
  12. if (out == NULL) {
  13. pal_printf("DkStreamOpen failed\n");
  14. return -1;
  15. }
  16. str[0] = 'H';
  17. str[1] = 'e';
  18. str[2] = 'l';
  19. str[3] = 'l';
  20. str[4] = 'o';
  21. str[5] = ' ';
  22. str[6] = 'W';
  23. str[7] = 'o';
  24. str[8] = 'r';
  25. str[9] = 'l';
  26. str[10] = 'd';
  27. str[11] = 0;
  28. int bytes = DkStreamWrite(out, 0, 11, str, NULL);
  29. if (!bytes) {
  30. pal_printf("DkStreamWrite failed\n");
  31. return -1;
  32. }
  33. DkObjectClose(out);
  34. PAL_HANDLE in = DkStreamOpen(FILE_URI, PAL_ACCESS_RDONLY, 0, 0, 0);
  35. bytes = DkStreamRead(in, 0, 20, str, NULL, 0);
  36. if (!bytes) {
  37. pal_printf("DkStreamRead failed\n");
  38. return -1;
  39. }
  40. pal_printf("%s\n", str);
  41. DkStreamDelete(in, 0);
  42. PAL_HANDLE del = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR, 0, 0, 0);
  43. if (del) {
  44. pal_printf("DkStreamDelete failed\n");
  45. return -1;
  46. }
  47. pal_printf("Leave Main Thread\n");
  48. return 0;
  49. }