\hypertarget{eet-file_8c-example}{}\section{eet-\/file.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o eet-file eet-file.c `pkg-config --cflags --libs eet`}

\textcolor{preprocessor}{#include <\hyperlink{Eet_8h}{Eet.h}>}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <string.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{int}
create\_eet\_file(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef;
   \textcolor{keywordtype}{char} buf[1024], *ptr;
   \textcolor{keywordtype}{int} size, len, i;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *some\_strings[] = \{
      \textcolor{stringliteral}{"And some more strings"},
      \textcolor{stringliteral}{"spread across several"},
      \textcolor{stringliteral}{"elements of an array!"}
   \};
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} some\_data[] =
     \textcolor{stringliteral}{"\(\backslash\)x1e\(\backslash\)xe7\(\backslash\)x0f\(\backslash\)x42\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x01\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x35"}
     \textcolor{stringliteral}{"\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)xa0\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)xa0\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x24\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x11"}
     \textcolor{stringliteral}{"\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x2f\(\backslash\)x6d\(\backslash\)x69\(\backslash\)x73\(\backslash\)x74\(\backslash\)x65\(\backslash\)x72\(\backslash\)x69\(\backslash\)x6f\(\backslash\)x75\(\backslash\)x73\(\backslash\)x2f"}
     \textcolor{stringliteral}{"\(\backslash\)x64\(\backslash\)x61\(\backslash\)x74\(\backslash\)x61\(\backslash\)x00\(\backslash\)x41\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x45\(\backslash\)x45\(\backslash\)x54\(\backslash\)x20\(\backslash\)x69\(\backslash\)x6e\(\backslash\)x73\(\backslash\)x69"}
     \textcolor{stringliteral}{"\(\backslash\)x64\(\backslash\)x65\(\backslash\)x20\(\backslash\)x6f\(\backslash\)x66\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x45\(\backslash\)x45\(\backslash\)x54\(\backslash\)x21\(\backslash\)x0a\(\backslash\)x54\(\backslash\)x68"}
     \textcolor{stringliteral}{"\(\backslash\)x69\(\backslash\)x73\(\backslash\)x20\(\backslash\)x77\(\backslash\)x61\(\backslash\)x73\(\backslash\)x6e\(\backslash\)x27\(\backslash\)x74\(\backslash\)x20\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x6c\(\backslash\)x6c\(\backslash\)x79"}
     \textcolor{stringliteral}{"\(\backslash\)x20\(\backslash\)x75\(\backslash\)x73\(\backslash\)x65\(\backslash\)x66\(\backslash\)x75\(\backslash\)x6c\(\backslash\)x20\(\backslash\)x62\(\backslash\)x75\(\backslash\)x74\(\backslash\)x20\(\backslash\)x69\(\backslash\)x74\(\backslash\)x20\(\backslash\)x68"}
     \textcolor{stringliteral}{"\(\backslash\)x65\(\backslash\)x6c\(\backslash\)x70\(\backslash\)x65\(\backslash\)x64\(\backslash\)x20\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x73\(\backslash\)x68\(\backslash\)x6f\(\backslash\)x77\(\backslash\)x20\(\backslash\)x68\(\backslash\)x6f"}
     \textcolor{stringliteral}{"\(\backslash\)x77\(\backslash\)x0a\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x75\(\backslash\)x73\(\backslash\)x65\(\backslash\)x20\(\backslash\)x65\(\backslash\)x65\(\backslash\)x74\(\backslash\)x5f\(\backslash\)x6d\(\backslash\)x65\(\backslash\)x6d"}
     \textcolor{stringliteral}{"\(\backslash\)x6f\(\backslash\)x70\(\backslash\)x65\(\backslash\)x6e\(\backslash\)x5f\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x64\(\backslash\)x28\(\backslash\)x29\(\backslash\)x20\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x6f"}
     \textcolor{stringliteral}{"\(\backslash\)x70\(\backslash\)x65\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x65\(\backslash\)x65\(\backslash\)x74\(\backslash\)x20\(\backslash\)x66\(\backslash\)x69\(\backslash\)x6c\(\backslash\)x65\(\backslash\)x20"}
     \textcolor{stringliteral}{"\(\backslash\)x66\(\backslash\)x72\(\backslash\)x6f\(\backslash\)x6d\(\backslash\)x0a\(\backslash\)x64\(\backslash\)x61\(\backslash\)x74\(\backslash\)x61\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6c\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x64"}
     \textcolor{stringliteral}{"\(\backslash\)x79\(\backslash\)x20\(\backslash\)x6c\(\backslash\)x6f\(\backslash\)x61\(\backslash\)x64\(\backslash\)x65\(\backslash\)x64\(\backslash\)x20\(\backslash\)x69\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x6d\(\backslash\)x65\(\backslash\)x6d\(\backslash\)x6f"}
     \textcolor{stringliteral}{"\(\backslash\)x72\(\backslash\)x79\(\backslash\)x2e\(\backslash\)x0a\(\backslash\)x00"};

   ef = \hyperlink{group__Eet__File__Group_ga5f55956b860aa2c77af9b1a880c4c256}{eet\_open}(\textcolor{stringliteral}{"/tmp/my\_file.eet"}, \hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a8f395f56fba48be007c65be51d799ee9}{EET\_FILE\_MODE\_WRITE});
   \textcolor{keywordflow}{if} (!ef) \textcolor{keywordflow}{return} 0;

   strcpy(buf, \textcolor{stringliteral}{"Here is a string of data to save!"});
   size = \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/key/to\_store/at"}, buf, \textcolor{keyword}{sizeof}(buf), 1);
   \textcolor{keywordflow}{if} (!size)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error writing data!\(\backslash\)n"});
        \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef);
        \textcolor{keywordflow}{return} 0;
     \}
   len = strlen(buf);
   printf(\textcolor{stringliteral}{"strlen() = %d, eet\_write() = %d\(\backslash\)n"}, len, size);

   ptr = buf;
   \textcolor{keywordflow}{for} (i = 0; i < 3; i++)
     \{
        len = strlen(some\_strings[i]) + 1;
        memcpy(ptr, some\_strings[i], len);
        ptr += len;
     \}
   \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/several/strings"}, buf, \textcolor{keyword}{sizeof}(buf), 1);
   \hyperlink{group__Eet__File__Group_gaf343f344180955ed898aa86b90ebefda}{eet\_sync}(ef);

   \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/some/mysterious/data"}, some\_data, \textcolor{keyword}{sizeof}(some\_data) - 1, 1);

   \hyperlink{group__Eet__File__Group_gaa8a980d684123dfbaf12e7efefdb57f5}{eet\_delete}(ef, \textcolor{stringliteral}{"/several/strings"});

   \textcolor{keywordflow}{return} \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef) == \hyperlink{group__Eet__Group_ggaa9142d865094701672375485d4a6284da2e3af24c66d0decf7c97fe4e5a7f75d4}{EET\_ERROR\_NONE};
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef;
   \textcolor{keywordtype}{char} *ret, **list;
   \textcolor{keywordtype}{int} size, num, i;

   \hyperlink{group__Eet__Group_ga9903687bfa20fe9a9e59d4c1d213e89a}{eet\_init}();

   \textcolor{keywordflow}{if} (!create\_eet\_file())
     \textcolor{keywordflow}{return} -1;

   ef = \hyperlink{group__Eet__File__Group_ga5f55956b860aa2c77af9b1a880c4c256}{eet\_open}(\textcolor{stringliteral}{"/tmp/my\_file.eet"}, \hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a416f7e9a76b8131a44bbeedb13060c81}{EET\_FILE\_MODE\_READ});
   \textcolor{keywordflow}{if} (!ef) \textcolor{keywordflow}{return} -1;

   list = \hyperlink{group__Eet__File__Group_ga6700a425f59086e7c8a945d6923874d3}{eet\_list}(ef, \textcolor{stringliteral}{"*"}, &num);
   \textcolor{keywordflow}{if} (list)
     \{
        \textcolor{keywordflow}{for} (i = 0; i < num; i++)
          printf(\textcolor{stringliteral}{"Key stored: %s\(\backslash\)n"}, list[i]);
        free(list);
     \}

   ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/key/to\_store/at"}, &size);
   \textcolor{keywordflow}{if} (ret)
     \{
        printf(\textcolor{stringliteral}{"Data read (%i bytes):\(\backslash\)n%s\(\backslash\)n"}, size, ret);
        free(ret);
     \}

   ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/several/strings"}, &size);
   \textcolor{keywordflow}{if} (ret)
     \{
        printf(\textcolor{stringliteral}{"More data read (%i bytes):\(\backslash\)n%s\(\backslash\)n"}, size, ret);
        free(ret);
     \}

   ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/some/mysterious/data"}, &size);
   \textcolor{keywordflow}{if} (ret)
     \{
        \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef2;

        ef2 = \hyperlink{group__Eet__File__Group_gac514fa1812cfe27f0b7c0ff5fc13af45}{eet\_memopen\_read}(ret, size);

        num = \hyperlink{group__Eet__File__Group_ga53bf1cf96267787aa93a99a0fe7ba8f7}{eet\_num\_entries}(ef2);
        printf(\textcolor{stringliteral}{"Mysterious data has %d entries\(\backslash\)n"}, num);

        printf(\textcolor{stringliteral}{"Mysterious data:\(\backslash\)n%s\(\backslash\)n"},
               (\textcolor{keywordtype}{char} *)\hyperlink{group__Eet__File__Group_ga73852ab3d1276c2913715b3716cf4a04}{eet\_read\_direct}(ef2, \textcolor{stringliteral}{"/mysterious/data"}, NULL));

        \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef2);

        free(ret);
     \}

   \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef);

   \hyperlink{group__Eet__Group_gacbc7583179399d3b3e7b003e911f866f}{eet\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}
 