\doxysection{fopen.\+c}
\hypertarget{fopen_8c_source}{}\label{fopen_8c_source}\index{workspace/post-\/scarcity/src/io/fopen.c@{workspace/post-\/scarcity/src/io/fopen.c}}
\mbox{\hyperlink{fopen_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00001}00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00002}00002\ \textcolor{comment}{\ *\ fopen.c}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00003}00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00004}00004\ \textcolor{comment}{\ *\ adapted\ from\ https://curl.haxx.se/libcurl/c/fopen.html.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00005}00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00006}00006\ \textcolor{comment}{\ *\ Modifications\ to\ read/write\ wide\ character\ streams\ by}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00007}00007\ \textcolor{comment}{\ *\ Simon\ Brooke.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00008}00008\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00009}00009\ \textcolor{comment}{\ *\ NOTE\ THAT:\ for\ my\ purposes,\ I'm\ only\ interested\ in\ wide\ characters,}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00010}00010\ \textcolor{comment}{\ *\ and\ I\ always\ read\ them\ one\ character\ at\ a\ time.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00011}00011\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00012}00012\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2003,\ 2017\ Simtec\ Electronics}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00013}00013\ \textcolor{comment}{\ *\ Some\ portions\ (c)\ 2019\ Simon\ Brooke\ <simon@journeyman.cc>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00014}00014\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00015}00015\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00016}00016\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00017}00017\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00018}00018\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00019}00019\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00020}00020\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00021}00021\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in\ the}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00022}00022\ \textcolor{comment}{\ *\ \ \ \ documentation\ and/or\ other\ materials\ provided\ with\ the\ distribution.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00023}00023\ \textcolor{comment}{\ *\ 3.\ The\ name\ of\ the\ author\ may\ not\ be\ used\ to\ endorse\ or\ promote\ products}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00024}00024\ \textcolor{comment}{\ *\ \ \ \ derived\ from\ this\ software\ without\ specific\ prior\ written\ permission.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00025}00025\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00026}00026\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ THE\ AUTHOR\ \`{}\`{}AS\ IS''\ AND\ ANY\ EXPRESS\ OR}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00027}00027\ \textcolor{comment}{\ *\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ THE\ IMPLIED\ WARRANTIES}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00028}00028\ \textcolor{comment}{\ *\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR\ PURPOSE\ ARE\ DISCLAIMED.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00029}00029\ \textcolor{comment}{\ *\ IN\ NO\ EVENT\ SHALL\ THE\ AUTHOR\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00030}00030\ \textcolor{comment}{\ *\ INCIDENTAL,\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00031}00031\ \textcolor{comment}{\ *\ NOT\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00032}00032\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00033}00033\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00034}00034\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ OF}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00035}00035\ \textcolor{comment}{\ *\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00036}00036\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00037}00037\ \textcolor{comment}{\ *\ This\ example\ requires\ libcurl\ 7.9.7\ or\ later.}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00038}00038\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00039}00039\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00040}00040\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00041}00041\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00042}00042\ \textcolor{preprocessor}{\#ifndef\ WIN32}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00043}00043\ \textcolor{preprocessor}{\#include\ <sys/time.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00044}00044\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00045}00045\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00046}00046\ \textcolor{preprocessor}{\#include\ <errno.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00047}00047\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00048}00048\ \textcolor{preprocessor}{\#include\ <curl/curl.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00049}00049\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00050}00050\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{fopen_8h}{io/fopen.h}}"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00051}00051\ \textcolor{preprocessor}{\#ifdef\ FOPEN\_STANDALONE}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00052}00052\ CURLSH\ *\mbox{\hyperlink{io_8c_ac40101a2ddb1b4aac9f2f722c84d16dd}{io\_share}};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00053}00053\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00054}00054\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{consspaceobject_8h}{memory/consspaceobject.h}}"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00055}00055\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{io_8h}{io/io.h}}"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00056}00056\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{utils_8h}{utils.h}}"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00057}00057\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00058}00058\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00059}00059\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00060}00060\ \textcolor{comment}{/*\ exported\ functions\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00061}00061\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *url,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *operation\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00062}00062\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00063}00063\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8c_a216d4da618cba31eb9b2badf6d5de2d9}{url\_feof}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00064}00064\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{url\_fread}}(\ \textcolor{keywordtype}{void}\ *ptr,\ \textcolor{keywordtype}{size\_t}\ size,\ \textcolor{keywordtype}{size\_t}\ nmemb,\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00065}00065\ \textcolor{keywordtype}{char}\ *\mbox{\hyperlink{fopen_8c_a581c0437f39131b6368dd163843afff8}{url\_fgets}}(\ \textcolor{keywordtype}{char}\ *ptr,\ \textcolor{keywordtype}{size\_t}\ size,\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00066}00066\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{fopen_8c_a136dc33c053055258c690193177cc0af}{url\_rewind}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00067}00067\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00068}00068\ \textcolor{comment}{/*\ we\ use\ a\ global\ one\ for\ convenience\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00069}00069\ \textcolor{keyword}{static}\ CURLM\ *multi\_handle;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00070}00070\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00071}00071\ \textcolor{comment}{/*\ curl\ calls\ this\ routine\ to\ get\ more\ data\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00072}00072\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{size\_t}\ write\_callback(\ \textcolor{keywordtype}{char}\ *buffer,}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00073}00073\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ size,\ \textcolor{keywordtype}{size\_t}\ nitems,\ \textcolor{keywordtype}{void}\ *userp\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00074}00074\ \ \ \ \ \textcolor{keywordtype}{char}\ *newbuff;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00075}00075\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ rembuff;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00076}00076\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00077}00077\ \ \ \ \ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *url\ =\ (\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ )\ userp;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00078}00078\ \ \ \ \ size\ *=\ nitems;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00079}00079\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00080}00080\ \ \ \ \ rembuff\ =\ url-\/>\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}}\ -\/\ url-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}};\ \ \textcolor{comment}{/*\ remaining\ space\ in\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00081}00081\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00082}00082\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ size\ >\ rembuff\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00083}00083\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ not\ enough\ space\ in\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00084}00084\ \ \ \ \ \ \ \ \ newbuff\ =\ realloc(\ url-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}},\ url-\/>\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}}\ +\ (\ size\ -\/\ rembuff\ )\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00085}00085\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ newbuff\ ==\ NULL\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00086}00086\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(\ stderr,\ \textcolor{stringliteral}{"{}callback\ buffer\ grow\ failed\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00087}00087\ \ \ \ \ \ \ \ \ \ \ \ \ size\ =\ rembuff;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00088}00088\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00089}00089\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ realloc\ succeeded\ increase\ buffer\ size\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00090}00090\ \ \ \ \ \ \ \ \ \ \ \ \ url-\/>\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}}\ +=\ size\ -\/\ rembuff;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00091}00091\ \ \ \ \ \ \ \ \ \ \ \ \ url-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ =\ newbuff;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00092}00092\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00093}00093\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00094}00094\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00095}00095\ \ \ \ \ memcpy(\ \&url-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}[url-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}],\ buffer,\ size\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00096}00096\ \ \ \ \ url-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ +=\ size;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00097}00097\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00098}00098\ \ \ \ \ \textcolor{keywordflow}{return}\ size;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00099}00099\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00100}00100\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00101}00101\ \textcolor{comment}{/*\ use\ to\ attempt\ to\ fill\ the\ read\ buffer\ up\ to\ requested\ number\ of\ bytes\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00102}00102\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ fill\_buffer(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file,\ \textcolor{keywordtype}{size\_t}\ want\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00103}00103\ \ \ \ \ fd\_set\ fdread;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00104}00104\ \ \ \ \ fd\_set\ fdwrite;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00105}00105\ \ \ \ \ fd\_set\ fdexcep;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00106}00106\ \ \ \ \ \textcolor{keyword}{struct\ }timeval\ timeout;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00107}00107\ \ \ \ \ \textcolor{keywordtype}{int}\ rc;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00108}00108\ \ \ \ \ CURLMcode\ mc;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ curl\_multi\_fdset()\ return\ code\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00109}00109\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00110}00110\ \ \ \ \ \textcolor{comment}{/*\ only\ attempt\ to\ fill\ buffer\ if\ transactions\ still\ running\ and\ buffer}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00111}00111\ \textcolor{comment}{\ \ \ \ \ *\ doesn't\ exceed\ required\ size\ already}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00112}00112\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00113}00113\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ (\ !file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ )\ ||\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ >\ want\ )\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00114}00114\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00115}00115\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00116}00116\ \ \ \ \ \textcolor{comment}{/*\ attempt\ to\ fill\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00117}00117\ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00118}00118\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ maxfd\ =\ -\/1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00119}00119\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{long}\ curl\_timeo\ =\ -\/1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00120}00120\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00121}00121\ \ \ \ \ \ \ \ \ FD\_ZERO(\ \&fdread\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00122}00122\ \ \ \ \ \ \ \ \ FD\_ZERO(\ \&fdwrite\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00123}00123\ \ \ \ \ \ \ \ \ FD\_ZERO(\ \&fdexcep\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00124}00124\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00125}00125\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ set\ a\ suitable\ timeout\ to\ fail\ on\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00126}00126\ \ \ \ \ \ \ \ \ timeout.tv\_sec\ =\ 60;\ \ \ \ \textcolor{comment}{/*\ 1\ minute\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00127}00127\ \ \ \ \ \ \ \ \ timeout.tv\_usec\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00128}00128\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00129}00129\ \ \ \ \ \ \ \ \ curl\_multi\_timeout(\ multi\_handle,\ \&curl\_timeo\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00130}00130\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ curl\_timeo\ >=\ 0\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00131}00131\ \ \ \ \ \ \ \ \ \ \ \ \ timeout.tv\_sec\ =\ curl\_timeo\ /\ 1000;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00132}00132\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ timeout.tv\_sec\ >\ 1\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00133}00133\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ timeout.tv\_sec\ =\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00134}00134\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00135}00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ timeout.tv\_usec\ =\ (\ curl\_timeo\ \%\ 1000\ )\ *\ 1000;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00136}00136\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00137}00137\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00138}00138\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ get\ file\ descriptors\ from\ the\ transfers\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00139}00139\ \ \ \ \ \ \ \ \ mc\ =\ curl\_multi\_fdset(\ multi\_handle,\ \&fdread,\ \&fdwrite,\ \&fdexcep,}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00140}00140\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&maxfd\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00141}00141\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00142}00142\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ mc\ !=\ CURLM\_OK\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00143}00143\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(\ stderr,\ \textcolor{stringliteral}{"{}curl\_multi\_fdset()\ failed,\ code\ \%d.\(\backslash\)n"{}},\ mc\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00144}00144\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00145}00145\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00146}00146\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00147}00147\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ On\ success\ the\ value\ of\ maxfd\ is\ guaranteed\ to\ be\ >=\ -\/1.\ We\ call}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00148}00148\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ select(maxfd\ +\ 1,\ ...);\ specially\ in\ case\ of\ (maxfd\ ==\ -\/1)\ there\ are}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00149}00149\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ no\ fds\ ready\ yet\ so\ we\ call\ select(0,\ ...)\ -\/-\/or\ Sleep()\ on\ Windows-\/-\/}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00150}00150\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ to\ sleep\ 100ms,\ which\ is\ the\ minimum\ suggested\ value\ in\ the}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00151}00151\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ curl\_multi\_fdset()\ doc.\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00152}00152\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00153}00153\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ maxfd\ ==\ -\/1\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00154}00154\ \textcolor{preprocessor}{\#ifdef\ \_WIN32}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00155}00155\ \ \ \ \ \ \ \ \ \ \ \ \ Sleep(\ 100\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00156}00156\ \ \ \ \ \ \ \ \ \ \ \ \ rc\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00157}00157\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00158}00158\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Portable\ sleep\ for\ platforms\ other\ than\ Windows.\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00159}00159\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{struct\ }timeval\ wait\ =\ \{\ 0,\ 100\ *\ 1000\ \};\ \ \textcolor{comment}{/*\ 100ms\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00160}00160\ \ \ \ \ \ \ \ \ \ \ \ \ rc\ =\ select(\ 0,\ NULL,\ NULL,\ NULL,\ \&wait\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00161}00161\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00162}00162\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00163}00163\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Note\ that\ on\ some\ platforms\ 'timeout'\ may\ be\ modified\ by\ select().}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00164}00164\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ If\ you\ need\ access\ to\ the\ original\ value\ save\ a\ copy\ beforehand.\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00165}00165\ \ \ \ \ \ \ \ \ \ \ \ \ rc\ =\ select(\ maxfd\ +\ 1,\ \&fdread,\ \&fdwrite,\ \&fdexcep,\ \&timeout\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00166}00166\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00167}00167\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00168}00168\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ rc\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00169}00169\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ -\/1:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00170}00170\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ select\ error\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00171}00171\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00172}00172\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00173}00173\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00174}00174\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00175}00175\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ timeout\ or\ readable/writable\ sockets\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00176}00176\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ curl\_multi\_perform(\ multi\_handle,\ \&file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00177}00177\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00178}00178\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00179}00179\ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ \&\&\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ <\ want\ )\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00180}00180\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00181}00181\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00182}00182\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00183}00183\ \textcolor{comment}{/*\ use\ to\ remove\ want\ bytes\ from\ the\ front\ of\ a\ files\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00184}00184\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ use\_buffer(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file,\ \textcolor{keywordtype}{size\_t}\ want\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00185}00185\ \ \ \ \ \textcolor{comment}{/*\ sort\ out\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00186}00186\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ -\/\ want\ )\ <=\ 0\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00187}00187\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ ditch\ buffer\ -\/\ write\ will\ recreate\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00188}00188\ \ \ \ \ \ \ \ \ free(\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00189}00189\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ =\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00190}00190\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00191}00191\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00192}00192\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00193}00193\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ move\ rest\ down\ make\ it\ available\ for\ later\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00194}00194\ \ \ \ \ \ \ \ \ memmove(\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}},}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00195}00195\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}[want],\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ -\/\ want\ )\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00196}00196\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00197}00197\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ -\/=\ want;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00198}00198\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00199}00199\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00200}00200\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00201}00201\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00202}\mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{00202}}\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *url,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *operation\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00203}00203\ \ \ \ \ \textcolor{comment}{/*\ this\ code\ could\ check\ for\ URLs\ or\ types\ in\ the\ 'url'\ and}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00204}00204\ \textcolor{comment}{\ \ \ \ \ \ \ basically\ use\ the\ real\ fopen()\ for\ standard\ files\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00205}00205\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00206}00206\ \ \ \ \ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00207}00207\ \ \ \ \ (\ void\ )\ operation;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00208}00208\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00209}00209\ \ \ \ \ file\ =\ calloc(\ 1,\ \textcolor{keyword}{sizeof}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ )\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00210}00210\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !file\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00211}00211\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00212}00212\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00213}00213\ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ =\ fopen(\ url,\ operation\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00214}00214\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00215}00215\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ =\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}};\ \textcolor{comment}{/*\ marked\ as\ file\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00216}00216\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (\ \mbox{\hyperlink{utils_8c_ab55c66b6fbeac34e71ec2b8f83a2aade}{index\_of}}(\ \textcolor{charliteral}{':'},\ url\ )\ >\ -\/1\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00217}00217\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ =\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}};\ \textcolor{comment}{/*\ marked\ as\ URL\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00218}00218\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ =\ curl\_easy\_init(\ \ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00219}00219\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00220}00220\ \ \ \ \ \ \ \ \ curl\_easy\_setopt(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl,\ CURLOPT\_URL,\ url\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00221}00221\ \ \ \ \ \ \ \ \ curl\_easy\_setopt(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl,\ CURLOPT\_WRITEDATA,\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00222}00222\ \ \ \ \ \ \ \ \ curl\_easy\_setopt(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl,\ CURLOPT\_VERBOSE,\ 0L\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00223}00223\ \ \ \ \ \ \ \ \ curl\_easy\_setopt(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl,\ CURLOPT\_WRITEFUNCTION,}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00224}00224\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ write\_callback\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00225}00225\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ use\ the\ share\ object\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00226}00226\ \ \ \ \ \ \ \ \ curl\_easy\_setopt(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl,\ CURLOPT\_SHARE,\ \mbox{\hyperlink{io_8c_ac40101a2ddb1b4aac9f2f722c84d16dd}{io\_share}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00227}00227\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00228}00228\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00229}00229\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !multi\_handle\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00230}00230\ \ \ \ \ \ \ \ \ \ \ \ \ multi\_handle\ =\ curl\_multi\_init(\ \ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00231}00231\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00232}00232\ \ \ \ \ \ \ \ \ curl\_multi\_add\_handle(\ multi\_handle,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00233}00233\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00234}00234\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ lets\ start\ the\ fetch\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00235}00235\ \ \ \ \ \ \ \ \ curl\_multi\_perform(\ multi\_handle,\ \&file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00236}00236\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00237}00237\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ ==\ 0\ )\ \&\&\ (\ !file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ )\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00238}00238\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ if\ still\_running\ is\ 0\ now,\ we\ should\ return\ NULL\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00239}00239\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00240}00240\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ make\ sure\ the\ easy\ handle\ is\ not\ in\ the\ multi\ handle\ anymore\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00241}00241\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_multi\_remove\_handle(\ multi\_handle,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00242}00242\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00243}00243\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ cleanup\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00244}00244\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_easy\_cleanup(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00245}00245\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00246}00246\ \ \ \ \ \ \ \ \ \ \ \ \ free(\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00247}00247\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00248}00248\ \ \ \ \ \ \ \ \ \ \ \ \ file\ =\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00249}00249\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00250}00250\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00251}00251\ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ =\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12abf2aa2baf8c5c768bee2228c2991c0a7}{CFTYPE\_NONE}};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00252}00252\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ not\ a\ file,\ and\ doesn't\ look\ like\ a\ URL.\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00253}00253\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00254}00254\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00255}00255\ \ \ \ \ \textcolor{keywordflow}{return}\ file;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00256}00256\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00257}00257\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00258}\mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{00258}}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00259}00259\ \ \ \ \ \textcolor{keywordtype}{int}\ ret\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ default\ is\ good\ return\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00260}00260\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00261}00261\ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00262}00262\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00263}00263\ \ \ \ \ \ \ \ \ \ \ \ \ ret\ =\ fclose(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ );\ \ \textcolor{comment}{/*\ passthrough\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00264}00264\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00265}00265\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00266}00266\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00267}00267\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ make\ sure\ the\ easy\ handle\ is\ not\ in\ the\ multi\ handle\ anymore\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00268}00268\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_multi\_remove\_handle(\ multi\_handle,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00269}00269\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00270}00270\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ cleanup\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00271}00271\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_easy\_cleanup(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00272}00272\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00273}00273\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00274}00274\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unknown\ or\ supported\ type\ -\/\ oh\ dear\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00275}00275\ \ \ \ \ \ \ \ \ \ \ \ \ ret\ =\ EOF;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00276}00276\ \ \ \ \ \ \ \ \ \ \ \ \ errno\ =\ EBADF;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00277}00277\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00278}00278\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00279}00279\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00280}00280\ \ \ \ \ free(\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ );\ \ \ \ \ \ \ \textcolor{comment}{/*\ free\ any\ allocated\ buffer\ space\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00281}00281\ \ \ \ \ free(\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00282}00282\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00283}00283\ \ \ \ \ \textcolor{keywordflow}{return}\ ret;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00284}00284\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00285}00285\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00286}\mbox{\hyperlink{fopen_8c_a216d4da618cba31eb9b2badf6d5de2d9}{00286}}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8c_a216d4da618cba31eb9b2badf6d5de2d9}{url\_feof}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00287}00287\ \ \ \ \ \textcolor{keywordtype}{int}\ ret\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00288}00288\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00289}00289\ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00290}00290\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00291}00291\ \ \ \ \ \ \ \ \ \ \ \ \ ret\ =\ feof(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00292}00292\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00293}00293\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00294}00294\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00295}00295\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ ==\ 0\ )\ \&\&\ (\ !file-\/>\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}}\ )\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00296}00296\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ret\ =\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00297}00297\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00298}00298\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00299}00299\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unknown\ or\ supported\ type\ -\/\ oh\ dear\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00300}00300\ \ \ \ \ \ \ \ \ \ \ \ \ ret\ =\ -\/1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00301}00301\ \ \ \ \ \ \ \ \ \ \ \ \ errno\ =\ EBADF;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00302}00302\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00303}00303\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00304}00304\ \ \ \ \ \textcolor{keywordflow}{return}\ ret;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00305}00305\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00306}00306\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00307}\mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{00307}}\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{url\_fread}}(\ \textcolor{keywordtype}{void}\ *ptr,\ \textcolor{keywordtype}{size\_t}\ size,\ \textcolor{keywordtype}{size\_t}\ nmemb,\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00308}00308\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ want;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00309}00309\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00310}00310\ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00311}00311\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00312}00312\ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ fread(\ ptr,\ size,\ nmemb,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00313}00313\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00314}00314\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00315}00315\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00316}00316\ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ nmemb\ *\ size;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00317}00317\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00318}00318\ \ \ \ \ \ \ \ \ \ \ \ \ fill\_buffer(\ file,\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00319}00319\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00320}00320\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ check\ if\ there's\ data\ in\ the\ buffer\ -\/\ if\ not\ fill\_buffer()}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00321}00321\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ either\ errored\ or\ EOF\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00322}00322\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00323}00323\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00324}00324\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00325}00325\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ ensure\ only\ available\ data\ is\ considered\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00326}00326\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ <\ want\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00327}00327\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00328}00328\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00329}00329\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ xfer\ data\ to\ caller\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00330}00330\ \ \ \ \ \ \ \ \ \ \ \ \ memcpy(\ ptr,\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}},\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00331}00331\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00332}00332\ \ \ \ \ \ \ \ \ \ \ \ \ use\_buffer(\ file,\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00333}00333\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00334}00334\ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ want\ /\ size;\ \textcolor{comment}{/*\ number\ of\ items\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00335}00335\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00336}00336\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00337}00337\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unknown\ or\ supported\ type\ -\/\ oh\ dear\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00338}00338\ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00339}00339\ \ \ \ \ \ \ \ \ \ \ \ \ errno\ =\ EBADF;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00340}00340\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00341}00341\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00342}00342\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00343}00343\ \ \ \ \ \textcolor{keywordflow}{return}\ want;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00344}00344\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00345}00345\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00346}\mbox{\hyperlink{fopen_8c_a581c0437f39131b6368dd163843afff8}{00346}}\ \textcolor{keywordtype}{char}\ *\mbox{\hyperlink{fopen_8c_a581c0437f39131b6368dd163843afff8}{url\_fgets}}(\ \textcolor{keywordtype}{char}\ *ptr,\ \textcolor{keywordtype}{size\_t}\ size,\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00347}00347\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ want\ =\ size\ -\/\ 1;\ \ \ \ \ \textcolor{comment}{/*\ always\ need\ to\ leave\ room\ for\ zero\ termination\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00348}00348\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ loop;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00349}00349\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00350}00350\ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00351}00351\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00352}00352\ \ \ \ \ \ \ \ \ \ \ \ \ ptr\ =\ fgets(\ ptr,\ (\ \textcolor{keywordtype}{int}\ )\ size,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00353}00353\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00354}00354\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00355}00355\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00356}00356\ \ \ \ \ \ \ \ \ \ \ \ \ fill\_buffer(\ file,\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00357}00357\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00358}00358\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ check\ if\ there's\ data\ in\ the\ buffer\ -\/\ if\ not\ fill\ either\ errored\ or}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00359}00359\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ EOF\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00360}00360\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00361}00361\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00362}00362\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00363}00363\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ ensure\ only\ available\ data\ is\ considered\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00364}00364\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ <\ want\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00365}00365\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00366}00366\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00367}00367\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*buffer\ contains\ data\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00368}00368\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ look\ for\ newline\ or\ eof\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00369}00369\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\ loop\ =\ 0;\ loop\ <\ want;\ loop++\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00370}00370\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}[loop]\ ==\ \textcolor{charliteral}{'\(\backslash\)n'}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00371}00371\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ want\ =\ loop\ +\ 1;\ \ \textcolor{comment}{/*\ include\ newline\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00372}00372\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00373}00373\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00374}00374\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00375}00375\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00376}00376\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ xfer\ data\ to\ caller\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00377}00377\ \ \ \ \ \ \ \ \ \ \ \ \ memcpy(\ ptr,\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}},\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00378}00378\ \ \ \ \ \ \ \ \ \ \ \ \ ptr[want]\ =\ 0;\ \ \ \ \ \ \textcolor{comment}{/*\ always\ null\ terminate\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00379}00379\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00380}00380\ \ \ \ \ \ \ \ \ \ \ \ \ use\_buffer(\ file,\ want\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00381}00381\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00382}00382\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00383}00383\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00384}00384\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unknown\ or\ supported\ type\ -\/\ oh\ dear\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00385}00385\ \ \ \ \ \ \ \ \ \ \ \ \ ptr\ =\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00386}00386\ \ \ \ \ \ \ \ \ \ \ \ \ errno\ =\ EBADF;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00387}00387\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00388}00388\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00389}00389\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00390}00390\ \ \ \ \ \textcolor{keywordflow}{return}\ ptr;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*success\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00391}00391\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00392}00392\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00393}\mbox{\hyperlink{fopen_8c_a136dc33c053055258c690193177cc0af}{00393}}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{fopen_8c_a136dc33c053055258c690193177cc0af}{url\_rewind}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *file\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00394}00394\ \ \ \ \ \textcolor{keywordflow}{switch}\ (\ file-\/>\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}}\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00395}00395\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00396}00396\ \ \ \ \ \ \ \ \ \ \ \ \ rewind(\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.file\ );\ \ \textcolor{comment}{/*\ passthrough\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00397}00397\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00398}00398\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00399}00399\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}:}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00400}00400\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ halt\ transaction\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00401}00401\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_multi\_remove\_handle(\ multi\_handle,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00402}00402\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00403}00403\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ restart\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00404}00404\ \ \ \ \ \ \ \ \ \ \ \ \ curl\_multi\_add\_handle(\ multi\_handle,\ file-\/>\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}}.curl\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00405}00405\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00406}00406\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ ditch\ buffer\ -\/\ write\ will\ recreate\ -\/\ resets\ stream\ pos\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00407}00407\ \ \ \ \ \ \ \ \ \ \ \ \ free(\ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00408}00408\ \ \ \ \ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}}\ =\ NULL;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00409}00409\ \ \ \ \ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00410}00410\ \ \ \ \ \ \ \ \ \ \ \ \ file-\/>\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00411}00411\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00412}00412\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00413}00413\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00414}00414\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unknown\ or\ supported\ type\ -\/\ oh\ dear\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00415}00415\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00416}00416\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00417}00417\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00418}00418\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00419}00419\ \textcolor{preprocessor}{\#ifdef\ FOPEN\_STANDALONE}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00420}00420\ \textcolor{preprocessor}{\#define\ FGETSFILE\ "{}fgets.test"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00421}00421\ \textcolor{preprocessor}{\#define\ FREADFILE\ "{}fread.test"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00422}00422\ \textcolor{preprocessor}{\#define\ REWINDFILE\ "{}rewind.test"{}}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00423}00423\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00424}00424\ \textcolor{comment}{/*\ Small\ main\ program\ to\ retrieve\ from\ a\ url\ using\ fgets\ and\ fread\ saving\ the}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00425}00425\ \textcolor{comment}{\ *\ output\ to\ two\ test\ files\ (note\ the\ fgets\ method\ will\ corrupt\ binary\ files\ if}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00426}00426\ \textcolor{comment}{\ *\ they\ contain\ 0\ chars\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00427}00427\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{init_8c_a0ddf1224851353fc92bfbff6f499fa97}{main}}(\ \textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[]\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00428}00428\ \ \ \ \ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *handle;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00429}00429\ \ \ \ \ FILE\ *outf;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00430}00430\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00431}00431\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ nread;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00432}00432\ \ \ \ \ \textcolor{keywordtype}{char}\ buffer[256];}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00433}00433\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *url;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00434}00434\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00435}00435\ \ \ \ \ CURL\ *curl;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00436}00436\ \ \ \ \ CURLcode\ res;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00437}00437\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00438}00438\ \ \ \ \ curl\_global\_init(\ CURL\_GLOBAL\_DEFAULT\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00439}00439\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00440}00440\ \ \ \ \ curl\ =\ curl\_easy\_init(\ \ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00441}00441\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00442}00442\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00443}00443\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ argc\ <\ 2\ )}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00444}00444\ \ \ \ \ \ \ \ \ url\ =\ \textcolor{stringliteral}{"{}http://192.168.7.3/testfile"{}};\ \ \textcolor{comment}{/*\ default\ to\ testurl\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00445}00445\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00446}00446\ \ \ \ \ \ \ \ \ url\ =\ argv[1];\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ use\ passed\ url\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00447}00447\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00448}00448\ \ \ \ \ \textcolor{comment}{/*\ copy\ from\ url\ line\ by\ line\ with\ fgets\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00449}00449\ \ \ \ \ outf\ =\ fopen(\ FGETSFILE,\ \textcolor{stringliteral}{"{}wb+"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00450}00450\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !outf\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00451}00451\ \ \ \ \ \ \ \ \ perror(\ \textcolor{stringliteral}{"{}couldn't\ open\ fgets\ output\ file\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00452}00452\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00453}00453\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00454}00454\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00455}00455\ \ \ \ \ handle\ =\ \mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ url,\ \textcolor{stringliteral}{"{}r"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00456}00456\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !handle\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00457}00457\ \ \ \ \ \ \ \ \ printf(\ \textcolor{stringliteral}{"{}couldn't\ url\_fopen()\ \%s\(\backslash\)n"{}},\ url\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00458}00458\ \ \ \ \ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00459}00459\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 2;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00460}00460\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00461}00461\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00462}00462\ \ \ \ \ \textcolor{keywordflow}{while}\ (\ !\mbox{\hyperlink{fopen_8c_a216d4da618cba31eb9b2badf6d5de2d9}{url\_feof}}(\ handle\ )\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00463}00463\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{fopen_8c_a581c0437f39131b6368dd163843afff8}{url\_fgets}}(\ buffer,\ \textcolor{keyword}{sizeof}(\ buffer\ ),\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00464}00464\ \ \ \ \ \ \ \ \ fwrite(\ buffer,\ 1,\ strlen(\ buffer\ ),\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00465}00465\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00466}00466\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00467}00467\ \ \ \ \ \mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00468}00468\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00469}00469\ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00470}00470\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00471}00471\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00472}00472\ \ \ \ \ \textcolor{comment}{/*\ Copy\ from\ url\ with\ fread\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00473}00473\ \ \ \ \ outf\ =\ fopen(\ FREADFILE,\ \textcolor{stringliteral}{"{}wb+"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00474}00474\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !outf\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00475}00475\ \ \ \ \ \ \ \ \ perror(\ \textcolor{stringliteral}{"{}couldn't\ open\ fread\ output\ file\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00476}00476\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00477}00477\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00478}00478\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00479}00479\ \ \ \ \ handle\ =\ \mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ \textcolor{stringliteral}{"{}testfile"{}},\ \textcolor{stringliteral}{"{}r"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00480}00480\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !handle\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00481}00481\ \ \ \ \ \ \ \ \ printf(\ \textcolor{stringliteral}{"{}couldn't\ url\_fopen()\ testfile\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00482}00482\ \ \ \ \ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00483}00483\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 2;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00484}00484\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00485}00485\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00486}00486\ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00487}00487\ \ \ \ \ \ \ \ \ nread\ =\ \mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{url\_fread}}(\ buffer,\ 1,\ \textcolor{keyword}{sizeof}(\ buffer\ ),\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00488}00488\ \ \ \ \ \ \ \ \ fwrite(\ buffer,\ 1,\ nread,\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00489}00489\ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (\ nread\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00490}00490\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00491}00491\ \ \ \ \ \mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00492}00492\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00493}00493\ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00494}00494\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00495}00495\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00496}00496\ \ \ \ \ \textcolor{comment}{/*\ Test\ rewind\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00497}00497\ \ \ \ \ outf\ =\ fopen(\ REWINDFILE,\ \textcolor{stringliteral}{"{}wb+"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00498}00498\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !outf\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00499}00499\ \ \ \ \ \ \ \ \ perror(\ \textcolor{stringliteral}{"{}couldn't\ open\ fread\ output\ file\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00500}00500\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00501}00501\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00502}00502\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00503}00503\ \ \ \ \ handle\ =\ \mbox{\hyperlink{fopen_8c_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ \textcolor{stringliteral}{"{}testfile"{}},\ \textcolor{stringliteral}{"{}r"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00504}00504\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ !handle\ )\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00505}00505\ \ \ \ \ \ \ \ \ printf(\ \textcolor{stringliteral}{"{}couldn't\ url\_fopen()\ testfile\(\backslash\)n"{}}\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00506}00506\ \ \ \ \ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00507}00507\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 2;}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00508}00508\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00509}00509\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00510}00510\ \ \ \ \ nread\ =\ \mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{url\_fread}}(\ buffer,\ 1,\ \textcolor{keyword}{sizeof}(\ buffer\ ),\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00511}00511\ \ \ \ \ fwrite(\ buffer,\ 1,\ nread,\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00512}00512\ \ \ \ \ \mbox{\hyperlink{fopen_8c_a136dc33c053055258c690193177cc0af}{url\_rewind}}(\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00513}00513\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00514}00514\ \ \ \ \ buffer[0]\ =\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00515}00515\ \ \ \ \ fwrite(\ buffer,\ 1,\ 1,\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00516}00516\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00517}00517\ \ \ \ \ nread\ =\ \mbox{\hyperlink{fopen_8c_ac0b29ae4a1d13706b283789ef93ed27b}{url\_fread}}(\ buffer,\ 1,\ \textcolor{keyword}{sizeof}(\ buffer\ ),\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00518}00518\ \ \ \ \ fwrite(\ buffer,\ 1,\ nread,\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00519}00519\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00520}00520\ \ \ \ \ \mbox{\hyperlink{fopen_8c_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ handle\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00521}00521\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00522}00522\ \ \ \ \ fclose(\ outf\ );}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00523}00523\ }
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00524}00524\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ all\ done\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00525}00525\ \}}
\DoxyCodeLine{\Hypertarget{fopen_8c_source_l00526}00526\ \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
