Commit | Line | Data |
---|---|---|
9b5ac6ff | 1 | /* -*-c-*- |
2 | * | |
9b5ac6ff | 3 | * Buffers and dynamic strings |
4 | * | |
5 | * (c) 2005 Straylight/Edgeware | |
6 | */ | |
7 | ||
d4efbcd9 | 8 | /*----- Licensing notice --------------------------------------------------* |
9b5ac6ff | 9 | * |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
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. | |
d4efbcd9 | 16 | * |
9b5ac6ff | 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. | |
d4efbcd9 | 21 | * |
9b5ac6ff | 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, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
28 | /*----- Header files ------------------------------------------------------*/ | |
29 | ||
30 | #include <string.h> | |
31 | ||
32 | #include "buf.h" | |
33 | ||
34 | /*----- Main code ---------------------------------------------------------*/ | |
35 | ||
31d0247c | 36 | /* --- @{,d}buf_getdstr{8,{16,24,32,64}{,l,b},z} --- * |
9b5ac6ff | 37 | * |
31d0247c | 38 | * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block |
9b5ac6ff | 39 | * @dstr *d@ = where to put the result |
40 | * | |
41 | * Returns: Zero if it worked, nonzero if there wasn't enough space. | |
42 | * | |
43 | * Use: Gets a block of data from a buffer, and writes its contents | |
44 | * to a string. | |
45 | */ | |
46 | ||
47 | #define BUF_GETDSTR_(n, W, w) \ | |
48 | int buf_getdstr##w(buf *b, dstr *d) \ | |
49 | { \ | |
50 | void *p; \ | |
51 | size_t sz; \ | |
52 | \ | |
53 | if ((p = buf_getmem##w(b, &sz)) == 0) \ | |
54 | return (-1); \ | |
55 | DPUTM(d, p, sz); \ | |
56 | return (0); \ | |
31d0247c MW |
57 | } \ |
58 | int (dbuf_getdstr##w)(dbuf *db, dstr *d) \ | |
59 | { return (dbuf_getdstr##w(db, d)); } | |
9b5ac6ff | 60 | BUF_DOSUFFIXES(BUF_GETDSTR_) |
61 | ||
31d0247c | 62 | /* --- @{,d}buf_putdstr{8,{16,24,32,64}{,l,b},z} --- * |
9b5ac6ff | 63 | * |
31d0247c | 64 | * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block |
9b5ac6ff | 65 | * @dstr *d@ = string to write |
66 | * | |
67 | * Returns: Zero if it worked, nonzero if there wasn't enough space. | |
68 | * | |
69 | * Use: Puts a dynamic string to a buffer. | |
70 | */ | |
71 | ||
72 | #define BUF_PUTDSTR_(n, W, w) \ | |
73 | int buf_putdstr##w(buf *b, dstr *d) \ | |
31d0247c MW |
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)); } | |
9b5ac6ff | 77 | BUF_DOSUFFIXES(BUF_PUTDSTR_) |
78 | ||
79 | /*----- That's all, folks -------------------------------------------------*/ |