X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;h=7123ba1ae5e00dfc13e1417bfbafd102c3946175;hp=a1f2a43c65756dc6ce066a5b6707c91b94f4c7d4;hb=e151dbb79eac16326585ec0a33cf48029f5f22f4;hpb=3e6bba778c867a8977704b5c15e52fa18fb0d900 diff --git a/string.c b/string.c index a1f2a43c..7123ba1a 100644 --- a/string.c +++ b/string.c @@ -128,7 +128,8 @@ __must_check __malloc char *para_strdup(const char *s) * function calls exit() if insufficient memory is available, while vasprintf() * returns -1 in this case. * - * \return Number of bytes written, not including the terminating '\0'. + * \return Number of bytes written, not including the terminating \p NULL + * character. * * \sa printf(3), vsnprintf(3), va_start(3), vasprintf(3), \ref xasprintf(). */ @@ -854,6 +855,27 @@ err: return ret; } +/** + * Find out if the given string is contained in the arg vector. + * + * \param arg The string to look for. + * \param argv The array to search. + * + * \return The first index whose value equals \a arg, or \p -E_ARG_NOT_FOUND if + * arg was not found in \a argv. + */ +int find_arg(const char *arg, char **argv) +{ + int i; + + if (!argv) + return -E_ARG_NOT_FOUND; + for (i = 0; argv[i]; i++) + if (strcmp(arg, argv[i]) == 0) + return i; + return -E_ARG_NOT_FOUND; +} + /** * Compile a regular expression. *