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 = malloc(sizeof(URL_FILE)); in url_fopen()
241 if(!file) in url_fopen()
244 memset(file, 0, sizeof(URL_FILE)); in url_fopen()
246 if((file->handle.file=fopen(url, operation))) in url_fopen()
247 file->type = CFTYPE_FILE; /* marked as URL */ in url_fopen()
250 file->type = CFTYPE_CURL; /* marked as URL */ in url_fopen()
251 file->handle.curl = curl_easy_init(); in url_fopen()
253 curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); in url_fopen()
254 curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); in url_fopen()
255 curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0L); in url_fopen()
256 curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); in url_fopen()
261 curl_multi_add_handle(multi_handle, file->handle.curl); in url_fopen()
264 curl_multi_perform(multi_handle, &file->still_running); in url_fopen()
266 if((file->buffer_pos == 0) && (!file->still_running)) { in url_fopen()
270 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_fopen()
273 curl_easy_cleanup(file->handle.curl); in url_fopen()
275 free(file); in url_fopen()
277 file = NULL; in url_fopen()
280 return file; in url_fopen()
283 int url_fclose(URL_FILE *file) in url_fclose() argument
287 switch(file->type) { in url_fclose()
289 ret=fclose(file->handle.file); /* passthrough */ in url_fclose()
294 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_fclose()
297 curl_easy_cleanup(file->handle.curl); in url_fclose()
306 free(file->buffer);/* free any allocated buffer space */ in url_fclose()
307 free(file); in url_fclose()
312 int url_feof(URL_FILE *file) in url_feof() argument
316 switch(file->type) { in url_feof()
318 ret=feof(file->handle.file); in url_feof()
322 if((file->buffer_pos == 0) && (!file->still_running)) in url_feof()
334 size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) in url_fread() argument
338 switch(file->type) { in url_fread()
340 want=fread(ptr, size, nmemb, file->handle.file); in url_fread()
346 fill_buffer(file, want); in url_fread()
350 if(!file->buffer_pos) in url_fread()
354 if(file->buffer_pos < want) in url_fread()
355 want = file->buffer_pos; in url_fread()
358 memcpy(ptr, file->buffer, want); in url_fread()
360 use_buffer(file, want); in url_fread()
374 char *url_fgets(char *ptr, size_t size, URL_FILE *file) in url_fgets() argument
379 switch(file->type) { in url_fgets()
381 ptr = fgets(ptr, (int)size, file->handle.file); in url_fgets()
385 fill_buffer(file, want); in url_fgets()
389 if(!file->buffer_pos) in url_fgets()
393 if(file->buffer_pos < want) in url_fgets()
394 want = file->buffer_pos; in url_fgets()
399 if(file->buffer[loop] == '\n') { in url_fgets()
406 memcpy(ptr, file->buffer, want); in url_fgets()
409 use_buffer(file, want); in url_fgets()
422 void url_rewind(URL_FILE *file) in url_rewind() argument
424 switch(file->type) { in url_rewind()
426 rewind(file->handle.file); /* passthrough */ in url_rewind()
431 curl_multi_remove_handle(multi_handle, file->handle.curl); in url_rewind()
434 curl_multi_add_handle(multi_handle, file->handle.curl); in url_rewind()
437 free(file->buffer); in url_rewind()
438 file->buffer=NULL; in url_rewind()
439 file->buffer_pos=0; in url_rewind()
440 file->buffer_len=0; in url_rewind()