/[public]/psiconv/trunk/lib/psiconv/buffer.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (show annotations)
Mon Dec 25 22:25:33 2000 UTC (18 years, 8 months ago) by frodo
File MIME type: text/plain
File size: 2330 byte(s)
(Frodo) Added a complete buffer abstraction

1 /*
2 buffer.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #include "config.h"
22 #include "compat.h"
23
24 #include <stdlib.h>
25
26 #include "list.h"
27 #include "error.h"
28 #include "buffer.h"
29
30 struct psiconv_buffer_s {
31 psiconv_u32 base_offset;
32 psiconv_list data;
33 };
34
35 psiconv_buffer psiconv_buffer_new(psiconv_u32 base_offset)
36 {
37 psiconv_buffer buf;
38 if (!(buf = malloc(sizeof(*buf))))
39 return NULL;
40 if (!(buf->data = psiconv_list_new(sizeof(psiconv_u8)))) {
41 free(buf);
42 return NULL;
43 }
44 buf->base_offset = base_offset;
45 return buf;
46 }
47
48 void psiconv_buffer_free(psiconv_buffer buf)
49 {
50 psiconv_list_free(buf->data);
51 free(buf);
52 }
53
54 psiconv_u32 psiconv_buffer_base_offset(const psiconv_buffer buf)
55 {
56 return buf->base_offset;
57 }
58
59 psiconv_u32 psiconv_buffer_length(const psiconv_buffer buf)
60 {
61 return psiconv_list_length(buf->data);
62 }
63
64
65 psiconv_u8 *psiconv_buffer_get(const psiconv_buffer buf, psiconv_u32 off)
66 {
67 return psiconv_list_get(buf->data,off);
68 }
69
70 int psiconv_buffer_add(psiconv_buffer buf,psiconv_u8 data)
71 {
72 return psiconv_list_add(buf->data,&data);
73 }
74
75 size_t psiconv_buffer_fread(psiconv_buffer buf,size_t size, FILE *f)
76 {
77 return psiconv_list_fread(buf->data,size,f);
78 }
79
80 int psiconv_buffer_fread_all(psiconv_buffer buf, FILE *f)
81 {
82 return psiconv_list_fread_all(buf->data,f);
83 }
84
85 int psiconv_buffer_fwrite_all(const psiconv_buffer buf, FILE *f)
86 {
87 return psiconv_list_fwrite_all(buf->data,f);
88 }
89
90 int psiconv_buffer_concat(psiconv_buffer buf, const psiconv_buffer extra)
91 {
92 return psiconv_list_concat(buf->data,extra->data);
93 }

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26