1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* buffer.h - Generic data buffer, used by openssh, gnome-keyring
Copyright (C) 2007, 2012 Stefan Walter
Copyright (C) 2012 Red Hat Inc.
The Gnome Keyring Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Keyring Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Stef Walter <stef@thewalter.net>
*/
#ifndef P11_BUFFER_H_
#define P11_BUFFER_H_
#include "compat.h"
enum {
P11_BUFFER_FAILED = 1 << 0,
P11_BUFFER_NULL = 1 << 1,
};
typedef struct {
void *data;
size_t len;
int flags;
size_t size;
void * (* frealloc) (void *, size_t);
void (* ffree) (void *);
} p11_buffer;
bool p11_buffer_init (p11_buffer *buffer,
size_t size);
bool p11_buffer_init_null (p11_buffer *buffer,
size_t size);
void p11_buffer_init_full (p11_buffer *buffer,
void *data,
size_t len,
int flags,
void * (* frealloc) (void *, size_t),
void (* ffree) (void *));
void p11_buffer_uninit (p11_buffer *buffer);
void * p11_buffer_steal (p11_buffer *buffer,
size_t *length);
bool p11_buffer_reset (p11_buffer *buffer,
size_t size);
void * p11_buffer_append (p11_buffer *buffer,
size_t length);
void p11_buffer_add (p11_buffer *buffer,
const void *data,
ssize_t length);
#define p11_buffer_fail(buf) \
((buf)->flags |= P11_BUFFER_FAILED)
#define p11_buffer_ok(buf) \
(((buf)->flags & P11_BUFFER_FAILED) ? false : true)
#define p11_buffer_failed(buf) \
(((buf)->flags & P11_BUFFER_FAILED) ? true : false)
#endif /* BUFFER_H */
|