aboutsummaryrefslogtreecommitdiffstats
path: root/src/string/new.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-11-18 18:54:44 +0100
committerMattias Andrée <maandree@operamail.com>2015-11-18 18:54:44 +0100
commit6585ae2b6dc3e5da4e73c7f00fb5e4dead0b3836 (patch)
treeaa08a9bd370e1d853c6b5647f1f54fea079314ed /src/string/new.c
parentadd more string.h and wchar.h functions (diff)
downloadslibc-6585ae2b6dc3e5da4e73c7f00fb5e4dead0b3836.tar.gz
slibc-6585ae2b6dc3e5da4e73c7f00fb5e4dead0b3836.tar.bz2
slibc-6585ae2b6dc3e5da4e73c7f00fb5e4dead0b3836.tar.xz
doc some new functions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/string/new.c')
-rw-r--r--src/string/new.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/string/new.c b/src/string/new.c
index 7854e1b..f407cb3 100644
--- a/src/string/new.c
+++ b/src/string/new.c
@@ -19,24 +19,68 @@
-size_t strclen(const char* string, int stop) /* slibc: completeness */
+/**
+ * Variant of `strlen` that treats both NUL and a
+ * selected byte as the termination-byte.
+ *
+ * This is a slibc extension added for completeness.
+ *
+ * @param str The string.
+ * @param stop The additional termination-byte.
+ * @return The number of bytes before, the first termination-byte.
+ */
+size_t strclen(const char* string, int stop)
{
return (size_t)(strchrnul(string, stop) - string);
}
-size_t strcnlen(const char* string, int stop, size_t maxlen) /* slibc: completeness */
+/**
+ * Variant of `strclen` that only inspects the
+ * beginning of a string.
+ *
+ * This is a slibc extension added for completeness.
+ *
+ * @param str The string.
+ * @param stop The additional termination-byte.
+ * @param maxlen The number of bytes to inspect, at most.
+ * @return The number of bytes before, the first termination-byte.
+ * `maxlen` if no termination-byte was found.
+ */
+size_t strcnlen(const char* string, int stop, size_t maxlen)
{
const char* end = strnchr(string, stop, maxlen);
return end ? (size_t)(end - string) : maxlen;
}
-size_t strstrlen(const char* string, const char* stop) /* slibc: completeness */
+/**
+ * Variant of `strlen` that treats both NUL and a
+ * selected string as the termination-mark.
+ *
+ * This is a slibc extension added for completeness.
+ *
+ * @param str The string.
+ * @param stop The additional termination-mark.
+ * @return The number of bytes before, the first termination-mark.
+ */
+size_t strstrlen(const char* string, const char* stop)
{
const char* end = strstr(string, stop);
return end ? (size_t)(end - string) : strlen(string);
}
-size_t strstrnlen(const char* string, const char* stop, size_t maxlen) /* slibc: completeness */
+/**
+ * Variant of `strstrlen` that only inspects the
+ * beginning of a string.
+ *
+ * This is a slibc extension added for completeness.
+ *
+ * @param str The string.
+ * @param stop The additional termination-mark.
+ * @param maxlen The number of bytes to inspect, at most.
+ * @return The number of bytes before, the first termination-mark.
+ * `maxlen` if no termination-byte was found.
+ */
+size_t strstrnlen(const char* string, const char* stop, size_t maxlen)
{
const char* end = strnstr(string, stop, maxlen);
return end ? (size_t)(end - string) : maxlen;