From f28b0ee6b299e17e203cfec682b5ece3587d2684 Mon Sep 17 00:00:00 2001 From: leitner Date: Thu, 28 Jun 2007 22:46:58 +0000 Subject: [PATCH] add fmt_ldapescape2 --- textcode.h | 1 + textcode/fmt_ldapescape2.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 textcode/fmt_ldapescape2.c diff --git a/textcode.h b/textcode.h index 886b926..612029f 100644 --- a/textcode.h +++ b/textcode.h @@ -34,6 +34,7 @@ size_t fmt_cescape2(char* dest,const char* src,size_t len,const char* escapeme); size_t fmt_foldwhitespace(char* dest,const char* src,size_t len); /* worst case: len*3 */ size_t fmt_ldapescape(char* dest,const char* src,size_t len); +size_t fmt_ldapescape2(char* dest,const char* src,size_t len,const char* escapeme); /* These read one line from src, decoded it, and write the result to * dest. The number of decoded bytes is written to destlen. dest diff --git a/textcode/fmt_ldapescape2.c b/textcode/fmt_ldapescape2.c new file mode 100644 index 0000000..c951258 --- /dev/null +++ b/textcode/fmt_ldapescape2.c @@ -0,0 +1,25 @@ +#include "fmt.h" +#include "textcode.h" +#include "haveinline.h" +#include + +size_t fmt_ldapescape2(char* dest,const char* src,size_t len,const char* escapeme) { + register const unsigned char* s=(const unsigned char*) src; + size_t written=0,i; + for (i=0; i>4); + dest[written+2]=fmt_tohex(s[i]&15); + } + written+=3; + } else { + if (dest) dest[written]=s[i]; ++written; + } + /* in case someone gives us malicious input */ + if (written>((size_t)-1)/2) return (size_t)-1; + } + return written; +} +