some more compiler attributes
make sure all textcode/scan_* routines work if dest or destlen is NULL
This commit is contained in:
62
textcode.h
62
textcode.h
@@ -3,6 +3,7 @@
|
||||
#define TEXTCODE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <libowfat/compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -11,120 +12,125 @@ extern "C" {
|
||||
/* These take len bytes from src and write them in encoded form to
|
||||
* dest (if dest != NULL), returning the number of bytes written. */
|
||||
|
||||
/* dietlibc defines these in sys/cdefs.h, which is included from stddef.h */
|
||||
#ifndef __readmemsz__
|
||||
#define __readmemsz__(a,b)
|
||||
#endif
|
||||
|
||||
#ifndef __writemem__
|
||||
#define __writemem__(a)
|
||||
#endif
|
||||
|
||||
/* Needs len/3*4 bytes */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_uuencoded(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Needs len/3*4 bytes */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_base64(char* dest,const char* src,size_t len);
|
||||
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_base64url(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Worst case: len*3 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_quotedprintable(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Worst case: len*3 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_quotedprintable2(char* dest,const char* src,size_t len,const char* escapeme);
|
||||
|
||||
/* Worst case: len*3 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_urlencoded(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Worst case: len*3 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_urlencoded2(char* dest,const char* src,size_t len,const char* escapeme);
|
||||
|
||||
/* Worst case: len*2 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_yenc(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Needs len*2 bytes */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_hexdump(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Change '<' to '<' and '&' to '&' and '\n' to '<br>'; worst case: len*5 */
|
||||
/* This is meant for outputting text that goes between tags */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_html(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Change '<' to '<' and '&' to '&' and '"' to '"'; worst case: len*6 */
|
||||
/* This is meant for outputting text that goes in a tag argument between double quotes*/
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_html_tagarg(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Change '<' to '<' and '&' to '&'; worst case: len*5 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_xml(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Change '\' to "\\", '\n' to "\n", ^A to "\x01" etc; worst case: len*4 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_cescape(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Worst case: len*4 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_cescape2(char* dest,const char* src,size_t len,const char* escapeme);
|
||||
|
||||
/* Fold whitespace to '_'; this is great for writing fields with
|
||||
* white spaces to a log file and still allow awk to do log analysis */
|
||||
/* Worst case: same size */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_foldwhitespace(char* dest,const char* src,size_t len);
|
||||
|
||||
/* Worst case: len*3 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_ldapescape(char* dest,const char* src,size_t len);
|
||||
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_ldapescape2(char* dest,const char* src,size_t len,const char* escapeme);
|
||||
|
||||
/* Encode JSON string from UTF-8; will backslash-escape the bare minimum.
|
||||
* Invalid UTF-8 in input will output as valid UTF-8 for each byte
|
||||
* Worst case: len*6 */
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_jsonescape(char* dest,const char* src,size_t len);
|
||||
|
||||
__writemem__(1) __readmemsz__(2,3)
|
||||
__strout_ornull(1) __bufin(2,3)
|
||||
size_t fmt_base85(char* dest,const char* src,size_t len);
|
||||
|
||||
/* These read one line from src, decode it, and write the result to
|
||||
* dest. The number of decoded bytes is written to destlen. dest
|
||||
* should be able to hold strlen(src) bytes as a rule of thumb. */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_uuencoded(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_base64(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_base64url(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_quotedprintable(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_urlencoded(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_urlencoded2(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_yenc(const char* src,char* dest,size_t* destlen);
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_hexdump(const char* src,char* dest,size_t* destlen);
|
||||
/* decodes all html5-standardized &foo; escapes, and also
|
||||
* "<br>" to "\n" and "<p>" to "\n\n", leaves the rest of the tags alone */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_html(const char* src,char* dest,size_t* destlen);
|
||||
/* decodes all html5-standardized &foo; escapes, but leaves all tags
|
||||
* alone */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_html_tagarg(const char* src,char* dest,size_t* destlen);
|
||||
/* Decodes escaped C string text, turning e.g. \n into newline */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_cescape(const char* src,char* dest,size_t* destlen);
|
||||
/* Decodes escaped LDIF text, turning e.g. \5C into \ */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_ldapescape(const char* src,char* dest,size_t* destlen);
|
||||
/* Decodes escaped JSON strings (like \"\r\n\u0013), turns escaped
|
||||
* surrogate pairs into UTF-8. Expects input to be valid UTF-8. Ends at
|
||||
* \0 or unescaped double quote. */
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_jsonescape(const char* src,char* dest,size_t* destlen);
|
||||
|
||||
__strin(1) __strout_ornull(2) __retarg_ornull(3)
|
||||
size_t scan_base85(const char* src,char* dest,size_t* destlen);
|
||||
|
||||
#ifdef STRALLOC_H
|
||||
|
||||
Reference in New Issue
Block a user