[9] | 1 | #include "sysincludes.h"
|
---|
| 2 | #include "msdos.h"
|
---|
| 3 | #include "stream.h"
|
---|
| 4 |
|
---|
| 5 | int batchmode = 0;
|
---|
| 6 |
|
---|
| 7 | int flush_stream(Stream_t *Stream)
|
---|
| 8 | {
|
---|
| 9 | int ret=0;
|
---|
| 10 | if(!batchmode) {
|
---|
| 11 | if(Stream->Class->flush)
|
---|
| 12 | ret |= Stream->Class->flush(Stream);
|
---|
| 13 | if(Stream->Next)
|
---|
| 14 | ret |= flush_stream(Stream->Next);
|
---|
| 15 | }
|
---|
| 16 | return ret;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | Stream_t *copy_stream(Stream_t *Stream)
|
---|
| 20 | {
|
---|
| 21 | if(Stream)
|
---|
| 22 | Stream->refs++;
|
---|
| 23 | return Stream;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | int free_stream(Stream_t **Stream)
|
---|
| 27 | {
|
---|
| 28 | int ret=0;
|
---|
| 29 |
|
---|
| 30 | if(!*Stream)
|
---|
| 31 | return -1;
|
---|
| 32 | if(! --(*Stream)->refs){
|
---|
| 33 | if((*Stream)->Class->flush)
|
---|
| 34 | ret |= (*Stream)->Class->flush(*Stream);
|
---|
| 35 | if((*Stream)->Class->freeFunc)
|
---|
| 36 | ret |= (*Stream)->Class->freeFunc(*Stream);
|
---|
| 37 | if((*Stream)->Next)
|
---|
| 38 | ret |= free_stream(&(*Stream)->Next);
|
---|
| 39 | Free(*Stream);
|
---|
| 40 | } else if ( (*Stream)->Next )
|
---|
| 41 | ret |= flush_stream((*Stream)->Next);
|
---|
| 42 | *Stream = NULL;
|
---|
| 43 | return ret;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | #define GET_DATA(stream, date, size, type, address) \
|
---|
| 48 | (stream)->Class->get_data( (stream), (date), (size), (type), (address) )
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | int get_data_pass_through(Stream_t *Stream, time_t *date, mt_size_t *size,
|
---|
| 52 | int *type, int *address)
|
---|
| 53 | {
|
---|
| 54 | return GET_DATA(Stream->Next, date, size, type, address);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | int read_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
|
---|
| 58 | {
|
---|
| 59 | return READS(Stream->Next, buf, start, len);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | int write_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
|
---|
| 63 | {
|
---|
| 64 | return WRITES(Stream->Next, buf, start, len);
|
---|
| 65 | }
|
---|