jcs
/wikipedia
/amendments
/28
util: Add strsep from OpenBSD
jcs made amendment 28 over 2 years ago
--- util.c Mon Sep 5 23:44:26 2022
+++ util.c Tue Sep 6 12:34:51 2022
@@ -1,7 +1,9 @@
/*
* Copyright (c) 2020-2022 joshua stein <jcs@jcs.org>
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
@@ -1624,6 +1626,44 @@ strndup(const char *str, size_t maxlen)
}
return copy;
+}
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(char **stringp, const char *delim)
+{
+ char *s;
+ const char *spanp;
+ int c, sc;
+ char *tok;
+
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+ return (NULL);
}
static struct format {
--- util.h Mon Sep 5 23:44:40 2022
+++ util.h Tue Sep 6 12:34:32 2022
@@ -157,6 +157,7 @@ void RestoreHiddenMenuBar(void);
size_t strlcat(char *dst, const char *src, size_t dsize);
size_t strlcpy(char *dst, const char *src, size_t dsize);
char * strndup(const char *str, size_t maxlen);
+char * strsep(char **stringp, const char *delim);
int snprintf(char *s, size_t size, const char *fmt, ...);
int vsnprintf(char *s, size_t size, const char *fmt, void *p);