netatalk 4.4.3
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
bstraux.h
Go to the documentation of this file.
1/* Copyright 2002-2015 Paul Hsieh
2 * This file is part of Bstrlib.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * 3. Neither the name of bstrlib nor the names of its contributors may be
15 * used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Alternatively, the contents of this file may be used under the terms of
31 * GNU General Public License Version 2 (the "GPL").
32 */
33
41
42#ifndef BSTRAUX_H
43#define BSTRAUX_H
44
45#ifdef HAVE_CONFIG_H
46#include <config.h>
47#endif
48
49#include <time.h>
50#include <bstrlib.h>
51
52#ifdef __cplusplus
53 extern "C" {
54#endif
55
56/* Safety mechanisms */
57#define bstrDeclare(b) \
58 bstring(b) = NULL
59
60#define bstrFree(b) \
61 do { \
62 if ((b) != NULL && (b)->slen >= 0 && (b)->mlen >= (b)->slen) { \
63 bdestroy(b); \
64 (b) = NULL; \
65 } \
66} while (0)
67
68/* Backward compatibilty with previous versions of Bstrlib */
69#define bAssign(a, b) \
70 ((bassign)((a), (b)))
71
72#define bSubs(b, pos, len, a, c) \
73 ((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
74
75#define bStrchr(b, c) \
76 ((bstrchr)((b), (c)))
77
78#define bStrchrFast(b, c) \
79 ((bstrchr)((b), (c)))
80
81#define bCatCstr(b, s) \
82 ((bcatcstr)((b), (s)))
83
84#define bCatBlk(b, s, len) \
85 ((bcatblk)((b), (s), (len)))
86
87#define bCatStatic(b, s) \
88 bCatBlk((b), ("" s ""), sizeof (s) - 1)
89
90#define bTrunc(b, n) \
91 ((btrunc)((b), (n)))
92
93#define bReplaceAll(b, find, repl, pos) \
94 ((bfindreplace)((b),(find),(repl),(pos)))
95
96#define bUppercase(b) \
97 ((btoupper)(b))
98
99#define bLowercase(b) \
100 ((btolower)(b))
101
102#define bCaselessCmp(a, b) \
103 ((bstricmp)((a), (b)))
104
105#define bCaselessNCmp(a, b, n) \
106 ((bstrnicmp)((a), (b), (n)))
107
108#define bBase64Decode(b) \
109 (bBase64DecodeEx((b), NULL))
110
111#define bUuDecode(b) \
112 (bUuDecodeEx((b), NULL))
113
114/* Unusual functions */
115
121 BSTR_PUBLIC struct bStream *
122 bsFromBstr(const bstring b);
123
127 BSTR_PUBLIC bstring
128 bTail(bstring b, int n);
129
133 BSTR_PUBLIC bstring
134 bHead(bstring b, int n);
135
144 BSTR_PUBLIC int
145 bSetCstrChar(bstring a, int pos, char c);
146
154 BSTR_PUBLIC int
155 bSetChar(bstring b, int pos, char c);
156
160 BSTR_PUBLIC int
161 bFill(bstring a, char c, int len);
162
166 BSTR_PUBLIC int
167 bReplicate(bstring b, int n);
168
172 BSTR_PUBLIC int
173 bReverse(bstring b);
174
179 BSTR_PUBLIC int
180 bInsertChrs(bstring b, int pos, int len, unsigned char c, unsigned char fill);
181
190 BSTR_PUBLIC bstring
191 bStrfTime(const char * fmt, const struct tm * timeptr);
192
193#define bAscTime(t) (bStrfTime ("%c\n", (t)))
194
195#define bCTime(t) ((t) ? bAscTime (localtime (t)) : NULL)
196
197/* Spacing formatting */
198
202 BSTR_PUBLIC int
203 bJustifyLeft(bstring b, int space);
204
208 BSTR_PUBLIC int
209 bJustifyRight(bstring b, int width, int space);
210
217 BSTR_PUBLIC int
218 bJustifyMargin(bstring b, int width, int space);
219
224 BSTR_PUBLIC int
225 bJustifyCenter(bstring b, int width, int space);
226
227/* Esoteric standards specific functions */
228
240 BSTR_PUBLIC char *
241 bStr2NetStr(const bstring b);
242
251 BSTR_PUBLIC bstring
252 bNetStr2Bstr(const char *buf);
253
259 BSTR_PUBLIC bstring
260 bBase64Encode(const bstring b);
261
269 BSTR_PUBLIC bstring
270 bBase64DecodeEx(const bstring b, int *boolTruncError);
271
281 BSTR_PUBLIC struct bStream *
282 bsUuDecode(struct bStream *sInp, int *badlines);
283
293
294 BSTR_PUBLIC bstring
295 bUuDecodeEx(const bstring src, int *badlines);
296
302 BSTR_PUBLIC bstring
303 bUuEncode(const bstring src);
304
312 BSTR_PUBLIC bstring
313 bYEncode(const bstring src);
314
320 BSTR_PUBLIC bstring
321 bYDecode(const bstring src);
322
323/* Writable stream */
324 typedef int
325(*bNwrite)(const void *buf, size_t elsize, size_t nelem, void *parm);
326
332 BSTR_PUBLIC struct bwriteStream *
333 bwsOpen(bNwrite writeFn, void *parm);
334
342 BSTR_PUBLIC int
343 bwsWriteBstr(struct bwriteStream *stream, const bstring b);
344
350 BSTR_PUBLIC int
351 bwsWriteBlk(struct bwriteStream *stream, void *blk, int len);
352
356 BSTR_PUBLIC int
357 bwsWriteFlush(struct bwriteStream *stream);
358
363 BSTR_PUBLIC int
364 bwsIsEOF(const struct bwriteStream *stream);
365
372 BSTR_PUBLIC int
373 bwsBuffLength(struct bwriteStream *stream, int sz);
374
382 BSTR_PUBLIC void *
383 bwsClose(struct bwriteStream *stream);
384
385/* Security functions */
386#define bSecureDestroy(b) \
387 do { \
388 if ((b) && (b)->mlen > 0 && (b)->data) { \
389 (void)memset((b)->data, 0, (size_t)(b)->mlen); \
390 } \
391 (void)bdestroy((b)); \
392} while (0)
393
394#define bSecureWriteProtect(t) \
395 do { \
396 if ((t).mlen >= 0) { \
397 if ((t).mlen > (t).slen)) { \
398 (void)memset((t).data + (t).slen, 0, \
399 (size_t)(t).mlen - (t).slen); \
400 } \
401 (t).mlen = -1; \
402 } \
403} while (0)
404
414 BSTR_PUBLIC bstring
415 bSecureInput(int maxlen, int termchar, bNgetc vgetchar, void *vgcCtx);
416
417#ifdef __cplusplus
418}
419#endif
420
421#endif /* BSTRAUX_H */
buf
static char buf[MAXPATHLEN+1]
Definition afppasswd.c:75
bwsClose
BSTR_PUBLIC void * bwsClose(struct bwriteStream *stream)
Definition bstraux.c:1178
bwsWriteFlush
BSTR_PUBLIC int bwsWriteFlush(struct bwriteStream *stream)
Definition bstraux.c:1084
bReplicate
BSTR_PUBLIC int bReplicate(bstring b, int n)
Definition bstraux.c:84
bYEncode
BSTR_PUBLIC bstring bYEncode(const bstring src)
Definition bstraux.c:832
bBase64DecodeEx
BSTR_PUBLIC bstring bBase64DecodeEx(const bstring b, int *boolTruncError)
Definition bstraux.c:430
bHead
BSTR_PUBLIC bstring bHead(bstring b, int n)
Definition bstraux.c:62
bReverse
BSTR_PUBLIC int bReverse(bstring b)
Definition bstraux.c:90
bwsOpen
BSTR_PUBLIC struct bwriteStream * bwsOpen(bNwrite writeFn, void *parm)
Definition bstraux.c:1053
bYDecode
BSTR_PUBLIC bstring bYDecode(const bstring src)
Definition bstraux.c:863
bSetChar
BSTR_PUBLIC int bSetChar(bstring b, int pos, char c)
Definition bstraux.c:972
bSetCstrChar
BSTR_PUBLIC int bSetCstrChar(bstring a, int pos, char c)
Definition bstraux.c:952
bStr2NetStr
BSTR_PUBLIC char * bStr2NetStr(const bstring b)
Definition bstraux.c:285
bwsWriteBstr
BSTR_PUBLIC int bwsWriteBstr(struct bwriteStream *stream, const bstring b)
Definition bstraux.c:1099
bStrfTime
BSTR_PUBLIC bstring bStrfTime(const char *fmt, const struct tm *timeptr)
Definition bstraux.c:913
bFill
BSTR_PUBLIC int bFill(bstring a, char c, int len)
Definition bstraux.c:74
bJustifyRight
BSTR_PUBLIC int bJustifyRight(bstring b, int width, int space)
Definition bstraux.c:161
bUuDecodeEx
BSTR_PUBLIC bstring bUuDecodeEx(const bstring src, int *badlines)
Definition bstraux.c:652
bJustifyCenter
BSTR_PUBLIC int bJustifyCenter(bstring b, int width, int space)
Definition bstraux.c:177
bsUuDecode
BSTR_PUBLIC struct bStream * bsUuDecode(struct bStream *sInp, int *badlines)
Definition bstraux.c:757
bJustifyMargin
BSTR_PUBLIC int bJustifyMargin(bstring b, int width, int space)
Definition bstraux.c:194
bwsWriteBlk
BSTR_PUBLIC int bwsWriteBlk(struct bwriteStream *stream, void *blk, int len)
Definition bstraux.c:1141
bwsBuffLength
BSTR_PUBLIC int bwsBuffLength(struct bwriteStream *stream, int sz)
Definition bstraux.c:1164
bNwrite
int(* bNwrite)(const void *buf, size_t elsize, size_t nelem, void *parm)
Definition bstraux.h:325
bsFromBstr
BSTR_PUBLIC struct bStream * bsFromBstr(const bstring b)
Definition bstraux.c:243
bBase64Encode
BSTR_PUBLIC bstring bBase64Encode(const bstring b)
Definition bstraux.c:343
bInsertChrs
BSTR_PUBLIC int bInsertChrs(bstring b, int pos, int len, unsigned char c, unsigned char fill)
Definition bstraux.c:111
bSecureInput
BSTR_PUBLIC bstring bSecureInput(int maxlen, int termchar, bNgetc vgetchar, void *vgcCtx)
Definition bstraux.c:990
bTail
BSTR_PUBLIC bstring bTail(bstring b, int n)
Definition bstraux.c:50
bwsIsEOF
BSTR_PUBLIC int bwsIsEOF(const struct bwriteStream *stream)
Definition bstraux.c:1152
bNetStr2Bstr
BSTR_PUBLIC bstring bNetStr2Bstr(const char *buf)
Definition bstraux.c:306
bJustifyLeft
BSTR_PUBLIC int bJustifyLeft(bstring b, int space)
Definition bstraux.c:137
bUuEncode
BSTR_PUBLIC bstring bUuEncode(const bstring src)
Definition bstraux.c:790
bstrlib.h
C implementaion of bstring functions.
BSTR_PUBLIC
#define BSTR_PUBLIC
Definition bstrlib.h:51
bstring
struct tagbstring * bstring
Definition bstrlib.h:82
bNgetc
int(* bNgetc)(void *parm)
Definition bstrlib.h:1116
config.h
bStream
Definition bstrlib.c:1964
bStream::parm
void * parm
Definition bstrlib.c:1966
bwriteStream
Definition bstraux.c:1044
bwriteStream::parm
void * parm
Definition bstraux.c:1046
bwriteStream::writeFn
bNwrite writeFn
Definition bstraux.c:1047