123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /***********************************************\
- ??? duck_io.c
- \***********************************************/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include "duck_io.h"
- #include "duck_io_http.h"
- #include "duck_io_file.h"
- #include "duck_hfb.h"
- #include <assert.h>
- #define MAKE_FOUR_CC(b1, b2, b3, b4 ) \
- ((b4 << 24) | (b3 << 16) | (b2 << 8) | (b1 << 0))
- int duck_readFinished(int han, int flag)
- {
- (void)han;
- (void)flag;
- return 1;
- }
- bool g_isHttp = false;
- int duck_open(const char *name, unsigned long userData)
- {
- if (strstr(name, "http://"))
- return duck_open_http(name, userData);
- else
- return duck_open_file(name, userData);
- }
- void duck_close(int handle)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- duck_close_http(handle);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- duck_close_file(handle);
- else
- assert(0);
- }
- int duck_read(int handle,unsigned char *buffer,int bytes)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- return duck_read_http(handle, buffer, bytes);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- return duck_read_file(handle, buffer, bytes);
- else
- {
- assert(0);
- return -1;
- }
- }
- int duck_read_blocking(int handle,unsigned char *buffer,int bytes)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- return duck_read_blocking_http(handle, buffer, bytes);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- return duck_read_file(handle, buffer, bytes);
- else
- {
- assert(0);
- return -1;
- }
- }
- int64_t duck_seek(int handle,int64_t offset,int origin)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- return duck_seek_http(handle, offset, origin);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- return duck_seek_file(handle, offset, origin);
- else
- {
- assert(0);
- return -1;
- }
-
- }
- int duck_name(int handle, char name[], size_t maxLen)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- return duck_name_http(handle, name, maxLen);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- return duck_name_file(handle, name, maxLen);
- else
- {
- assert(0);
- return -1;
- }
- }
- int64_t duck_available_data(int handle)
- {
- unsigned long schemeCC = *((unsigned long *) handle);
- if (schemeCC == MAKE_FOUR_CC('h','t','t','p'))
- return duck_available_data_http(handle);
- else if (schemeCC == MAKE_FOUR_CC('f','i','l','e'))
- return duck_available_data_file(handle);
- else
- {
- assert(0);
- return -1;
- }
- }
|