|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* Copyright (C) 2007, 2012 Stefan Walter
|
|
Packit Service |
3749ba |
* Copyright (C) 2012 Red Hat Inc.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
3749ba |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
3749ba |
* are met:
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* * Redistributions of source code must retain the above
|
|
Packit Service |
3749ba |
* copyright notice, this list of conditions and the
|
|
Packit Service |
3749ba |
* following disclaimer.
|
|
Packit Service |
3749ba |
* * Redistributions in binary form must reproduce the
|
|
Packit Service |
3749ba |
* above copyright notice, this list of conditions and
|
|
Packit Service |
3749ba |
* the following disclaimer in the documentation and/or
|
|
Packit Service |
3749ba |
* other materials provided with the distribution.
|
|
Packit Service |
3749ba |
* * The names of contributors to this software may not be
|
|
Packit Service |
3749ba |
* used to endorse or promote products derived from this
|
|
Packit Service |
3749ba |
* software without specific prior written permission.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
3749ba |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
3749ba |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit Service |
3749ba |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit Service |
3749ba |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit Service |
3749ba |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
Packit Service |
3749ba |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
Packit Service |
3749ba |
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
Packit Service |
3749ba |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit Service |
3749ba |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
Packit Service |
3749ba |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
Packit Service |
3749ba |
* DAMAGE.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Author: Stef Walter <stef@thewalter.net>
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#ifndef P11_BUFFER_H_
|
|
Packit Service |
3749ba |
#define P11_BUFFER_H_
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "compat.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
enum {
|
|
Packit Service |
3749ba |
P11_BUFFER_FAILED = 1 << 0,
|
|
Packit Service |
3749ba |
P11_BUFFER_NULL = 1 << 1,
|
|
Packit Service |
3749ba |
};
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
typedef struct {
|
|
Packit Service |
3749ba |
void *data;
|
|
Packit Service |
3749ba |
size_t len;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
int flags;
|
|
Packit Service |
3749ba |
size_t size;
|
|
Packit Service |
3749ba |
void * (* frealloc) (void *, size_t);
|
|
Packit Service |
3749ba |
void (* ffree) (void *);
|
|
Packit Service |
3749ba |
} p11_buffer;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
bool p11_buffer_init (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
size_t size);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
bool p11_buffer_init_null (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
size_t size);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
void p11_buffer_init_full (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
void *data,
|
|
Packit Service |
3749ba |
size_t len,
|
|
Packit Service |
3749ba |
int flags,
|
|
Packit Service |
3749ba |
void * (* frealloc) (void *, size_t),
|
|
Packit Service |
3749ba |
void (* ffree) (void *));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
void p11_buffer_uninit (p11_buffer *buffer);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
void * p11_buffer_steal (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
size_t *length);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
bool p11_buffer_reset (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
size_t size);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
void * p11_buffer_append (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
size_t length);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
void p11_buffer_add (p11_buffer *buffer,
|
|
Packit Service |
3749ba |
const void *data,
|
|
Packit Service |
3749ba |
ssize_t length);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#define p11_buffer_fail(buf) \
|
|
Packit Service |
3749ba |
((buf)->flags |= P11_BUFFER_FAILED)
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#define p11_buffer_ok(buf) \
|
|
Packit Service |
3749ba |
(((buf)->flags & P11_BUFFER_FAILED) ? false : true)
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#define p11_buffer_failed(buf) \
|
|
Packit Service |
3749ba |
(((buf)->flags & P11_BUFFER_FAILED) ? true : false)
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#endif /* BUFFER_H */
|