Eina tmpstr is intended for being able to conveniently pass strings back to a calling parent without having to use single static buffers (which don\textquotesingle{}t work with multiple threads or when returning multiple times as parameters to a single function.

The traditional way to \char`\"{}return\char`\"{} a string in C is either to provide a buffer as a parameter to return it in, return a pointer to a single static buffer, which has issues, or return a duplicated string. All cases are inconvenient and return special handling. This is intended to make this easier. Now you can do something like this\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr}}\ *my\_homedir(\textcolor{keywordtype}{void})\ \{}
\DoxyCodeLine{\ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga4d785a1e6484d0454568a580ee9e466f}{eina\_tmpstr\_add}}(\mbox{\hyperlink{group__Eina__Tools__Group_ga358b0d604ad29672a7ae31a4ce975a40}{eina\_environment\_home\_get}}());}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr}}\ *my\_tmpdir(\textcolor{keywordtype}{void})\ \{}
\DoxyCodeLine{\ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga4d785a1e6484d0454568a580ee9e466f}{eina\_tmpstr\_add}}(getenv(\textcolor{stringliteral}{"{}TMP"{}}));}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ my\_movefile(\mbox{\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr}}\ *src,\ \mbox{\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr}}\ *dst)\ \{}
\DoxyCodeLine{\ \ rename(src,\ dst);}
\DoxyCodeLine{\ \ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga0c32cf7aadbc1fcd60500d5bb9c03c93}{eina\_tmpstr\_del}}(src);}
\DoxyCodeLine{\ \ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga0c32cf7aadbc1fcd60500d5bb9c03c93}{eina\_tmpstr\_del}}(dst);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{char}\ buf[500];}
\DoxyCodeLine{my\_movefile(my\_homedir(),\ my\_tmpdir());}
\DoxyCodeLine{my\_movefile(\textcolor{stringliteral}{"{}/tmp/file"{}},\ \textcolor{stringliteral}{"{}/tmp/newname"{}});}
\DoxyCodeLine{my\_movefile(my\_homedir(),\ \textcolor{stringliteral}{"{}/var/tmp"{}});}
\DoxyCodeLine{snprintf(buf,\ \textcolor{keyword}{sizeof}(buf),\ \textcolor{stringliteral}{"{}/tmp/\%i.file"{}},\ rand());}
\DoxyCodeLine{my\_movefile(\textcolor{stringliteral}{"{}/tmp.file"{}},\ buf);}

\end{DoxyCode}


Notice that you can interchange standard C strings (static ones or even generated buffers) with tmpstrings. The Eina\+\_\+\+Tmpstr type is merely a type marker letting you know that the function will clean up those strings after use, and it is totally interchangeable with const char. 