This file had been imported from musl as part of the commit 79d5ad7d6f7bbcc20edf2ce2bbf3cc08f04b08dd. It looks like it got slightly modified to possibly silence the compiler (see the diff below).
``` diff musl/src/locale/strfmon.c libc/locale/strfmon.c 12c12 < int fill, nogrp, negpar, nosym, left, intl; --- > int left; 25,28d24 < fill = ' '; < nogrp = 0; < negpar = 0; < nosym = 0; 33d28 < fill = *++fmt; 36d30 < nogrp = 1; 39d32 < negpar = 1; 43d35 < nosym = 1; 61,62d52 < intl = *fmt++ == 'i'; < ``` More specifically if one looks at the musl code, the variables fill, nogrp, negpar, nosym and intl are set but never referenced/used. As a matter of fact dropping the statements 'fill = *++fmt;' and 'intl = *fmt++ == 'i';' affects fmt variable and possibly has a bug. TODO: Add a test. Signed-off-by: Waldemar Kozaczuk <[email protected]> --- Makefile | 2 +- libc/locale/strfmon.c | 91 ------------------------------------------- 2 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 libc/locale/strfmon.c diff --git a/Makefile b/Makefile index 0abbd196..168a6bdd 100644 --- a/Makefile +++ b/Makefile @@ -1046,7 +1046,7 @@ musl += locale/strcasecmp_l.o libc += locale/strcoll.o libc += locale/strcoll_l.o musl += locale/strerror_l.o -libc += locale/strfmon.o +musl += locale/strfmon.o libc += locale/strftime_l.o musl += locale/strncasecmp_l.o libc += locale/strtod_l.o diff --git a/libc/locale/strfmon.c b/libc/locale/strfmon.c deleted file mode 100644 index 14623fa7..00000000 --- a/libc/locale/strfmon.c +++ /dev/null @@ -1,91 +0,0 @@ -#include <stdio.h> -#include <ctype.h> -#include <stdarg.h> -#include <monetary.h> -#include <errno.h> -#include <stdarg.h> - -static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_list ap) -{ - size_t l; - double x; - int left; - int lp, rp, w, fw; - char *s0=s; - for (; n && *fmt; ) { - if (*fmt != '%') { - literal: - *s++ = *fmt++; - n--; - continue; - } - fmt++; - if (*fmt == '%') goto literal; - - left = 0; - for (; ; fmt++) { - switch (*fmt) { - case '=': - continue; - case '^': - continue; - case '(': - case '+': - continue; - case '!': - continue; - case '-': - left = 1; - continue; - } - break; - } - - for (fw=0; isdigit(*fmt); fmt++) - fw = 10*fw + (*fmt-'0'); - lp = 0; - rp = 2; - if (*fmt=='#') for (lp=0, fmt++; isdigit(*fmt); fmt++) - lp = 10*lp + (*fmt-'0'); - if (*fmt=='.') for (rp=0, fmt++; isdigit(*fmt); fmt++) - rp = 10*rp + (*fmt-'0'); - - w = lp + 1 + rp; - if (!left && fw>w) w = fw; - - x = va_arg(ap, double); - l = snprintf(s, n, "%*.*f", w, rp, x); - if (l >= n) { - errno = E2BIG; - return -1; - } - s += l; - n -= l; - } - return s-s0; -} - -ssize_t strfmon_l(char *restrict s, size_t n, locale_t loc, const char *restrict fmt, ...) -{ - va_list ap; - ssize_t ret; - - va_start(ap, fmt); - ret = vstrfmon_l(s, n, loc, fmt, ap); - va_end(ap); - - return ret; -} - - -ssize_t strfmon(char *restrict s, size_t n, const char *restrict fmt, ...) -{ - va_list ap; - ssize_t ret; - - va_start(ap, fmt); - ret = vstrfmon_l(s, n, 0, fmt, ap); - va_end(ap); - - return ret; -} -- 2.26.2 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20200815042719.51117-8-jwkozaczuk%40gmail.com.
