Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | * Force I/O to be done to complete transfer length
|
---|
| 3 | *
|
---|
| 4 | * written by:
|
---|
| 5 | *
|
---|
| 6 | * Alain L. Knaff
|
---|
| 7 | * alain@linux.lu
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include "sysincludes.h"
|
---|
| 12 | #include "msdos.h"
|
---|
| 13 | #include "stream.h"
|
---|
| 14 |
|
---|
| 15 | static int force_io(Stream_t *Stream,
|
---|
| 16 | char *buf, mt_off_t start, size_t len,
|
---|
| 17 | int (*io)(Stream_t *, char *, mt_off_t, size_t))
|
---|
| 18 | {
|
---|
| 19 | int ret;
|
---|
| 20 | int done=0;
|
---|
| 21 |
|
---|
| 22 | while(len){
|
---|
| 23 | ret = io(Stream, buf, start, len);
|
---|
| 24 | if ( ret <= 0 ){
|
---|
| 25 | if (done)
|
---|
| 26 | return done;
|
---|
| 27 | else
|
---|
| 28 | return ret;
|
---|
| 29 | }
|
---|
| 30 | start += ret;
|
---|
| 31 | done += ret;
|
---|
| 32 | len -= ret;
|
---|
| 33 | buf += ret;
|
---|
| 34 | }
|
---|
| 35 | return done;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | int force_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
|
---|
| 39 | {
|
---|
| 40 | return force_io(Stream, buf, start, len,
|
---|
| 41 | Stream->Class->write);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | int force_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len)
|
---|
| 45 | {
|
---|
| 46 | return force_io(Stream, buf, start, len,
|
---|
| 47 | Stream->Class->read);
|
---|
| 48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.