diff options
author | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
commit | bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch) | |
tree | c7d1995a09f6ed0c4e6873252e957d72f5d07d07 /matchcaseprefix.c | |
download | ldadp-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.c | 20 |
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]); +} + |