3 * Buffers and dynamic strings
5 * (c) 2005 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
34 /*----- Main code ---------------------------------------------------------*/
36 /* --- @{,d}buf_getdstr{8,{16,24,32,64}{,l,b},z} --- *
38 * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block
39 * @dstr *d@ = where to put the result
41 * Returns: Zero if it worked, nonzero if there wasn't enough space.
43 * Use: Gets a block of data from a buffer, and writes its contents
47 #define BUF_GETDSTR_(n, W, w) \
48 int buf_getdstr##w(buf *b, dstr *d) \
53 if ((p = buf_getmem##w(b, &sz)) == 0) \
58 int (dbuf_getdstr##w)(dbuf *db, dstr *d) \
59 { return (dbuf_getdstr##w(db, d)); }
60 BUF_DOSUFFIXES(BUF_GETDSTR_)
62 /* --- @{,d}buf_putdstr{8,{16,24,32,64}{,l,b},z} --- *
64 * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block
65 * @dstr *d@ = string to write
67 * Returns: Zero if it worked, nonzero if there wasn't enough space.
69 * Use: Puts a dynamic string to a buffer.
72 #define BUF_PUTDSTR_(n, W, w) \
73 int buf_putdstr##w(buf *b, dstr *d) \
74 { return (buf_putmem##w(b, d->buf, d->len)); } \
75 int (dbuf_putdstr##w)(dbuf *db, dstr *d) \
76 { return (dbuf_putdstr##w(db, d)); }
77 BUF_DOSUFFIXES(BUF_PUTDSTR_)
79 /*----- That's all, folks -------------------------------------------------*/