Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
battery: Remove unnecessary defines for paths
[slstatus.git]
/
util.c
diff --git
a/util.c
b/util.c
index
b412211
..
4c37ab0
100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-1,6
+1,7
@@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdarg.h>
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdarg.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-48,27
+49,37
@@
die(const char *fmt, ...)
exit(1);
}
exit(1);
}
-int
-e
snprintf(char *str, size_t size, const char *fmt, ...
)
+
static
int
+e
vsnprintf(char *str, size_t size, const char *fmt, va_list ap
)
{
{
- va_list ap;
int ret;
int ret;
- va_start(ap, fmt);
ret = vsnprintf(str, size, fmt, ap);
ret = vsnprintf(str, size, fmt, ap);
- va_end(ap);
if (ret < 0) {
if (ret < 0) {
- warn("snprintf:");
+ warn("
v
snprintf:");
return -1;
} else if ((size_t)ret >= size) {
return -1;
} else if ((size_t)ret >= size) {
- warn("snprintf: Output truncated");
+ warn("
v
snprintf: Output truncated");
return -1;
}
return ret;
}
return -1;
}
return ret;
}
+int
+esnprintf(char *str, size_t size, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = evsnprintf(str, size, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
const char *
bprintf(const char *fmt, ...)
{
const char *
bprintf(const char *fmt, ...)
{
@@
-76,18
+87,14
@@
bprintf(const char *fmt, ...)
int ret;
va_start(ap, fmt);
int ret;
va_start(ap, fmt);
- if ((ret = vsnprintf(buf, sizeof(buf), fmt, ap)) < 0) {
- warn("vsnprintf:");
- } else if ((size_t)ret >= sizeof(buf)) {
- warn("vsnprintf: Output truncated");
- }
+ ret = evsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
va_end(ap);
- return buf;
+ return
(ret < 0) ? NULL :
buf;
}
const char *
}
const char *
-fmt_human(
size
_t num, int base)
+fmt_human(
uint64
_t num, int base)
{
double scaled;
size_t i, prefixlen;
{
double scaled;
size_t i, prefixlen;