Change soft-fail to use the config, rather than env
[rbx.git] / shotgun / external_libs / libbstring / bstraux.h
blob21dd367ced5bbc2906f1a00faeea867fa6700726
1 /*
2 * This source file is part of the bstring string library. This code was
3 * written by Paul Hsieh in 2002-2007, and is covered by the BSD open source
4 * license. Refer to the accompanying documentation for details on usage and
5 * license.
6 */
8 /*
9 * bstraux.h
11 * This file is not a necessary part of the core bstring library itself, but
12 * is just an auxilliary module which includes miscellaneous or trivial
13 * functions.
16 #ifndef BSTRAUX_INCLUDE
17 #define BSTRAUX_INCLUDE
19 #include <time.h>
20 #include "bstrlib.h"
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
26 /* Safety mechanisms */
27 #define bstrDeclare(b) bstring (b) = NULL;
28 #define bstrFree(b) {if ((b) != NULL && (b)->slen >= 0 && (b)->mlen >= (b)->slen) { bdestroy (b); (b) = NULL; }}
30 /* Backward compatibilty with previous versions of Bstrlib */
31 #define bAssign(a,b) ((bassign)((a), (b)))
32 #define bSubs(b,pos,len,a,c) ((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
33 #define bStrchr(b,c) ((bstrchr)((b), (c)))
34 #define bStrchrFast(b,c) ((bstrchr)((b), (c)))
35 #define bCatCstr(b,s) ((bcatcstr)((b), (s)))
36 #define bCatBlk(b,s,len) ((bcatblk)((b),(s),(len)))
37 #define bCatStatic(b,s) bCatBlk ((b), ("" s ""), sizeof (s) - 1)
38 #define bTrunc(b,n) ((btrunc)((b), (n)))
39 #define bReplaceAll(b,find,repl,pos) ((bfindreplace)((b),(find),(repl),(pos)))
40 #define bUppercase(b) ((btoupper)(b))
41 #define bLowercase(b) ((btolower)(b))
42 #define bCaselessCmp(a,b) ((bstricmp)((a), (b)))
43 #define bCaselessNCmp(a,b,n) ((bstrnicmp)((a), (b), (n)))
44 #define bBase64Decode(b) (bBase64DecodeEx ((b), NULL))
45 #define bUuDecode(b) (bUuDecodeEx ((b), NULL))
47 /* Unusual functions */
48 extern struct bStream * bsFromBstr (const_bstring b);
49 extern bstring bTail (bstring b, int n);
50 extern bstring bHead (bstring b, int n);
51 extern int bSetCstrChar (bstring a, int pos, char c);
52 extern int bSetChar (bstring b, int pos, char c);
53 extern int bFill (bstring a, char c, int len);
54 extern int bReplicate (bstring b, int n);
55 extern int bReverse (bstring b);
56 extern int bInsertChrs (bstring b, int pos, int len, unsigned char c, unsigned char fill);
57 extern bstring bStrfTime (const char * fmt, const struct tm * timeptr);
58 #define bAscTime(t) (bStrfTime ("%c\n", (t)))
59 #define bCTime(t) ((t) ? bAscTime (localtime (t)) : NULL)
61 /* Spacing formatting */
62 extern int bJustifyLeft (bstring b, int space);
63 extern int bJustifyRight (bstring b, int width, int space);
64 extern int bJustifyMargin (bstring b, int width, int space);
65 extern int bJustifyCenter (bstring b, int width, int space);
67 /* Esoteric standards specific functions */
68 extern char * bStr2NetStr (const_bstring b);
69 extern bstring bNetStr2Bstr (const char * buf);
70 extern bstring bBase64Encode (const_bstring b);
71 extern bstring bBase64DecodeEx (const_bstring b, int * boolTruncError);
72 extern struct bStream * bsUuDecode (struct bStream * sInp, int * badlines);
73 extern bstring bUuDecodeEx (const_bstring src, int * badlines);
74 extern bstring bUuEncode (const_bstring src);
75 extern bstring bYEncode (const_bstring src);
76 extern bstring bYDecode (const_bstring src);
78 /* Writable stream */
79 typedef int (* bNwrite) (const void * buf, size_t elsize, size_t nelem, void * parm);
81 struct bwriteStream * bwsOpen (bNwrite writeFn, void * parm);
82 int bwsWriteBstr (struct bwriteStream * stream, const_bstring b);
83 int bwsWriteBlk (struct bwriteStream * stream, void * blk, int len);
84 int bwsWriteFlush (struct bwriteStream * stream);
85 int bwsIsEOF (const struct bwriteStream * stream);
86 int bwsBuffLength (struct bwriteStream * stream, int sz);
87 void * bwsClose (struct bwriteStream * stream);
89 /* Security functions */
90 #define bSecureDestroy(b) { \
91 bstring bstr__tmp = (b); \
92 if (bstr__tmp && bstr__tmp->mlen > 0 && bstr__tmp->data) { \
93 (void) memset (bstr__tmp->data, 0, (size_t) bstr__tmp->mlen); \
94 bdestroy (bstr__tmp); \
95 } \
97 #define bSecureWriteProtect(t) { \
98 if ((t).mlen >= 0) { \
99 if ((t).mlen > (t).slen)) { \
100 (void) memset ((t).data + (t).slen, 0, (size_t) (t).mlen - (t).slen); \
102 (t).mlen = -1; \
105 extern bstring bSecureInput (int maxlen, int termchar,
106 bNgetc vgetchar, void * vgcCtx);
108 #ifdef __cplusplus
110 #endif
112 #endif