From 2387528e4153c90f6e4b7e1bb7dba2fd09b1943c Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 2 Dec 2006 20:53:47 +0100 Subject: [PATCH] add m_strpad to the string functions. Signed-off-by: Pierre Habouzit --- lib-lib/str.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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))); -- 2.20.1