summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/strchrnul.c
diff options
context:
space:
mode:
authorzeising <zeising@FreeBSD.org>2013-02-13 15:46:33 +0000
committerzeising <zeising@FreeBSD.org>2013-02-13 15:46:33 +0000
commit742b0cd5e431c7658486d03808994218cb67ff73 (patch)
tree3a292c5a3296a11ce621635ac4655f56153629f7 /lib/libc/string/strchrnul.c
parent5f9d7af0e4c93982da4e8a81a5dc98d58db74544 (diff)
downloadFreeBSD-src-742b0cd5e431c7658486d03808994218cb67ff73.zip
FreeBSD-src-742b0cd5e431c7658486d03808994218cb67ff73.tar.gz
Add strchrnul(), a GNU function similar to strchr(), except that it returns
a pointer to the end of the string, rather than NULL, if the character was not found. Approved by: theraven
Diffstat (limited to 'lib/libc/string/strchrnul.c')
-rw-r--r--lib/libc/string/strchrnul.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/libc/string/strchrnul.c b/lib/libc/string/strchrnul.c
new file mode 100644
index 0000000..98e652d
--- /dev/null
+++ b/lib/libc/string/strchrnul.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Niclas Zeising
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stddef.h>
+#include <string.h>
+
+__weak_reference(__strchrnul, strchrnul);
+
+char *
+__strchrnul(const char *p, int ch)
+{
+ char c;
+
+ c = ch;
+ for (;; ++p) {
+ if (*p == c || *p == '\0')
+ return ((char *)p);
+ }
+ /* NOTREACHED */
+}
+
OpenPOWER on IntegriCloud