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 | |
36 | /* --- @buf_getdstr{8,{16,24,32,64}{,l,b},z} --- * |
37 | * |
38 | * Arguments: @buf *b@ = pointer to a buffer block |
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); \ |
57 | } |
58 | BUF_DOSUFFIXES(BUF_GETDSTR_) |
59 | |
60 | /* --- @buf_putdstr{8,{16,24,32,64}{,l,b},z} --- * |
61 | * |
62 | * Arguments: @buf *b@ = pointer to a buffer block |
63 | * @dstr *d@ = string to write |
64 | * |
65 | * Returns: Zero if it worked, nonzero if there wasn't enough space. |
66 | * |
67 | * Use: Puts a dynamic string to a buffer. |
68 | */ |
69 | |
70 | #define BUF_PUTDSTR_(n, W, w) \ |
71 | int buf_putdstr##w(buf *b, dstr *d) \ |
72 | { return (buf_putmem##w(b, d->buf, d->len)); } |
73 | BUF_DOSUFFIXES(BUF_PUTDSTR_) |
74 | |
75 | /*----- That's all, folks -------------------------------------------------*/ |