eina_tmpstr_ppage(3)

NAME
eina_tmpstr_ppage - 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 multiple times as parameters to a single function.

The traditional way to 'return' 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:

Eina_Tmpstr *my_homedir(void) {
  return eina_tmpstr_add(eina_environment_home_get());
}
Eina_Tmpstr *my_tmpdir(void) {
  return eina_tmpstr_add(getenv("TMP"));
}
void my_movefile(Eina_Tmpstr *src, Eina_Tmpstr *dst) {
  rename(src, dst);
  eina_tmpstr_del(src);
  eina_tmpstr_del(dst);
}
char buf[500];
my_movefile(my_homedir(), my_tmpdir());
my_movefile("/tmp/file", "/tmp/newname");
my_movefile(my_homedir(), "/var/tmp");
snprintf(buf, sizeof(buf), "/tmp/%i.file", rand());
my_movefile("/tmp.file", buf);

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.