tutil.[ch]: add strlcpy for platforms that do not have it - vote - simple cgi voting system for web and gopher
(HTM) git clone git://src.adamsgaard.dk/vote
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 5190a3453c2755d07cb5e6afeb9689d27275d4da
(DIR) parent a6ae3f0db3f76e55a4ecc84bf09ee62e629881e3
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sun, 27 Sep 2020 08:59:58 +0200
util.[ch]: add strlcpy for platforms that do not have it
Diffstat:
M util.c | 24 ++++++++++++++++++++++++
M util.h | 1 +
2 files changed, 25 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/util.c b/util.c
t@@ -228,3 +228,27 @@ escapechars(char *s)
}
}
}
+
+#ifdef NEED_STRLCPY /* OpenBSD implementation */
+size_t
+strlcpy(char *dst, const char *src, size_t dsize) {
+ const char *osrc = src;
+ size_t nleft = dsize;
+
+ if (nleft != 0) {
+ while (--nleft != 0) {
+ if ((*dst++= *src++) == '\0')
+ break;
+ }
+ }
+
+ if (nleft == 0) {
+ if (dsize != 0)
+ *dst = '\0';
+ while (*src++)
+ ;
+ }
+
+ return(src - osrc - 1);
+}
+#endif /* NEED_STRLCPY */
(DIR) diff --git a/util.h b/util.h
t@@ -17,3 +17,4 @@ int uriencode(const char *s, char *buf, size_t bufsiz);
int utf8pad(char *buf, size_t bufsiz, const char *s, size_t len, int pad);
void xmlencode(const char *s);
void escapechars(char *s);
+size_t strlcpy(char *dst, const char *src, size_t dsize);