Tizen Native API

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.

eina_tmpstr_page

Functions

Eina_Tmpstreina_tmpstr_add (const char *str)
 Adds a new temporary string based on the input string.
Eina_Tmpstreina_tmpstr_add_length (const char *str, size_t length)
 Adds a new temporary string based on the input string and length.
size_t eina_tmpstr_strlen (Eina_Tmpstr *tmpstr)
 Returns the length of a temporary string including the '\0'.
void eina_tmpstr_del (Eina_Tmpstr *tmpstr)
 Deletes the temporary string if it is one, or ignores it if it is not.

Typedefs

typedef const char Eina_Tmpstr
 Interchangeable with "const char *", but still a good visual hint for the purpose. This indicates that the string is temporary and should be freed after use.

Typedef Documentation

Interchangeable with "const char *", but still a good visual hint for the purpose. This indicates that the string is temporary and should be freed after use.

Since (EFL) :
1.8.0

Function Documentation

Eina_Tmpstr* eina_tmpstr_add ( const char *  str)

Adds a new temporary string based on the input string.

Since (EFL) :
1.8.0
Since :
2.3.1
Remarks:
When you add a temporary string (tmpstr) it is expected to have a very short lifespan, and at any one time only a few of these are intended to exist. This is not intended for long term storage of strings. The intended use is the ability to safely pass strings as return values from functions directly into parameters of new functions and then have the string cleaned up automatically by the caller.
If str is NULL, or no memory space exists to store the tmpstr, then NULL is returned, otherwise a valid string pointer is returned that you can treat as any other C string (eg: strdup(tmpstr) or printf("%s\n", tmpstr) etc.). This string should be considered read-only and immutable, and when you are done with the string you should delete it using eina_tmpstr_del().

Example usage:

 Eina_Tmpstr *my_homedir(void) {
   return eina_tmpstr_add(getenv("HOME"));
 }

 void my_rmfile(Eina_Tmpstr *str) {
   if (!str) return;
   unlink(str);
   eina_tmpstr_del(str);
 }

 my_rmfile(my_homedir());
 my_rmfile("/tmp/file");
Parameters:
[in]strThe input string that is copied into the temp string
Returns:
A pointer to the tmp string that is a standard C string
See also:
eina_tmpstr_del()
eina_tmpstr_add_length()
Eina_Tmpstr* eina_tmpstr_add_length ( const char *  str,
size_t  length 
)

Adds a new temporary string based on the input string and length.

Since (EFL) :
1.8.0
Since :
2.3.1
Remarks:
When you add a temporary string (tmpstr) it is expected to have a very short lifespan, and at any one time only a few of these are intended to exist. This is not intended for long term storage of strings. The intended use is the ability to safely pass strings as return values from functions directly into parameters of new functions and then have the string cleaned up automatically by the caller.
If str is NULL, or no memory space exists to store the tmpstr, then NULL is returned, otherwise a valid string pointer is returned that you can treat as any other C string (eg strdup(tmpstr) or printf("%s\n", tmpstr) etc.). This string should be considered read-only and immutable, and when you are done with the string you should delete it using eina_tmpstr_del().
Note:
If the length is greater than the actual string, but still '\0' terminateed. Their won't be any crash and the string will be correct, but eina_tmpstr_strlen will return an erroneous length. So if you want to have the correct length always call eina_tmpstr_add_length with length == strlen(str).
Parameters:
[in]strThe input string that is copied into the temp string
[in]lengthThe maximum length and the allocated length of the temp string
Returns:
A pointer to the tmp string that is a standard C string
See also:
eina_tmpstr_del()
eina_tmpstr_add()
void eina_tmpstr_del ( Eina_Tmpstr tmpstr)

Deletes the temporary string if it is one, or ignores it if it is not.

This deletes the given temporary string tmpstr if it is a valid temporary string, otherwise it ignores it and does nothing, so this can be used safely with non-temporary strings.

Since (EFL) :
1.8.0
Since :
2.3.1
Parameters:
[in]tmpstrA C string pointer, but if it is a tmp string it is freed
See also:
eina_tmpstr_add()
size_t eina_tmpstr_strlen ( Eina_Tmpstr tmpstr)

Returns the length of a temporary string including the '\0'.

Since (EFL) :
1.8.0
Since :
2.3.1
Parameters:
[in]tmpstrA C string pointer, but if it is a tmp string it returns the length faster
Returns:
The length of the string including the '\0'