From: Darshit Shah Date: Fri, 14 Oct 2016 22:59:42 +0000 (+0100) Subject: replace the ugly strfcpy() macro with a function X-Git-Tag: neomutt-20161028~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1613a0c9e874ba92c83f1b757f1134a3318cb23;p=neomutt replace the ugly strfcpy() macro with a function --- diff --git a/lib.c b/lib.c index 28c2937cf..ad0dfbace 100644 --- a/lib.c +++ b/lib.c @@ -1112,3 +1112,13 @@ int mutt_same_path (const char *a, const char *b) return ((a_len == (b_end - b)) && (mutt_strncasecmp (a, b, a_len) == 0)); } +char * strfcpy (char *dest, const char *src, size_t dlen) +{ + char *dest0 = dest; + while ((--dlen > 0) && (*src != '\0')) + *dest++ = *src++; + + *dest = '\0'; + return dest0; +} + diff --git a/lib.h b/lib.h index 120a0f0b3..2bae30e21 100644 --- a/lib.h +++ b/lib.h @@ -77,7 +77,6 @@ # define FREE(x) safe_free(x) # define NONULL(x) x?x:"" # define ISSPACE(c) isspace((unsigned char)c) -# define strfcpy(DST,SRC,LEN) do { if ((LEN) > 0) { *(DST+(LEN)-1)=0; strncpy(DST,SRC,(LEN)-1); } } while (0) # undef MAX # undef MIN @@ -177,6 +176,7 @@ char *mutt_substrdup (const char *, const char *); char *safe_strcat (char *, size_t, const char *); char *safe_strncat (char *, size_t, const char *, size_t); char *safe_strdup (const char *); +char *strfcpy (char *dest, const char *src, size_t dlen); /* strtol() wrappers with range checking; they return * 0 success