summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-snprintf.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2007-01-24 00:07:29 +1100
committerDarren Tucker <dtucker@zip.com.au>2007-01-24 00:07:29 +1100
commit07877ca68066593473fbe29dd309dcdc61b6d629 (patch)
treec56aa3788d8aa6592c21173a93ff52c55966820a /openbsd-compat/bsd-snprintf.c
parent9f7410528945a433f9f640c67677916623f3d7cf (diff)
- (dtucker) [openbsd-compat/bsd-snprintf.c] Static declarations for public
library interfaces aren't very helpful. Fix up the DOPR_OUTCH macro so it works properly and modify its callers so that they don't pre or post decrement arguments that are conditionally evaluated. While there, put SNPRINTF_CONST back as it prevents build failures in some configurations. ok djm@ (for most of it)
Diffstat (limited to 'openbsd-compat/bsd-snprintf.c')
-rw-r--r--openbsd-compat/bsd-snprintf.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c
index cefb1d1ad..41d2be238 100644
--- a/openbsd-compat/bsd-snprintf.c
+++ b/openbsd-compat/bsd-snprintf.c
@@ -168,12 +168,13 @@
168 168
169#define DOPR_OUTCH(buf, pos, buflen, thechar) \ 169#define DOPR_OUTCH(buf, pos, buflen, thechar) \
170 do { \ 170 do { \
171 if (++pos >= INT_MAX) { \ 171 if (pos + 1 >= INT_MAX) { \
172 errno = ERANGE; \ 172 errno = ERANGE; \
173 return -1; \ 173 return -1; \
174 } \
174 if (pos < buflen) \ 175 if (pos < buflen) \
175 buf[pos] = thechar; \ 176 buf[pos] = thechar; \
176 } \ 177 (pos)++; \
177 } while (0) 178 } while (0)
178 179
179static int dopr(char *buffer, size_t maxlen, const char *format, 180static int dopr(char *buffer, size_t maxlen, const char *format,
@@ -494,7 +495,8 @@ fmtstr(char *buffer, size_t *currlen, size_t maxlen,
494 ++cnt; 495 ++cnt;
495 } 496 }
496 while (*value && (cnt < max)) { 497 while (*value && (cnt < max)) {
497 DOPR_OUTCH(buffer, *currlen, maxlen, *value++); 498 DOPR_OUTCH(buffer, *currlen, maxlen, *value);
499 *value++;
498 ++cnt; 500 ++cnt;
499 } 501 }
500 while ((padlen < 0) && (cnt < max)) { 502 while ((padlen < 0) && (cnt < max)) {
@@ -582,8 +584,10 @@ fmtint(char *buffer, size_t *currlen, size_t maxlen,
582 } 584 }
583 585
584 /* Digits */ 586 /* Digits */
585 while (place > 0) 587 while (place > 0) {
586 DOPR_OUTCH(buffer, *currlen, maxlen, convert[--place]); 588 --place;
589 DOPR_OUTCH(buffer, *currlen, maxlen, convert[place]);
590 }
587 591
588 /* Left Justified spaces */ 592 /* Left Justified spaces */
589 while (spadlen < 0) { 593 while (spadlen < 0) {
@@ -788,8 +792,10 @@ fmtfp (char *buffer, size_t *currlen, size_t maxlen,
788 if (signvalue) 792 if (signvalue)
789 DOPR_OUTCH(buffer, *currlen, maxlen, signvalue); 793 DOPR_OUTCH(buffer, *currlen, maxlen, signvalue);
790 794
791 while (iplace > 0) 795 while (iplace > 0) {
792 DOPR_OUTCH(buffer, *currlen, maxlen, iconvert[--iplace]); 796 --iplace;
797 DOPR_OUTCH(buffer, *currlen, maxlen, iconvert[iplace]);
798 }
793 799
794#ifdef DEBUG_SNPRINTF 800#ifdef DEBUG_SNPRINTF
795 printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); 801 printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
@@ -807,9 +813,10 @@ fmtfp (char *buffer, size_t *currlen, size_t maxlen,
807 --zpadlen; 813 --zpadlen;
808 } 814 }
809 815
810 while (fplace > 0) 816 while (fplace > 0) {
811 DOPR_OUTCH(buffer, *currlen, maxlen, 817 --fplace;
812 fconvert[--fplace]); 818 DOPR_OUTCH(buffer, *currlen, maxlen, fconvert[fplace]);
819 }
813 } 820 }
814 821
815 while (padlen < 0) { 822 while (padlen < 0) {
@@ -821,7 +828,7 @@ fmtfp (char *buffer, size_t *currlen, size_t maxlen,
821#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */ 828#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
822 829
823#if !defined(HAVE_VSNPRINTF) 830#if !defined(HAVE_VSNPRINTF)
824static int 831int
825vsnprintf (char *str, size_t count, const char *fmt, va_list args) 832vsnprintf (char *str, size_t count, const char *fmt, va_list args)
826{ 833{
827 return dopr(str, count, fmt, args); 834 return dopr(str, count, fmt, args);
@@ -829,8 +836,8 @@ vsnprintf (char *str, size_t count, const char *fmt, va_list args)
829#endif 836#endif
830 837
831#if !defined(HAVE_SNPRINTF) 838#if !defined(HAVE_SNPRINTF)
832static int 839int
833snprintf(char *str, size_t count, const char *fmt, ...) 840snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...)
834{ 841{
835 size_t ret; 842 size_t ret;
836 va_list ap; 843 va_list ap;