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_gadb653e2dd0baf58b7f8bb7eea1753b2b}{eina\_tmpstr\_add}}(\mbox{\hyperlink{group__Eina__Tools__Group_gaaa4c9c9269f1cc1508ca0a785dec8c1c}{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_gadb653e2dd0baf58b7f8bb7eea1753b2b}{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_gaa84ec3cc6c63bc67355aa3cbaa26189f}{eina\_tmpstr\_del}}(src);}
\DoxyCodeLine{  \mbox{\hyperlink{group__Eina__Stringshare__Group_gaa84ec3cc6c63bc67355aa3cbaa26189f}{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. 