From: Jon Turney Date: Sat, 8 Apr 2017 12:39:44 +0000 (+0100) Subject: Avoid decimal point localization in /proc/loadavg X-Git-Tag: newlib-snapshot-20170421~9 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=c84697c259d340ec2322efe79394d3c9e96cf006;p=newlib-cygwin.git Avoid decimal point localization in /proc/loadavg Explicitly format the contents of /proc/loadavg to avoid the decimal point getting localized according to LC_NUMERIC. Using anything other than '.' is wrong and breaks top. Signed-off-by: Jon Turney --- diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index a7e816fe8..ad367e457 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -30,6 +30,7 @@ details. */ #include #include "cpuid.h" #include "mount.h" +#include #define _COMPILING_NEWLIB #include @@ -432,10 +433,14 @@ format_proc_loadavg (void *, char *&destbuf) double loadavg[3] = { 0.0, 0.0, 0.0 }; getloadavg (loadavg, 3); +#define HUNDRETHS(l) (int)((l - floor(l))*100) + destbuf = (char *) crealloc_abort (destbuf, 48); - return sprintf (destbuf, "%.2f %.2f %.2f %u/%u\n", - loadavg[0], loadavg[1], loadavg[2], running, - (unsigned int)pids.npids); + return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n", + (int)loadavg[0], HUNDRETHS(loadavg[0]), + (int)loadavg[1], HUNDRETHS(loadavg[1]), + (int)loadavg[2], HUNDRETHS(loadavg[2]), + running, (unsigned int)pids.npids); } static off_t