summaryrefslogtreecommitdiffstats
path: root/matchcaseprefix.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-03-15 01:49:50 +0100
committerSimon Rettberg2014-03-15 01:49:50 +0100
commitbedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch)
treec7d1995a09f6ed0c4e6873252e957d72f5d07d07 /matchcaseprefix.c
downloadldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'matchcaseprefix.c')
-rw-r--r--matchcaseprefix.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/matchcaseprefix.c b/matchcaseprefix.c
new file mode 100644
index 0000000..9f709b7
--- /dev/null
+++ b/matchcaseprefix.c
@@ -0,0 +1,20 @@
+#include <string.h>
+#include "case.h"
+#include "asn1.h"
+#include "str.h"
+
+/* behave like strcmp, but also return 0 if s is a prefix of c. */
+int matchcaseprefix(struct string* s,const char* c) {
+ unsigned int l,l1,i;
+ if (!c) return -1;
+ l1=l=str_len(c);
+ if (s->l<l1) l1=s->l;
+ i=case_diffb(s->s,l1,c);
+ if (i) return i;
+ /* one is a prefix of the other */
+ if (l==s->l) return 0;
+ if (c[l1]) /* is c the longer string? */
+ return 0;
+ return -(int)(s->s[l1]);
+}
+