add utils::strdup() convenience function

This commit is contained in:
Axel Kohlmeyer
2021-02-04 15:35:43 -05:00
parent f5bf10e00f
commit 0f07215a2b
4 changed files with 41 additions and 0 deletions

View File

@ -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
------------------------------------------------------------------------- */