From a0707daa23f8706326aa837f969c20d3e4ee02aa Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 25 Aug 2022 16:33:29 +0200 Subject: [PATCH] Open-code find_arg(). There is only one caller in client_common.c, so open-code the logic there and get rid of the public function and the unused error code. --- client_common.c | 8 +++++++- error.h | 1 - string.c | 21 --------------------- string.h | 1 - 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/client_common.c b/client_common.c index f476a1c4..64f6c676 100644 --- a/client_common.c +++ b/client_common.c @@ -255,9 +255,15 @@ static int send_sb_command(struct client_task *ct) return send_sb(ct, 0, command, len, SBD_COMMAND, false); } +/* Find out if the given string is contained in the features vector. */ static bool has_feature(const char *feature, struct client_task *ct) { - return find_arg(feature, ct->features) >= 0? true : false; + if (!ct->features) + return false; + for (int i = 0; ct->features[i]; i++) + if (strcmp(feature, ct->features[i]) == 0) + return i; + return false; } /* diff --git a/error.h b/error.h index a644b967..82920ea8 100644 --- a/error.h +++ b/error.h @@ -29,7 +29,6 @@ PARA_ERROR(AO_OPEN_LIVE, "ao: could not open audio device"), \ PARA_ERROR(AO_PLAY, "ao_play() failed"), \ PARA_ERROR(AO_PTHREAD, "pthread error"), \ - PARA_ERROR(ARG_NOT_FOUND, "argument not found in arg vector"), \ PARA_ERROR(ASN1_PARSE, "could not parse ASN.1 key"), \ PARA_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \ PARA_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \ diff --git a/string.c b/string.c index 2c6d35d6..46b34623 100644 --- a/string.c +++ b/string.c @@ -806,27 +806,6 @@ int create_shifted_argv(const char *buf, const char *delim, char ***result) return create_argv_offset(1, buf, delim, result); } -/** - * 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. * diff --git a/string.h b/string.h index 060d6540..d773600f 100644 --- a/string.h +++ b/string.h @@ -88,7 +88,6 @@ int para_atoi32(const char *str, int32_t *value); int read_size_header(const char *buf); int create_argv(const char *buf, const char *delim, char ***result); int create_shifted_argv(const char *buf, const char *delim, char ***result); -int find_arg(const char *arg, char **argv); void free_argv(char **argv); int para_regcomp(regex_t *preg, const char *regex, int cflags); void freep(void *arg); -- 2.39.5