netatalk 4.5.0
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#if !defined(BSTRLIB_REDUCE_NAMESPACE_POLLUTION)
70#define bAssign(a, b) \
71 ((bassign)((a), (b)))
72
73#define bSubs(b, pos, len, a, c) \
74 ((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
75
76#define bStrchr(b, c) \
77 ((bstrchr)((b), (c)))
78
79#define bStrchrFast(b, c) \
80 ((bstrchr)((b), (c)))
81
82#define bCatCstr(b, s) \
83 ((bcatcstr)((b), (s)))
84
85#define bCatBlk(b, s, len) \
86 ((bcatblk)((b), (s), (len)))
87
88#define bCatStatic(b, s) \
89 bcatStatic(b, s)
90
91#define bTrunc(b, n) \
92 ((btrunc)((b), (n)))
93
94#define bReplaceAll(b, find, repl, pos) \
95 ((bfindreplace)((b),(find),(repl),(pos)))
96
97#define bUppercase(b) \
98 ((btoupper)(b))
99
100#define bLowercase(b) \
101 ((btolower)(b))
102
103#define bCaselessCmp(a, b) \
104 ((bstricmp)((a), (b)))
105
106#define bCaselessNCmp(a, b, n) \
107 ((bstrnicmp)((a), (b), (n)))
108
109#define bBase64Decode(b) \
110 (bBase64DecodeEx((b), NULL))
111
112#define bUuDecode(b) \
113 (bUuDecodeEx((b), NULL))
114#endif
115
116/* Unusual functions */
117
123 BSTR_PUBLIC struct bStream *
124 bsFromBstr(const bstring b);
125
129 BSTR_PUBLIC bstring
130 bTail(bstring b, int n);
131
135 BSTR_PUBLIC bstring
136 bHead(bstring b, int n);
137
146 BSTR_PUBLIC int
147 bSetCstrChar(bstring a, int pos, char c);
148
156 BSTR_PUBLIC int
157 bSetChar(bstring b, int pos, char c);
158
162 BSTR_PUBLIC int
163 bFill(bstring a, char c, int len);
164
168 BSTR_PUBLIC int
169 bReplicate(bstring b, int n);
170
174 BSTR_PUBLIC int
175 bReverse(bstring b);
176
181 BSTR_PUBLIC int
182 bInsertChrs(bstring b, int pos, int len, unsigned char c, unsigned char fill);
183
192 BSTR_PUBLIC bstring
193 bStrfTime(const char * fmt, const struct tm * timeptr);
194
195#define bAscTime(t) (bStrfTime ("%c\n", (t)))
196
197#define bCTime(t) ((t) ? bAscTime (localtime (t)) : NULL)
198
199/* Spacing formatting */
200
204 BSTR_PUBLIC int
205 bJustifyLeft(bstring b, int space);
206
210 BSTR_PUBLIC int
211 bJustifyRight(bstring b, int width, int space);
212
219 BSTR_PUBLIC int
220 bJustifyMargin(bstring b, int width, int space);
221
226 BSTR_PUBLIC int
227 bJustifyCenter(bstring b, int width, int space);
228
229/* Esoteric standards specific functions */
230
242 BSTR_PUBLIC char *
243 bStr2NetStr(const bstring b);
244
253 BSTR_PUBLIC bstring
254 bNetStr2Bstr(const char *buf);
255
261 BSTR_PUBLIC bstring
262 bBase64Encode(const bstring b);
263
271 BSTR_PUBLIC bstring
272 bBase64DecodeEx(const bstring b, int *boolTruncError);
273
283 BSTR_PUBLIC struct bStream *
284 bsUuDecode(struct bStream *sInp, int *badlines);
285
295
296 BSTR_PUBLIC bstring
297 bUuDecodeEx(const bstring src, int *badlines);
298
304 BSTR_PUBLIC bstring
305 bUuEncode(const bstring src);
306
314 BSTR_PUBLIC bstring
315 bYEncode(const bstring src);
316
322 BSTR_PUBLIC bstring
323 bYDecode(const bstring src);
324
332 BSTR_PUBLIC int
333 bSGMLEncode(bstring b);
334
335/* Writable stream */
336 typedef int
337(*bNwrite)(const void *buf, size_t elsize, size_t nelem, void *parm);
338
344 BSTR_PUBLIC struct bwriteStream *
345 bwsOpen(bNwrite writeFn, void *parm);
346
354 BSTR_PUBLIC int
355 bwsWriteBstr(struct bwriteStream *stream, const bstring b);
356
362 BSTR_PUBLIC int
363 bwsWriteBlk(struct bwriteStream *stream, void *blk, int len);
364
368 BSTR_PUBLIC int
369 bwsWriteFlush(struct bwriteStream *stream);
370
375 BSTR_PUBLIC int
376 bwsIsEOF(const struct bwriteStream *stream);
377
384 BSTR_PUBLIC int
385 bwsBuffLength(struct bwriteStream *stream, int sz);
386
394 BSTR_PUBLIC void *
395 bwsClose(struct bwriteStream *stream);
396
397/* Security functions */
398#define bSecureDestroy(b) \
399 do { \
400 if ((b) && (b)->mlen > 0 && (b)->data) { \
401 (void)memset((b)->data, 0, (size_t)(b)->mlen); \
402 } \
403 (void)bdestroy((b)); \
404} while (0)
405
406#define bSecureWriteProtect(t) \
407 do { \
408 if ((t).mlen >= 0) { \
409 if ((t).mlen > (t).slen)) { \
410 (void)memset((t).data + (t).slen, 0, \
411 (size_t)(t).mlen - (t).slen); \
412 } \
413 (t).mlen = -1; \
414 } \
415} while (0)
416
426 BSTR_PUBLIC bstring
427 bSecureInput(int maxlen, int termchar, bNgetc vgetchar, void *vgcCtx);
428
429#ifdef __cplusplus
430}
431#endif
432
433#endif /* BSTRAUX_H */
buf
static char buf[MAXPATHLEN+1]
Definition afppasswd.c:113
bwsClose
BSTR_PUBLIC void * bwsClose(struct bwriteStream *stream)
Definition bstraux.c:1222
bwsWriteFlush
BSTR_PUBLIC int bwsWriteFlush(struct bwriteStream *stream)
Definition bstraux.c:1128
bReplicate
BSTR_PUBLIC int bReplicate(bstring b, int n)
Definition bstraux.c:84
bYEncode
BSTR_PUBLIC bstring bYEncode(const bstring src)
Definition bstraux.c:854
bBase64DecodeEx
BSTR_PUBLIC bstring bBase64DecodeEx(const bstring b, int *boolTruncError)
Definition bstraux.c:439
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:1097
bYDecode
BSTR_PUBLIC bstring bYDecode(const bstring src)
Definition bstraux.c:885
bSetChar
BSTR_PUBLIC int bSetChar(bstring b, int pos, char c)
Definition bstraux.c:1013
bSetCstrChar
BSTR_PUBLIC int bSetCstrChar(bstring a, int pos, char c)
Definition bstraux.c:993
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:1143
bStrfTime
BSTR_PUBLIC bstring bStrfTime(const char *fmt, const struct tm *timeptr)
Definition bstraux.c:954
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:666
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:779
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:1185
bwsBuffLength
BSTR_PUBLIC int bwsBuffLength(struct bwriteStream *stream, int sz)
Definition bstraux.c:1208
bNwrite
int(* bNwrite)(const void *buf, size_t elsize, size_t nelem, void *parm)
Definition bstraux.h:337
bSGMLEncode
BSTR_PUBLIC int bSGMLEncode(bstring b)
Definition bstraux.c:939
bsFromBstr
BSTR_PUBLIC struct bStream * bsFromBstr(const bstring b)
Definition bstraux.c:243
bBase64Encode
BSTR_PUBLIC bstring bBase64Encode(const bstring b)
Definition bstraux.c:352
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:1031
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:1196
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:812
bstrlib.h
C implementaion of bstring functions.
BSTR_PUBLIC
#define BSTR_PUBLIC
Definition bstrlib.h:51
bstring
struct tagbstring * bstring
Definition bstrlib.h:86
bNgetc
int(* bNgetc)(void *parm)
Definition bstrlib.h:1174
config.h
c
size_t c
Definition dircache.c:257
bStream
Definition bstrlib.c:2018
bStream::parm
void * parm
Definition bstrlib.c:2020
bwriteStream
Definition bstraux.c:1088
bwriteStream::parm
void * parm
Definition bstraux.c:1090
bwriteStream::writeFn
bNwrite writeFn
Definition bstraux.c:1091