Files
mars-tinyldap/bstr.h
2024-11-26 16:23:20 +00:00

31 lines
1.2 KiB
C

#include <stddef.h>
#include <libowfat/compiler.h>
/* The LDAP read-only data store is mmapped and trusted, because it
* takes higher privileges than tinyldap has to modify it.
* Strings are stored in it as ASCIIZ, so we can just operate on them
* after mapping the file into memory.
* However, we also need to be able to store binary data including
* 0 bytes, so we extend the format slightly. Zero-length strings don't
* happen in regular LDAP, so if the string starts with a 0 byte, the
* next four bytes are a little-endian 32-bit length value and after
* than come that many binary bytes.
* This means we need small wrappers around strlen and strcmp.
* These are those small wrappers. */
__strin(1) __strin(2) att_pure
int bstr_diff(const char* a,const char* b);
#define bstr_equal(s,t) (!bstr_diff((s),(t)))
__strin(1) __strnin(2,3) att_pure
int bstr_diff2(const char* a,const char* b,size_t blen);
#define bstr_equal2(s,t,l) (!bstr_diff2((s),(t),(l)))
__strin(1) att_pure
size_t bstrlen(const char* a);
__strin(1) att_pure
size_t bstrstart(const char* a); /* offset of first byte of bstring */
__strin(1) att_pure
const char* bstrfirst(const char* a); /* pointer to first byte of bstring */