]>
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 */
49 io_stream_memory::read (void *buffer
, size_t len
)
53 unsigned char *to
= (unsigned char *) buffer
;
54 unsigned char *end
= to
+ len
;
56 while (to
< end
&& pos
< length
)
58 *to
++ = pos_block
->data
[pos_block_offset
++];
60 if (pos_block_offset
== pos_block
->len
)
62 pos_block
= pos_block
->next
;
71 io_stream_memory::write (const void *buffer
, size_t len
)
75 /* talk about primitive :} */
76 tail
->next
= new memblock (len
);
77 if (!tail
->next
->data
)
85 memcpy (tail
->data
, buffer
, len
);
88 pos_block_offset
= len
;
94 io_stream_memory::peek (void *buffer
, size_t len
)
97 size_t toff
= pos_block_offset
;
98 memblock
*tblock
= pos_block
;
99 ssize_t tmp
= read (buffer
, len
);
101 pos_block_offset
= toff
;
107 io_stream_memory::error ()
This page took 0.038745 seconds and 5 git commands to generate.