From: Pierre Habouzit Date: Thu, 30 Nov 2006 08:03:39 +0000 (+0100) Subject: some simplifications. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=c76ab67f3430e67b14b381bc1e3a23a14a4053b8;p=apps%2Fmadmutt.git some simplifications. Signed-off-by: Pierre Habouzit --- diff --git a/lib-lib/str.h b/lib-lib/str.h index a5791c3..25abac8 100644 --- a/lib-lib/str.h +++ b/lib-lib/str.h @@ -128,6 +128,14 @@ static inline char *m_strreplace(char **p, const char *s) { return (*p = m_strdup(s)); } +static inline ssize_t m_strputc(char *dst, ssize_t n, int c) { + if (n > 1) { + dst[0] = c; + dst[1] = '\0'; + } + return 1; +} + ssize_t m_strcpy(char *dst, ssize_t n, const char *src); ssize_t m_strncpy(char *dst, ssize_t n, const char *src, ssize_t l); diff --git a/lib-mime/rfc822address.c b/lib-mime/rfc822address.c index 36485d3..a6a06c4 100644 --- a/lib-mime/rfc822address.c +++ b/lib-mime/rfc822address.c @@ -410,14 +410,14 @@ ssize_t rfc822_write_address_single(char *buf, ssize_t buflen, } if (addr->personal) { - pos += m_strcpy(buf + pos, buflen - pos, ">"); + pos += m_strputc(buf + pos, buflen - pos, '>'); } if (addr->group) { - pos += m_strcpy(buf + pos, buflen - pos, ":"); + pos += m_strputc(buf + pos, buflen - pos, ':'); } } else { - pos += m_strcpy(buf + pos, buflen - pos, ";"); + pos += m_strputc(buf + pos, buflen - pos, ';'); } return pos; diff --git a/pattern.c b/pattern.c index ea72544..594beda 100644 --- a/pattern.c +++ b/pattern.c @@ -631,20 +631,16 @@ static const struct pattern_flags *lookup_tag (char tag) return NULL; } -static /* const */ char *find_matching_paren ( /* const */ char *s) +static const char *find_matching_paren (const char *s) { - int level = 1; - - for (; *s; s++) { - if (*s == '(') - level++; - else if (*s == ')') { - level--; - if (!level) - break; + int level = 1; + + for (; *s; s++) { + level += (*s == '(') - (*s == ')'); + if (!level) + break; } - } - return s; + return s; } pattern_t *mutt_pattern_comp(const char *s, int flags, BUFFER *err)