summaryrefslogtreecommitdiff
path: root/src/string/strncmp.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/string/strncmp.c
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
Diffstat (limited to 'src/string/strncmp.c')
-rw-r--r--src/string/strncmp.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/string/strncmp.c b/src/string/strncmp.c
new file mode 100644
index 00000000..23c8104e
--- /dev/null
+++ b/src/string/strncmp.c
@@ -0,0 +1,31 @@
+#include <string.h>
+#include "nonstd/assert.h"
+
+/** compare bound strings **/
+int strncmp(const char *s1, const char *s2, size_t n)
+{
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+
+ if (strlen(s1) < n) {
+ n = strlen(s1);
+ }
+ if (strlen(s2) < n) {
+ n = strlen(s2);
+ }
+
+ /*
+ RETURN(NEGATIVE, ARGUMENT(s1) is less than ARGUMENT(s2));
+ RETURN(ZERO, ARGUMENT(s1) is equal to ARGUMENT(s2));
+ RETURN(POSITIVE, ARGUMENT(s1) is greater than ARGUMENT(s2));
+ */
+ return memcmp(s1, s2, n);
+}
+
+/***
+compares up to the first ARGUMENT(n) bytes of the strings at ARGUMENT(s1) and
+ARGUMENT(s2), or until the first CHAR(\0), whichever comes first.
+***/
+/*
+STDC(1)
+*/