From 860d05aa8d580bbf3853db13bc25e9dfcb16f514 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 23 Dec 2019 14:27:04 -0500 Subject: Add fopen/close/rewind for urls --- include/url.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 include/url.h (limited to 'include') diff --git a/include/url.h b/include/url.h new file mode 100644 index 0000000..99a8b96 --- /dev/null +++ b/include/url.h @@ -0,0 +1,44 @@ +#ifndef SPM_SPM_URL_H +#define SPM_SPM_URL_H + +#include +#include +#ifndef WIN32 +# include +#endif +#include +#include + +#include + +enum fcurl_type_e { + CFTYPE_NONE = 0, + CFTYPE_FILE = 1, + CFTYPE_CURL = 2 +}; + +struct fcurl_data +{ + enum fcurl_type_e type; /* type of handle */ + union { + CURL *curl; + FILE *file; + } handle; /* handle */ + + char *buffer; /* buffer to store cached data*/ + size_t buffer_len; /* currently allocated buffers length */ + size_t buffer_pos; /* end of data in buffer*/ + int still_running; /* Is background url fetch still in progress */ +}; + +typedef struct fcurl_data URL_FILE; + +/* exported functions */ +URL_FILE *url_fopen(const char *url, const char *operation); +int url_fclose(URL_FILE *file); +int url_feof(URL_FILE *file); +size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file); +char *url_fgets(char *ptr, size_t size, URL_FILE *file); +void url_rewind(URL_FILE *file); + +#endif // SPM_SPM_URL_H -- cgit