From: Pierre Habouzit Date: Sat, 2 Dec 2006 19:53:47 +0000 (+0100) Subject: add m_strpad to the string functions. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=2387528e4153c90f6e4b7e1bb7dba2fd09b1943c add m_strpad to the string functions. Signed-off-by: Pierre Habouzit --- diff --git a/lib-lib/str.h b/lib-lib/str.h index 882a103..fd80950 100644 --- a/lib-lib/str.h +++ b/lib-lib/str.h @@ -301,6 +301,25 @@ static inline ssize_t m_strputc(char *dst, ssize_t n, int c) { return 1; } +/** \brief Sets a portion of a string to a defined character, à la memset. + * + * \param[in] dst pointer to the buffer. + * \param[in] n size of that buffer, (negative values allowed). + * \param[in] c the char to use in the padding. + * \param[in] len length of the padding. + * \return MAX(0, len). + */ +__attribute__((nonnull(1))) +static inline ssize_t m_strpad(char *dst, ssize_t n, int c, ssize_t len) +{ + ssize_t dlen = MIN(n - 1, len); + if (dlen > 0) { + memset(dst, c, dlen); + dst[dlen] = '\0'; + } + return MAX(0, len); +} + ssize_t m_strcpy(char *dst, ssize_t n, const char *src) __attribute__((nonnull(1)));