\doxysection{fopen.\+h}
\hypertarget{fopen_8h_source}{}\label{fopen_8h_source}\index{workspace/post-\/scarcity/src/io/fopen.h@{workspace/post-\/scarcity/src/io/fopen.h}}
\mbox{\hyperlink{fopen_8h}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00001}00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00002}00002\ \textcolor{comment}{\ *\ fopen.h}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00003}00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00004}00004\ \textcolor{comment}{\ *\ adapted\ from\ https://curl.haxx.se/libcurl/c/fopen.html.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00005}00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00006}00006\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00007}00007\ \textcolor{comment}{\ *\ Modifications\ to\ read/write\ wide\ character\ streams\ by}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00008}00008\ \textcolor{comment}{\ *\ Simon\ Brooke.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00009}00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00010}00010\ \textcolor{comment}{\ *\ NOTE\ THAT:\ for\ my\ purposes,\ I'm\ only\ interested\ in\ wide\ characters,}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00011}00011\ \textcolor{comment}{\ *\ and\ I\ always\ read\ them\ one\ character\ at\ a\ time.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00012}00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00013}00013\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2003,\ 2017\ Simtec\ Electronics}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00014}00014\ \textcolor{comment}{\ *\ Some\ portions\ (c)\ 2019\ Simon\ Brooke\ <simon@journeyman.cc>}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00015}00015\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00016}00016\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00017}00017\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00018}00018\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00019}00019\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00020}00020\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00021}00021\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00022}00022\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in\ the}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00023}00023\ \textcolor{comment}{\ *\ \ \ \ documentation\ and/or\ other\ materials\ provided\ with\ the\ distribution.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00024}00024\ \textcolor{comment}{\ *\ 3.\ The\ name\ of\ the\ author\ may\ not\ be\ used\ to\ endorse\ or\ promote\ products}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00025}00025\ \textcolor{comment}{\ *\ \ \ \ derived\ from\ this\ software\ without\ specific\ prior\ written\ permission.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00026}00026\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00027}00027\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ THE\ AUTHOR\ \`{}\`{}AS\ IS''\ AND\ ANY\ EXPRESS\ OR}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00028}00028\ \textcolor{comment}{\ *\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ THE\ IMPLIED\ WARRANTIES}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00029}00029\ \textcolor{comment}{\ *\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR\ PURPOSE\ ARE\ DISCLAIMED.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00030}00030\ \textcolor{comment}{\ *\ IN\ NO\ EVENT\ SHALL\ THE\ AUTHOR\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00031}00031\ \textcolor{comment}{\ *\ INCIDENTAL,\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00032}00032\ \textcolor{comment}{\ *\ NOT\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00033}00033\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00034}00034\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00035}00035\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ OF}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00036}00036\ \textcolor{comment}{\ *\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00037}00037\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00038}00038\ \textcolor{comment}{\ *\ This\ example\ requires\ libcurl\ 7.9.7\ or\ later.}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00039}00039\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00040}00040\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00041}00041\ \textcolor{preprocessor}{\#ifndef\ \_\_fopen\_h}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00042}00042\ \textcolor{preprocessor}{\#define\ \_\_fopen\_h}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00043}00043\ \textcolor{preprocessor}{\#include\ <curl/curl.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00044}00044\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00045}00045\ \textcolor{comment}{\ *\ wide\ characters}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00046}00046\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00047}00047\ \textcolor{preprocessor}{\#include\ <wchar.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00048}00048\ \textcolor{preprocessor}{\#include\ <wctype.h>}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00049}00049\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00050}\mbox{\hyperlink{fopen_8h_ac88d8de2499a3cdc3a4c7c4f5a4424e8}{00050}}\ \textcolor{preprocessor}{\#define\ url\_fwprintf(f,\ ...)\ ((f-\/>type\ =\ CFTYPE\_FILE)\ ?\ fwprintf(\ f-\/>handle.file,\ \_\_VA\_ARGS\_\_)\ :\ -\/1)}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00051}\mbox{\hyperlink{fopen_8h_a862d5262a566cd54dab0677ebf57371d}{00051}}\ \textcolor{preprocessor}{\#define\ url\_fputws(ws,\ f)\ ((f-\/>type\ =\ CFTYPE\_FILE)\ ?\ \ fputws(ws,\ f-\/>handle.file)\ :\ 0)}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00052}\mbox{\hyperlink{fopen_8h_a014681924c4591cdcc58d12017611e31}{00052}}\ \textcolor{preprocessor}{\#define\ url\_fputwc(wc,\ f)\ ((f-\/>type\ =\ CFTYPE\_FILE)\ ?\ \ fputwc(wc,\ f-\/>handle.file)\ :\ 0)}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00053}00053\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00054}\mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12}{00054}}\ \textcolor{keyword}{enum}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12}{fcurl\_type\_e}}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00055}\mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12abf2aa2baf8c5c768bee2228c2991c0a7}{00055}}\ \ \ \ \ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12abf2aa2baf8c5c768bee2228c2991c0a7}{CFTYPE\_NONE}}\ =\ 0,}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00056}\mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{00056}}\ \ \ \ \ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a3cbcf3d97506c91623b1e0641c3671b4}{CFTYPE\_FILE}}\ =\ 1,}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00057}00057\ \ \ \ \ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{CFTYPE\_CURL}}\ =\ 2}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00058}\mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12a008570f612978c91c772a226badbee17}{00058}}\ \};}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00059}00059\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00060}\mbox{\hyperlink{fopen_8h}{00060}}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{fopen_8h_structfcurl__data}{fcurl\_data}}\ \{}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00061}\mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{00061}}\ \ \ \ \ \textcolor{keyword}{enum}\ \mbox{\hyperlink{fopen_8h_a529ac570f58a46fd897c0d4c40d97c12}{fcurl\_type\_e}}\ \mbox{\hyperlink{fopen_8h_a3f626b0c4d351deff31d373b1987f5a7}{type}};\ \ \ \ \ \textcolor{comment}{/*\ type\ of\ handle\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00062}\mbox{\hyperlink{fopen_8h}{00062}}\ \ \ \ \ \textcolor{keyword}{union\ }\{}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00063}00063\ \ \ \ \ \ \ \ \ CURL\ *curl;}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00064}00064\ \ \ \ \ \ \ \ \ FILE\ *file;}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00065}\mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{00065}}\ \ \ \ \ \}\ \mbox{\hyperlink{fopen_8h_a61eb2fbb79b1d44fffa49dd0a194e09b}{handle}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ handle\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00066}00066\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00067}\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{00067}}\ \ \ \ \ \textcolor{keywordtype}{char}\ *\mbox{\hyperlink{fopen_8h_aff2566f4c366b48d73479bef43ee4d2e}{buffer}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ buffer\ to\ store\ cached\ data\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00068}\mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{00068}}\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{fopen_8h_a6bfa135ea1282c77528701bbb081ed06}{buffer\_len}};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ currently\ allocated\ buffer's\ length\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00069}\mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{00069}}\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{fopen_8h_ad772d2f9803cdbdf265ba17194a1314c}{buffer\_pos}};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ cursor\ into\ in\ buffer\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00070}\mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{00070}}\ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8h_a01acc90c6f8ec9a702b10ef31b3290c5}{still\_running}};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Is\ background\ url\ fetch\ still\ in\ progress\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00071}00071\ \};}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00072}00072\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00073}\mbox{\hyperlink{fopen_8h_a8c81a077422f5e2410ba71eb75108f6e}{00073}}\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{fopen_8h_structfcurl__data}{fcurl\_data}}\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}};}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00074}00074\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00075}00075\ \textcolor{comment}{/*\ exported\ functions\ */}}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00076}00076\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\mbox{\hyperlink{fopen_8h_a26798feb43118ca8efe6fde1aa0dcaba}{url\_fopen}}(\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *url,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *operation\ );}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00077}00077\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8h_ae855f8141739dd05eb4a2319006d1177}{url\_fclose}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00078}00078\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{fopen_8h_a216d4da618cba31eb9b2badf6d5de2d9}{url\_feof}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00079}00079\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{fopen_8h_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_8h_source_l00080}00080\ \textcolor{keywordtype}{char}\ *\mbox{\hyperlink{fopen_8h_a581c0437f39131b6368dd163843afff8}{url\_fgets}}(\ \textcolor{keywordtype}{char}\ *ptr,\ \textcolor{keywordtype}{size\_t}\ size,\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00081}00081\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{fopen_8h_a136dc33c053055258c690193177cc0af}{url\_rewind}}(\ \mbox{\hyperlink{fopen_8h_structfcurl__data}{URL\_FILE}}\ *\ file\ );}
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00082}00082\ }
\DoxyCodeLine{\Hypertarget{fopen_8h_source_l00083}00083\ \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
