70 lines
7.6 KiB
TeX
70 lines
7.6 KiB
TeX
\doxysection{file.\+c}
|
|
\hypertarget{file_8c_source}{}\label{file_8c_source}\mbox{\hyperlink{file_8c}{Go to the documentation of this file.}}
|
|
\begin{DoxyCode}{0}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00001}00001\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{file_8h}{file.h}}"{}}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00002}00002\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00003}00003\ \textcolor{comment}{/*}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00004}00004\ \textcolor{comment}{\ *\ Here\ we\ load\ a\ file\ and\ write\ the\ file\ as\ string\ to\ a\ memory\ address:}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00005}00005\ \textcolor{comment}{\ *\ Input:}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00006}00006\ \textcolor{comment}{\ *\ \ \ \ \ \ char*\ fname:\ the\ name\ of\ the\ file\ to\ open}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00007}00007\ \textcolor{comment}{\ *\ \ \ \ \ \ int\ cbSize:\ the\ size\ of\ the\ strContent}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00008}00008\ \textcolor{comment}{\ *\ Output:}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00009}00009\ \textcolor{comment}{\ *\ \ \ \ \ \ char\ **strContent:\ a\ pointer\ to\ a\ address\ where\ you\ have\ to\ allocate\ enougth\ memory\ to\ store\ the\ whole\ file}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00010}00010\ \textcolor{comment}{\ *\ \ \ \ \ \ int\ neededSize:\ this\ returns\ the\ needed\ size\ of\ the\ buffer\ strContent}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00011}00011\ \textcolor{comment}{\ *}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00012}00012\ \textcolor{comment}{\ *\ \ Note:}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00013}00013\ \textcolor{comment}{\ *\ \ \ \ \ \ to\ get\ the\ size\ define\ strContent\ as\ NULL,\ then\ the\ needed\ size\ will\ return\ the\ needed\ buffersize}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00014}00014\ \textcolor{comment}{\ *}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00015}00015\ \textcolor{comment}{\ *}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00016}00016\ \textcolor{comment}{\ */}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00017}\mbox{\hyperlink{file_8c_a415337a87938760b49ba4c0d74ab6c6a}{00017}}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{file_8c_a415337a87938760b49ba4c0d74ab6c6a}{getFile}}(\textcolor{keywordtype}{char}\ *fname,\ \textcolor{keywordtype}{char}\ **strContent,\textcolor{keywordtype}{int}\ cbSize,\textcolor{keywordtype}{long}\ *neededSize)}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00018}00018\ \{}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00019}00019\ \ \ \ \ FILE\ *hfile\ =\ fopen(fname,\textcolor{stringliteral}{"{}r"{}});}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00020}00020\ \ \ \ \ \textcolor{keywordtype}{long}\ file\_size=0;}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00021}00021\ \ \ \ \ \textcolor{keywordtype}{int}\ ret=0;}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00022}00022\ \ \ \ \ \textcolor{keywordflow}{if}(hfile\ ==\ NULL)}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00023}00023\ \ \ \ \ \{}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00024}00024\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{file_8h_a44d189cf44f6ef2cb48c2f22c7824469}{FILE\_ERROR\_OPEN}};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00025}00025\ \ \ \ \ \}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00026}00026\ \ \ \ \ }
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00027}00027\ \ \ \ \ printf(\textcolor{stringliteral}{"{}file\ openend:\%s"{}},fname);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00028}00028\ \ \ \ fseek(hfile,0,SEEK\_END);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00029}00029\ \ \ \ file\_size\ =\ ftell(hfile);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00030}00030\ \ \ \ \ \textcolor{keywordflow}{if}(strContent\ ==\ NULL)\ \textcolor{comment}{//we\ must\ determine\ the\ size\ and\ return\ to\ neededSize}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00031}00031\ \ \ \ \ \{}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00032}00032\ \ \ \ \ \ \ \ \ *neededSize\ =\ file\_size+1;}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00033}00033\ \ \ \ \ \ \ \ \ fclose(hfile);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00034}00034\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{config_8h_a258bb72419ef143530a2f8f55e7d57af}{NO\_ERROR}};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00035}00035\ \ \ \ \ \}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00036}00036\ }
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00037}00037\ \ \ \ \ \textcolor{keywordflow}{if}(cbSize\ <\ file\_size)}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00038}00038\ \ \ \ \ \{}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00039}00039\ \ \ \ \ \ \ \ \ *neededSize\ =\ file\_size+1;\ \textcolor{comment}{//null\ terminator}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00040}00040\ \ \ \ \ \ \ \ \ fclose(hfile);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00041}00041\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{file_8h_a12f43bc1d8b150bb55c18877bbe612ac}{FILE\_ERROR\_STRCONTENT\_TO\_SMALL}};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00042}00042\ \ \ \ \ \}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00043}00043\ }
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00044}00044\ \ \ \ \ fseek(hfile,0,SEEK\_SET);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00045}00045\ \ \ \ \ ret=fread(*strContent,file\_size,1,hfile);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00046}00046\ \ \ \ \ \textcolor{keywordflow}{if}(ret\ !=\ 1)}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00047}00047\ \ \ \ \ \{}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00048}00048\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Reading\ error\ read\ and\ should\ read\ missmatch\(\backslash\)nnumber\ written\ elements:\%d\(\backslash\)n"{}},}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00049}00049\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ret);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00050}00050\ \ \ \ \ \ \ \ \ fclose(hfile);}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00051}00051\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{file_8h_aa161b7390609303815b39df4a4850cfc}{FILE\_ERROR\_READ\_MISMATCH}};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00052}00052\ \ \ \ \ \}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00053}00053\ \ \ \ \ \textcolor{comment}{//buffer\ end-\/1\ =\ \(\backslash\)0}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00054}00054\ \ \ \ \ \textcolor{comment}{//buffer\ end-\/2\ =\ \(\backslash\)n}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00055}00055\ \ \ \ \ \textcolor{comment}{//buffer\ end-\/3\ =\ last\ character}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00056}00056\ \ \ \ \ printf(\textcolor{stringliteral}{"{}strcontent:\ \%ld,\ [\%c]\(\backslash\)n"{}},*neededSize,*(*strContent+\ *neededSize-\/3));}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00057}00057\ \ \ \ \ *(*strContent\ +\ *neededSize\ -\/1)\ =\textcolor{charliteral}{'\(\backslash\)0'};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00058}00058\ \ \ \ \ printf(\textcolor{stringliteral}{"{}after\ zero\ assign:\ \%ld,\ \%s\(\backslash\)n"{}},*neededSize,(*strContent+\ *neededSize-\/1));}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00059}00059\ \ \ \ \ \textcolor{comment}{//printf("{}content:\%s"{},*strContent);}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00060}00060\ \ \ \ \ fclose(hfile);\ \ \ \ \ \ \ \ \ \ \ }
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00061}00061\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{config_8h_a258bb72419ef143530a2f8f55e7d57af}{NO\_ERROR}};}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00062}00062\ \}}
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00063}00063\ }
|
|
\DoxyCodeLine{\Hypertarget{file_8c_source_l00064}00064\ }
|
|
|
|
\end{DoxyCode}
|