Simplify w32cygwinx.c and pacify GCC (Bug#32189)
* src/w32cygwinx.c (format_string): New function. (Fw32_battery_status): Use it.
This commit is contained in:
parent
249606fb53
commit
144bcc0132
1 changed files with 16 additions and 21 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue