-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);
+/** \brief Puts a char in a string buffer.
+ *
+ * Puts a char at position 0 of a string buffer of size \c n.
+ * Then \c \\0 terminate the buffer.
+ *
+ * \param[in] dst pointer to the buffer.
+ * \param[in] n size of that buffer (negative values allowed).
+ * \param[in] c the character to append.
+ * \return always return 1.
+ */
+__attribute__((nonnull(1)))
+static inline ssize_t m_strputc(char *dst, ssize_t n, int c) {
+ if (n > 1) {
+ dst[0] = c;
+ dst[1] = '\0';
+ }
+ 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)));
+
+ssize_t m_strncpy(char *dst, ssize_t n, const char *src, ssize_t l)
+ __attribute__((nonnull(1)));