]>
cygwin.com Git - cygwin-apps/setup.git/blob - io_stream_memory.cc
2 * Copyright (c) 2001, Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
17 static const char *cvsid
=
27 #include "io_stream.h"
28 #include "io_stream_memory.h"
30 /* memblock helper class */
31 memblock::~memblock ()
39 io_stream_memory::~io_stream_memory ()
41 /* memblocks are self deleting. Nice of 'em eh what */
48 io_stream_memory::read (void *buffer
, size_t len
)
52 unsigned char *to
= (unsigned char *) buffer
;
53 unsigned char *end
= to
+ len
;
55 while (to
< end
&& pos
< length
)
57 *to
++ = pos_block
->data
[pos_block_offset
++];
59 if (pos_block_offset
== pos_block
->len
)
61 pos_block
= pos_block
->next
;
70 io_stream_memory::write (const void *buffer
, size_t len
)
74 /* talk about primitive :} */
75 tail
->next
= new memblock (len
);
76 if (!tail
->next
->data
)
84 memcpy (tail
->data
, buffer
, len
);
87 pos_block_offset
= len
;
93 io_stream_memory::peek (void *buffer
, size_t len
)
96 size_t toff
= pos_block_offset
;
97 memblock
*tblock
= pos_block
;
98 ssize_t tmp
= read (buffer
, len
);
100 pos_block_offset
= toff
;
106 io_stream_memory::error ()
This page took 0.037176 seconds and 5 git commands to generate.