aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2023-12-30 23:22:59 +0100
committerEgor Tensin <egor@tensin.name>2023-12-30 23:22:59 +0100
commit3d878bfc3ed733ca3b29ecc2ff50a96dfb47ca06 (patch)
tree4a4e02df0539c62c6758d2d4802433aab03abe69 /src
parenttest/py/ -> test/src/ (diff)
downloadcimple-3d878bfc3ed733ca3b29ecc2ff50a96dfb47ca06.tar.gz
cimple-3d878bfc3ed733ca3b29ecc2ff50a96dfb47ca06.zip
string: stpecpy -> string_append
Diffstat (limited to '')
-rw-r--r--src/event_loop.c4
-rw-r--r--src/string.c6
-rw-r--r--src/string.h16
3 files changed, 19 insertions, 7 deletions
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 <stdlib.h>
#include <string.h>
-/* 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);