diff options
Diffstat (limited to 'portable/snprintf.c')
-rw-r--r-- | portable/snprintf.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/portable/snprintf.c b/portable/snprintf.c index a42ef3b..a22e4e4 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -25,6 +25,28 @@ # define vsnprintf test_vsnprintf #endif +/* + * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 + * could you use the __format__ form of the attributes, which is what we use + * (to avoid confusion with other macros). + */ +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(spec) /* empty */ +# endif +#endif + +/* + * Older Clang doesn't support __attribute__((fallthrough)) properly and + * complains about the empty statement that it is decorating. Suppress that + * warning. Also suppress warnings about unknown attributes to handle older + * Clang versions. + */ +#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) +# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wmissing-declarations" +#endif + /* Specific to rra-c-util, but only when debugging is enabled. */ #ifdef DEBUG_SNPRINTF # include <util/messages.h> @@ -64,7 +86,7 @@ * probably requires libm on most operating systems. Don't yet * support the exponent (e,E) and sigfig (g,G). Also, fmtint() * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code + * which showed it, so that's been fixed. Also, formatted the code * to mutt conventions, and removed dead code left over from the * original. Also, there is now a builtin-test, just compile with: * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm @@ -366,7 +388,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'X': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'x': flags |= DP_F_UNSIGNED; if (cflags == DP_C_SHORT) @@ -388,7 +411,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'E': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); @@ -398,7 +422,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'G': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'g': flags |= DP_F_FP_G; if (cflags == DP_C_LDOUBLE) @@ -714,7 +739,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (intpart != 0) { /* For each digit of INTPART, print one less fractional digit. */ - LLONG temp = intpart; + LLONG temp; for (temp = intpart; temp != 0; temp /= 10) --max; if (max < 0) |