source: trunk/minix/commands/i386/mtools-3.9.7/file_read.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 641 bytes
RevLine 
[9]1#include "sysincludes.h"
2#include "msdos.h"
3#include "mtools.h"
4#include "file.h"
5
6/*
7 * Read the clusters given the beginning FAT entry. Returns 0 on success.
8 */
9
10int file_read(FILE *fp, Stream_t *Source, int textmode, int stripmode)
11{
12 char buffer[16384];
13 int pos;
14 int ret;
15
16 if (!Source){
17 fprintf(stderr,"Couldn't open source file\n");
18 return -1;
19 }
20
21 pos = 0;
22 while(1){
23 ret = Source->Class->read(Source, buffer, (mt_off_t) pos, 16384);
24 if (ret < 0 ){
25 perror("file read");
26 return -1;
27 }
28 if ( ret == 0)
29 break;
30 if(!fwrite(buffer, 1, ret, fp)){
31 perror("write");
32 return -1;
33 }
34 pos += ret;
35 }
36 return 0;
37}
Note: See TracBrowser for help on using the repository browser.