duck_io.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /***********************************************\
  2. ??? duck_io.c
  3. \***********************************************/
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include "duck_io.h"
  8. #include "duck_io_http.h"
  9. #include "duck_io_file.h"
  10. #include "duck_hfb.h"
  11. #include <assert.h>
  12. #define MAKE_FOUR_CC(b1, b2, b3, b4 ) \
  13. ((b4 << 24) | (b3 << 16) | (b2 << 8) | (b1 << 0))
  14. int duck_readFinished(int han, int flag)
  15. {
  16. (void)han;
  17. (void)flag;
  18. return 1;
  19. }
  20. bool g_isHttp = false;
  21. int duck_open(const char *name, unsigned long userData)
  22. {
  23. if (strstr(name, "http://"))
  24. return duck_open_http(name, userData);
  25. else
  26. return duck_open_file(name, userData);
  27. }
  28. void duck_close(int handle)
  29. {
  30. unsigned long schemeCC = *((unsigned long *) handle);
  31. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  32. duck_close_http(handle);
  33. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  34. duck_close_file(handle);
  35. else
  36. assert(0);
  37. }
  38. int duck_read(int handle,unsigned char *buffer,int bytes)
  39. {
  40. unsigned long schemeCC = *((unsigned long *) handle);
  41. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  42. return duck_read_http(handle, buffer, bytes);
  43. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  44. return duck_read_file(handle, buffer, bytes);
  45. else
  46. {
  47. assert(0);
  48. return -1;
  49. }
  50. }
  51. int duck_read_blocking(int handle,unsigned char *buffer,int bytes)
  52. {
  53. unsigned long schemeCC = *((unsigned long *) handle);
  54. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  55. return duck_read_blocking_http(handle, buffer, bytes);
  56. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  57. return duck_read_file(handle, buffer, bytes);
  58. else
  59. {
  60. assert(0);
  61. return -1;
  62. }
  63. }
  64. int64_t duck_seek(int handle,int64_t offset,int origin)
  65. {
  66. unsigned long schemeCC = *((unsigned long *) handle);
  67. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  68. return duck_seek_http(handle, offset, origin);
  69. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  70. return duck_seek_file(handle, offset, origin);
  71. else
  72. {
  73. assert(0);
  74. return -1;
  75. }
  76. }
  77. int duck_name(int handle, char name[], size_t maxLen)
  78. {
  79. unsigned long schemeCC = *((unsigned long *) handle);
  80. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  81. return duck_name_http(handle, name, maxLen);
  82. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  83. return duck_name_file(handle, name, maxLen);
  84. else
  85. {
  86. assert(0);
  87. return -1;
  88. }
  89. }
  90. int64_t duck_available_data(int handle)
  91. {
  92. unsigned long schemeCC = *((unsigned long *) handle);
  93. if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
  94. return duck_available_data_http(handle);
  95. else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
  96. return duck_available_data_file(handle);
  97. else
  98. {
  99. assert(0);
  100. return -1;
  101. }
  102. }