add utils::strdup() convenience function
This commit is contained in:
@ -546,6 +546,18 @@ int utils::expand_args(const char *file, int line, int narg, char **arg,
|
||||
return newarg;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Make copy of string in new storage. Works like the (non-portable)
|
||||
C-style strdup() but also accepts a C++ string as argument.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
char *utils::strdup(const std::string &text)
|
||||
{
|
||||
char *tmp = new char[text.size()+1];
|
||||
strcpy(tmp,text.c_str());
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return string without leading or trailing whitespace
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user