From 3d878bfc3ed733ca3b29ecc2ff50a96dfb47ca06 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 30 Dec 2023 23:22:59 +0100 Subject: string: stpecpy -> string_append --- src/event_loop.c | 4 ++-- src/string.c | 6 +++--- src/string.h | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/event_loop.c b/src/event_loop.c index e463aca..736a553 100644 --- a/src/event_loop.c +++ b/src/event_loop.c @@ -132,8 +132,8 @@ static void event_loop_remove(struct event_loop *loop, struct event_fd *entry) static char *append_event(char *buf, size_t sz, char *ptr, const char *event) { if (ptr > buf) - ptr = stpecpy(ptr, buf + sz, ","); - return stpecpy(ptr, buf + sz, event); + ptr = string_append(ptr, buf + sz, ","); + return string_append(ptr, buf + sz, event); } static char *events_to_string(short events) diff --git a/src/string.c b/src/string.c index f2010c6..b610e2f 100644 --- a/src/string.c +++ b/src/string.c @@ -12,9 +12,9 @@ #include #include -/* This is not provided by glibc; however, it does provide a possible - * implementation in string_copying(7), which I copied from. */ -char *stpecpy(char *dst, char *end, const char *src) +/* glibc calls this stpecpy; it's not provided by glibc; however, it does + * provide a possible implementation in string_copying(7), which I copied from. */ +char *string_append(char *dst, char *end, const char *src) { if (!dst) return NULL; diff --git a/src/string.h b/src/string.h index 7c16318..e9f2b89 100644 --- a/src/string.h +++ b/src/string.h @@ -8,8 +8,20 @@ #ifndef __STRING_H__ #define __STRING_H__ -/* For details, see string_copying(7). */ -char *stpecpy(char *dst, char *end, const char *src); +/* + * This is an implementation for stpecpy. + * For details, see string_copying(7). + * + * You can safely do something like this: + * + * char buf[128]; + * char *ptr = buf; + * + * ptr = string_append(ptr, buf + 128, "random"); + * ptr = string_append(ptr, buf + 128, "strings"); + * ptr = string_append(ptr, buf + 128, "can be appended safely"); + */ +char *string_append(char *dst, char *end, const char *src); int string_to_int(const char *src, int *result); -- cgit v1.2.3