Lines Matching refs:file
71 FILE *file; member
84 int url_fclose(URL_FILE *file);
85 int url_feof(URL_FILE *file);
86 size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file);
87 char *url_fgets(char *ptr, size_t size, URL_FILE *file);
88 void url_rewind(URL_FILE *file);
128 static int fill_buffer(URL_FILE *file, size_t want) in fill_buffer() argument
140 if((!file->still_running) || (file->buffer_pos > want)) in fill_buffer()
203 curl_multi_perform(multi_handle, &file->still_running); in fill_buffer()
206 } while(file->still_running && (file->buffer_pos < want)); in fill_buffer()
211 static int use_buffer(URL_FILE *file, size_t want) in use_buffer() argument
214 if((file->buffer_pos - want) <= 0) { in use_buffer()
216 free(file->buffer); in use_buffer()
217 file->buffer = NULL; in use_buffer()
218 file->buffer_pos = 0; in use_buffer()
219 file->buffer_len = 0; in use_buffer()
223 memmove(file->buffer, in use_buffer()
224 &file->buffer[want], in use_buffer()
225 (file->buffer_pos - want)); in use_buffer()
227 file->buffer_pos -= want; in use_buffer()
237 URL_FILE *file; in url_fopen() local
240 file = calloc(1, sizeof(URL_FILE)); in url_fopen()
241 if(!file) in url_fopen()
244 file->handle.file = fopen(url, operation); in url_fopen()
245 if(file->handle.file) in url_fopen()
246 file->type = CFTYPE_FILE; /* marked as URL */ in url_fopen()
249 file->type = CFTYPE_CURL; /* marked as URL */ in url_fopen()
250 file->handle.curl = curl_easy_init(); in url_fopen()
252 curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); in url_fopen()
253 curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); in url_fopen()
254 curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0L); in url_fopen()
255 curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); in url_fopen()
260 curl_multi_add_handle(multi_handle, file->handle.curl); in url_fopen()
263 curl_multi_perform(multi_handle, &file->still_running); in url_fopen()
265 if((file->buffer_pos == 0) && (!file->still_running)) { in url_fopen()
269 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_fopen()
272 curl_easy_cleanup(file->handle.curl); in url_fopen()
274 free(file); in url_fopen()
276 file = NULL; in url_fopen()
279 return file; in url_fopen()
282 int url_fclose(URL_FILE *file) in url_fclose() argument
286 switch(file->type) { in url_fclose()
288 ret = fclose(file->handle.file); /* passthrough */ in url_fclose()
293 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_fclose()
296 curl_easy_cleanup(file->handle.curl); in url_fclose()
305 free(file->buffer);/* free any allocated buffer space */ in url_fclose()
306 free(file); in url_fclose()
311 int url_feof(URL_FILE *file) in url_feof() argument
315 switch(file->type) { in url_feof()
317 ret = feof(file->handle.file); in url_feof()
321 if((file->buffer_pos == 0) && (!file->still_running)) in url_feof()
333 size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) in url_fread() argument
337 switch(file->type) { in url_fread()
339 want = fread(ptr, size, nmemb, file->handle.file); in url_fread()
345 fill_buffer(file, want); in url_fread()
349 if(!file->buffer_pos) in url_fread()
353 if(file->buffer_pos < want) in url_fread()
354 want = file->buffer_pos; in url_fread()
357 memcpy(ptr, file->buffer, want); in url_fread()
359 use_buffer(file, want); in url_fread()
373 char *url_fgets(char *ptr, size_t size, URL_FILE *file) in url_fgets() argument
378 switch(file->type) { in url_fgets()
380 ptr = fgets(ptr, (int)size, file->handle.file); in url_fgets()
384 fill_buffer(file, want); in url_fgets()
388 if(!file->buffer_pos) in url_fgets()
392 if(file->buffer_pos < want) in url_fgets()
393 want = file->buffer_pos; in url_fgets()
398 if(file->buffer[loop] == '\n') { in url_fgets()
405 memcpy(ptr, file->buffer, want); in url_fgets()
408 use_buffer(file, want); in url_fgets()
421 void url_rewind(URL_FILE *file) in url_rewind() argument
423 switch(file->type) { in url_rewind()
425 rewind(file->handle.file); /* passthrough */ in url_rewind()
430 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_rewind()
433 curl_multi_add_handle(multi_handle, file->handle.curl); in url_rewind()
436 free(file->buffer); in url_rewind()
437 file->buffer = NULL; in url_rewind()
438 file->buffer_pos = 0; in url_rewind()
439 file->buffer_len = 0; in url_rewind()