diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2017-04-08 13:39:44 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2017-04-10 10:59:54 +0100 |
commit | c84697c259d340ec2322efe79394d3c9e96cf006 (patch) | |
tree | 82497a1bc01c18f373ef5f05e542a0c00bccddfe /winsup/cygwin/fhandler_proc.cc | |
parent | c47c9bdc1b94b2ae9432f90b6b93fd99f7f9c209 (diff) | |
download | newlib-c84697c259d340ec2322efe79394d3c9e96cf006.zip newlib-c84697c259d340ec2322efe79394d3c9e96cf006.tar.gz newlib-c84697c259d340ec2322efe79394d3c9e96cf006.tar.bz2 |
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 <jon.turney@dronecode.org.uk>
Diffstat (limited to 'winsup/cygwin/fhandler_proc.cc')
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index a7e816f..ad367e4 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -30,6 +30,7 @@ details. */ #include <wctype.h> #include "cpuid.h" #include "mount.h" +#include <math.h> #define _COMPILING_NEWLIB #include <dirent.h> @@ -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 |