*
* \param s The string to be duplicated.
*
- * A wrapper for strdup(3). It calls \p exit(EXIT_FAILURE) on errors, i.e.
- * there is no need to check the return value in the caller.
+ * A strdup(3)-like function which aborts if insufficient memory was available
+ * to allocate the duplicated string, absolving the caller from the
+ * responsibility to check for failure.
*
- * \return A pointer to the duplicated string. If \a s was the \p NULL pointer,
- * an pointer to an empty string is returned.
+ * \return A pointer to the duplicated string. Unlike strdup(3), the caller may
+ * pass NULL, in which case the function returns a pointer to an empty string.
+ * Regardless of whether or not NULL was passed, the returned string is
+ * allocated on the heap and has to be freed by the caller.
*
- * \sa strdup(3)
+ * \sa strdup(3).
*/
__must_check __malloc char *para_strdup(const char *s)
{
- char *ret;
+ char *dupped_string = strdup(s? s: "");
- if ((ret = strdup(s? s: "")))
- return ret;
- PARA_EMERG_LOG("strdup failed, aborting\n");
- exit(EXIT_FAILURE);
+ assert(dupped_string);
+ return dupped_string;
}
/**