Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/nettle/buffer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* buffer.h
0002 
0003    A bare-bones string stream.
0004 
0005    Copyright (C) 2002 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033  
0034 #ifndef NETTLE_BUFFER_H_INCLUDED
0035 #define NETTLE_BUFFER_H_INCLUDED
0036 
0037 #include "realloc.h"
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 struct nettle_buffer
0044 {
0045   uint8_t *contents;
0046   /* Allocated size */
0047   size_t alloc;
0048 
0049   void *realloc_ctx;
0050   nettle_realloc_func *realloc;
0051 
0052   /* Current size */
0053   size_t size;
0054 };
0055 
0056 /* Initializes a buffer that uses plain realloc */
0057 void
0058 nettle_buffer_init(struct nettle_buffer *buffer);
0059 
0060 void
0061 nettle_buffer_init_realloc(struct nettle_buffer *buffer,
0062                void *realloc_ctx,
0063                nettle_realloc_func *realloc);
0064 
0065 /* Initializes a buffer of fix size */
0066 void
0067 nettle_buffer_init_size(struct nettle_buffer *buffer,
0068             size_t length, uint8_t *space);
0069 
0070 void
0071 nettle_buffer_clear(struct nettle_buffer *buffer);
0072 
0073 /* Resets the buffer, without freeing the buffer space. */
0074 void
0075 nettle_buffer_reset(struct nettle_buffer *buffer);
0076 
0077 int
0078 nettle_buffer_grow(struct nettle_buffer *buffer,
0079            size_t length);
0080 
0081 #define NETTLE_BUFFER_PUTC(buffer, c) \
0082 ( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
0083   && ((buffer)->contents[(buffer)->size++] = (c), 1) )
0084 
0085 int
0086 nettle_buffer_write(struct nettle_buffer *buffer,
0087             size_t length, const uint8_t *data);
0088 
0089 /* Like nettle_buffer_write, but instead of copying data to the
0090  * buffer, it returns a pointer to the area where the caller can copy
0091  * the data. The pointer is valid only until the next call that can
0092  * reallocate the buffer. */
0093 uint8_t *
0094 nettle_buffer_space(struct nettle_buffer *buffer,
0095             size_t length);
0096 
0097 /* Copy the contents of SRC to the end of DST. */
0098 int
0099 nettle_buffer_copy(struct nettle_buffer *dst,
0100            const struct nettle_buffer *src);
0101 
0102 #ifdef __cplusplus
0103 }
0104 #endif
0105 
0106 #endif /* NETTLE_BUFFER_H_INCLUDED */