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't work with multiple threads or when returning multilpe 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 paramater 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}
\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr} *my\_homedir(\textcolor{keywordtype}{void}) \{
  \textcolor{keywordflow}{return} \hyperlink{group__Eina__Stringshare__Group_gadb653e2dd0baf58b7f8bb7eea1753b2b}{eina\_tmpstr\_add}(getenv(\textcolor{stringliteral}{"HOME"}));
\}

\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr} *my\_tmpdir(\textcolor{keywordtype}{void}) \{
  \textcolor{keywordflow}{return} \hyperlink{group__Eina__Stringshare__Group_gadb653e2dd0baf58b7f8bb7eea1753b2b}{eina\_tmpstr\_add}(getenv(\textcolor{stringliteral}{"TMP"}));
\}

\textcolor{keywordtype}{void} my\_movefile(\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr} *src, \hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr} *dst) \{
  \hyperlink{evil__stdio_8h_ab92755272ef649e2c6e74ab80def85be}{rename}(src, dst);
  \hyperlink{group__Eina__Stringshare__Group_gaa84ec3cc6c63bc67355aa3cbaa26189f}{eina\_tmpstr\_del}(src);
  \hyperlink{group__Eina__Stringshare__Group_gaa84ec3cc6c63bc67355aa3cbaa26189f}{eina\_tmpstr\_del}(dst);
\}

\textcolor{keywordtype}{char} buf[500];
my\_movefile(my\_homedir(), my\_tmpdir());
my\_movefile(\textcolor{stringliteral}{"/tmp/file"}, \textcolor{stringliteral}{"/tmp/newname"});
my\_movefile(my\_homedir(), \textcolor{stringliteral}{"/var/tmp"});
snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"/tmp/%i.file"}, rand());
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. 