Global cosmetic change.
[silc.git] / lib / silccore / silcbufutil.c
1 /*
2
3   silcbufutil.c
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20 /*
21  * $Id$
22  * $Log$
23  * Revision 1.2  2000/07/05 06:06:35  priikone
24  *      Global cosmetic change.
25  *
26  * Revision 1.1.1.1  2000/06/27 11:36:55  priikone
27  *      Imported from internal CVS/Added Log headers.
28  *
29  *
30  */
31
32 #include "silcincludes.h"
33
34 #ifdef SILC_DEBUG               /* If we are doing debugging we won't
35                                    have the optimized inline buffer functions
36                                    available as optimization is not set
37                                    to compiler. These normal routines are
38                                    used in debugging mode. */
39
40 /* Clears and initialiazes the buffer to the state as if it was just
41    allocated by silc_buffer_alloc. */
42
43 void silc_buffer_clear(SilcBuffer sb)
44 {
45   memset(sb->head, 0, sb->truelen);
46   sb->data = sb->head;
47   sb->tail = sb->head;
48   sb->len = 0;
49 }
50
51 /* Generates copy of a SilcBuffer. This copies everything inside the
52    currently valid data area, nothing more. Use silc_buffer_clone to
53    copy entire buffer. */
54
55 SilcBuffer silc_buffer_copy(SilcBuffer sb)
56 {
57   SilcBuffer sb_new;
58
59   sb_new = silc_buffer_alloc(sb->len);
60   silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
61   silc_buffer_put(sb_new, sb->data, sb->len);
62
63   return sb_new;
64 }
65
66 /* Clones SilcBuffer. This generates new SilcBuffer and copies
67    everything from the source buffer. The result is exact clone of
68    the original buffer. */
69
70 SilcBuffer silc_buffer_clone(SilcBuffer sb)
71 {
72   SilcBuffer sb_new;
73
74   sb_new = silc_buffer_alloc(sb->truelen);
75   silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
76   silc_buffer_put(sb_new, sb->head, sb->truelen);
77   sb_new->data = sb_new->head + sb->len;
78   sb_new->tail = sb_new->head + (sb->end - sb->tail);
79   sb_new->len = sb->len;
80
81   return sb_new;
82 }
83
84 #endif /* SILC_DEBUG */