5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
23 * Revision 1.1 2000/09/13 17:45:16 priikone
24 * Splitted SILC core library. Core library includes now only
25 * SILC protocol specific stuff. New utility library includes the
26 * old stuff from core library that is more generic purpose stuff.
28 * Revision 1.3 2000/07/14 06:08:49 priikone
29 * Added silc_buffer_realloc. Fixed silc_buffer_clone.
31 * Revision 1.2 2000/07/05 06:06:35 priikone
32 * Global cosmetic change.
34 * Revision 1.1.1.1 2000/06/27 11:36:55 priikone
35 * Imported from internal CVS/Added Log headers.
40 #include "silcincludes.h"
42 #ifdef SILC_DEBUG /* If we are doing debugging we won't
43 have the optimized inline buffer functions
44 available as optimization is not set
45 to compiler. These normal routines are
46 used in debugging mode. */
48 /* Clears and initialiazes the buffer to the state as if it was just
49 allocated by silc_buffer_alloc. */
51 void silc_buffer_clear(SilcBuffer sb)
53 memset(sb->head, 0, sb->truelen);
59 /* Generates copy of a SilcBuffer. This copies everything inside the
60 currently valid data area, nothing more. Use silc_buffer_clone to
61 copy entire buffer. */
63 SilcBuffer silc_buffer_copy(SilcBuffer sb)
67 sb_new = silc_buffer_alloc(sb->len);
68 silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
69 silc_buffer_put(sb_new, sb->data, sb->len);
74 /* Clones SilcBuffer. This generates new SilcBuffer and copies
75 everything from the source buffer. The result is exact clone of
76 the original buffer. */
78 SilcBuffer silc_buffer_clone(SilcBuffer sb)
82 sb_new = silc_buffer_alloc(sb->truelen);
83 silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
84 silc_buffer_put(sb_new, sb->head, sb->truelen);
85 sb_new->data = sb_new->head + (sb->data - sb->head);
86 sb_new->tail = sb_new->data + sb->len;
87 sb_new->len = sb->len;
92 /* Reallocates buffer. Old data is saved into the new buffer. Returns
93 new SilcBuffer pointer. The buffer is exact clone of the old one
94 except that there is now more space at the end of buffer. */
96 SilcBuffer silc_buffer_realloc(SilcBuffer sb, unsigned int newsize)
100 sb_new = silc_buffer_alloc(newsize);
101 silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
102 silc_buffer_put(sb_new, sb->head, sb->truelen);
103 sb_new->data = sb_new->head + (sb->data - sb->head);
104 sb_new->tail = sb_new->data + sb->len;
105 sb_new->len = sb->len;
107 silc_buffer_free(sb);
112 #endif /* SILC_DEBUG */