\hypertarget{eina_error_01_8c-example}{}\section{eina\+\_\+error\+\_\+01.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -g eina\_error\_01.c -o eina\_error\_01 `pkg-config --cflags --libs eina`}

\textcolor{preprocessor}{#include <stdlib.h>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#include <eina\_main.h>}
\textcolor{preprocessor}{#include <eina\_error.h>}

\mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} MY\_ERROR\_NEGATIVE;
\mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} MY\_ERROR\_NULL;

\textcolor{keywordtype}{void} *data\_new()
\{
   \mbox{\hyperlink{group__Eina__Error__Group_ga80a8249f135460d4e07ebfe3f0a7bad1}{eina\_error\_set}}(0);

   \mbox{\hyperlink{group__Eina__Error__Group_ga80a8249f135460d4e07ebfe3f0a7bad1}{eina\_error\_set}}(MY\_ERROR\_NULL);
   \textcolor{keywordflow}{return} NULL;
\}

\textcolor{keywordtype}{int} test(\textcolor{keywordtype}{int} n)
\{
   \mbox{\hyperlink{group__Eina__Error__Group_ga80a8249f135460d4e07ebfe3f0a7bad1}{eina\_error\_set}}(0);

   \textcolor{keywordflow}{if} (n < 0)
     \{
        \mbox{\hyperlink{group__Eina__Error__Group_ga80a8249f135460d4e07ebfe3f0a7bad1}{eina\_error\_set}}(MY\_ERROR\_NEGATIVE);
        \textcolor{keywordflow}{return} 0;
     \}

   \textcolor{keywordflow}{return} 1;
\}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})
\{
   \textcolor{keywordtype}{void} *data;

   \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Eina__Main__Group_gafee4bfc0e509b6ffed6598edf6f4b3de}{eina\_init}}())
     \{
        printf (\textcolor{stringliteral}{"Error during the initialization of eina\_error module\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   MY\_ERROR\_NEGATIVE = \mbox{\hyperlink{group__Eina__Error__Group_ga004c7ceb7103cd5a698247ae3eb4578a}{eina\_error\_msg\_static\_register}}(\textcolor{stringliteral}{"Negative number"});
   MY\_ERROR\_NULL = \mbox{\hyperlink{group__Eina__Error__Group_ga004c7ceb7103cd5a698247ae3eb4578a}{eina\_error\_msg\_static\_register}}(\textcolor{stringliteral}{"NULL pointer"});

   data = data\_new();
   \textcolor{keywordflow}{if} (!data)
     \{
        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;

        err = \mbox{\hyperlink{group__Eina__Error__Group_gae0683831c4f8eebfdcb4f3cf1aef7052}{eina\_error\_get}}();
        \textcolor{keywordflow}{if} (err)
           printf(\textcolor{stringliteral}{"Error during memory allocation: %s\(\backslash\)n"},
                  \mbox{\hyperlink{group__Eina__Error__Group_ga3402bc58a9f854391eb35fa7650edda5}{eina\_error\_msg\_get}}(err));
     \}

   \textcolor{keywordflow}{if} (!test(0))
     \{
        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;

        err = \mbox{\hyperlink{group__Eina__Error__Group_gae0683831c4f8eebfdcb4f3cf1aef7052}{eina\_error\_get}}();
        \textcolor{keywordflow}{if} (err)
           printf(\textcolor{stringliteral}{"Error during test function: %s\(\backslash\)n"},
                  \mbox{\hyperlink{group__Eina__Error__Group_ga3402bc58a9f854391eb35fa7650edda5}{eina\_error\_msg\_get}}(err));
     \}

   \textcolor{keywordflow}{if} (!test(-1))
     \{
        \mbox{\hyperlink{group__Eina__Error__Group_ga95b3cbb33e987e7d92a81ea785001686}{Eina\_Error}} err;

        err = \mbox{\hyperlink{group__Eina__Error__Group_gae0683831c4f8eebfdcb4f3cf1aef7052}{eina\_error\_get}}();
        \textcolor{keywordflow}{if} (err)
           printf(\textcolor{stringliteral}{"Error during test function: %s\(\backslash\)n"},
                  \mbox{\hyperlink{group__Eina__Error__Group_ga3402bc58a9f854391eb35fa7650edda5}{eina\_error\_msg\_get}}(err));
     \}

   \mbox{\hyperlink{group__Eina__Main__Group_ga2c8b4020427108a30c44707af22c99d3}{eina\_shutdown}}();

   \textcolor{keywordflow}{return} EXIT\_SUCCESS;
\}
\end{DoxyCodeInclude}
 