sd-event: replace snprintf() with strpcpyf()
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "signal-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "time-util.h"
|
||||
|
||||
#define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC)
|
||||
@@ -3248,15 +3249,16 @@ _public_ int sd_event_dispatch(sd_event *e) {
|
||||
}
|
||||
|
||||
static void event_log_delays(sd_event *e) {
|
||||
char b[ELEMENTSOF(e->delays) * DECIMAL_STR_MAX(unsigned) + 1];
|
||||
unsigned i;
|
||||
int o;
|
||||
char b[ELEMENTSOF(e->delays) * DECIMAL_STR_MAX(unsigned) + 1], *p;
|
||||
size_t l, i;
|
||||
|
||||
for (i = o = 0; i < ELEMENTSOF(e->delays); i++) {
|
||||
o += snprintf(&b[o], sizeof(b) - o, "%u ", e->delays[i]);
|
||||
p = b;
|
||||
l = sizeof(b);
|
||||
for (i = 0; i < ELEMENTSOF(e->delays); i++) {
|
||||
l = strpcpyf(&p, l, "%u ", e->delays[i]);
|
||||
e->delays[i] = 0;
|
||||
}
|
||||
log_debug("Event loop iterations: %.*s", o, b);
|
||||
log_debug("Event loop iterations: %s", b);
|
||||
}
|
||||
|
||||
_public_ int sd_event_run(sd_event *e, uint64_t timeout) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "string-util.h"
|
||||
@@ -78,6 +79,24 @@ static void test_strscpyl(void) {
|
||||
assert_se(space_left == 10);
|
||||
}
|
||||
|
||||
static void test_sd_event_code_migration(void) {
|
||||
char b[100 * DECIMAL_STR_MAX(unsigned) + 1];
|
||||
char c[100 * DECIMAL_STR_MAX(unsigned) + 1], *p;
|
||||
unsigned i;
|
||||
size_t l;
|
||||
int o;
|
||||
|
||||
for (i = o = 0; i < 100; i++)
|
||||
o += snprintf(&b[o], sizeof(b) - o, "%u ", i);
|
||||
|
||||
p = c;
|
||||
l = sizeof(c);
|
||||
for (i = 0; i < 100; i++)
|
||||
l = strpcpyf(&p, l, "%u ", i);
|
||||
|
||||
assert_se(streq(b, c));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_strpcpy();
|
||||
test_strpcpyf();
|
||||
@@ -85,5 +104,7 @@ int main(int argc, char *argv[]) {
|
||||
test_strscpy();
|
||||
test_strscpyl();
|
||||
|
||||
test_sd_event_code_migration();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user