Tizen Native API

Functions

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

Typedefs

typedef const char Eina_Tmpstr

Typedef Documentation

Interchangeable with "const char *" but still a good visual hint for the purpose. This indicates 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)

Add a new temporary string based on the input string.

Since :
2.3
Parameters:
[in]strThis is the input stringthat is copied into the temp string.
Returns:
A pointer to the tmp string that is a standard C string.
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 longer 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 be cleaned up automatically by the caller.
If str is NULL, or no memory space exists to store the tmpstr, then NULL will be returned, otherwise a valid string pointer will be 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 youa re done with the string yo should delete it with 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");
See also:
eina_tmpstr_del()
eina_tmpstr_add_length()
Since (EFL) :
1.8.0
Eina_Tmpstr* eina_tmpstr_add_length ( const char *  str,
size_t  length 
)

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

Since :
2.3
Parameters:
[in]strThis is the input string that is copied into the temp string.
[in]lengthThis is the maximum length and the allocated length of the temp string.
Returns:
A pointer to the tmp string that is a standard C string.
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 longer 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 be cleaned up automatically by the caller.
If str is NULL, or no memory space exists to store the tmpstr, then NULL will be returned, otherwise a valid string pointer will be 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 yo should delete it with eina_tmpstr_del().
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).
See also:
eina_tmpstr_del()
eina_tmpstr_add()
Since (EFL) :
1.8.0
void eina_tmpstr_del ( Eina_Tmpstr tmpstr)

Delete the temporary string if it is one, or ignore it if it is not.

Since :
2.3
Parameters:
[in]tmpstrThis is any C string pointer, but if it is a tmp string it is freed.
Remarks:
This will delete the given temporary string tmpstr if it is a valid temporary string, or otherwise it will ignore it and do nothing so this can be used safely with non-temporary strings.
See also:
eina_tmpstr_add()
Since (EFL) :
1.8.0
size_t eina_tmpstr_strlen ( Eina_Tmpstr tmpstr)

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

Since :
2.3
Parameters:
[in]tmpstrThis is any C string pointer, but if it is a tmp string it will return the length faster.
Returns:
The length of the string including the '\0';
Since (EFL) :
1.8.0