emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 144bcc0: Simplify w32cygwinx.c and pacify GCC (Bug#


From: Paul Eggert
Subject: [Emacs-diffs] master 144bcc0: Simplify w32cygwinx.c and pacify GCC (Bug#32189)
Date: Fri, 20 Jul 2018 10:30:20 -0400 (EDT)

branch: master
commit 144bcc0132e61cc932348312720d592764022844
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Simplify w32cygwinx.c and pacify GCC (Bug#32189)
    
    * src/w32cygwinx.c (format_string): New function.
    (Fw32_battery_status): Use it.
---
 src/w32cygwinx.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c
index 8d3ae16..5d48c3a 100644
--- a/src/w32cygwinx.c
+++ b/src/w32cygwinx.c
@@ -24,6 +24,16 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "w32common.h"
 
+static Lisp_Object ATTRIBUTE_FORMAT_PRINTF (1, 2)
+format_string (char const *format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  Lisp_Object str = vformat_string (format, args);
+  va_end (args);
+  return str;
+}
+
 DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0,
        doc: /* Get power status information from Windows system.
 
@@ -92,32 +102,17 @@ The following %-sequences are provided:
       if (system_status.BatteryLifePercent > 100)
        load_percentage = build_string ("N/A");
       else
-       {
-         char buffer[16];
-         snprintf (buffer, 16, "%d", system_status.BatteryLifePercent);
-         load_percentage = build_string (buffer);
-       }
+       load_percentage = format_string ("%d", 
system_status.BatteryLifePercent);
 
       if (seconds_left < 0)
        seconds = minutes = hours = remain = build_string ("N/A");
       else
        {
-         long m;
-         double h;
-         char buffer[16];
-         snprintf (buffer, 16, "%ld", seconds_left);
-         seconds = build_string (buffer);
-
-         m = seconds_left / 60;
-         snprintf (buffer, 16, "%ld", m);
-         minutes = build_string (buffer);
-
-         h = seconds_left / 3600.0;
-         snprintf (buffer, 16, "%3.1f", h);
-         hours = build_string (buffer);
-
-         snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60);
-         remain = build_string (buffer);
+         long m = seconds_left / 60;
+         seconds = format_string ("%ld", seconds_left);
+         minutes = format_string ("%ld", m);
+         hours = format_string ("%3.1f", seconds_left / 3600.0);
+         remain = format_string ("%ld:%02ld", m / 60, m % 60);
        }
 
       status = listn (CONSTYPE_HEAP, 8,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]