1*d5c9a868SElliott Hughes /* Copyright 1986-1992 Emmet P. Gray.
2*d5c9a868SElliott Hughes * Copyright 1996,1997,1999,2002,2009 Alain Knaff.
3*d5c9a868SElliott Hughes * This file is part of mtools.
4*d5c9a868SElliott Hughes *
5*d5c9a868SElliott Hughes * Mtools is free software: you can redistribute it and/or modify
6*d5c9a868SElliott Hughes * it under the terms of the GNU General Public License as published by
7*d5c9a868SElliott Hughes * the Free Software Foundation, either version 3 of the License, or
8*d5c9a868SElliott Hughes * (at your option) any later version.
9*d5c9a868SElliott Hughes *
10*d5c9a868SElliott Hughes * Mtools is distributed in the hope that it will be useful,
11*d5c9a868SElliott Hughes * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*d5c9a868SElliott Hughes * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*d5c9a868SElliott Hughes * GNU General Public License for more details.
14*d5c9a868SElliott Hughes *
15*d5c9a868SElliott Hughes * You should have received a copy of the GNU General Public License
16*d5c9a868SElliott Hughes * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
17*d5c9a868SElliott Hughes */
18*d5c9a868SElliott Hughes
19*d5c9a868SElliott Hughes #include "sysincludes.h"
20*d5c9a868SElliott Hughes #include "msdos.h"
21*d5c9a868SElliott Hughes #include "mtools.h"
22*d5c9a868SElliott Hughes #include "file.h"
23*d5c9a868SElliott Hughes
24*d5c9a868SElliott Hughes /*
25*d5c9a868SElliott Hughes * Read the clusters given the beginning FAT entry. Returns 0 on success.
26*d5c9a868SElliott Hughes */
27*d5c9a868SElliott Hughes
file_read(FILE * fp,Stream_t * Source,int textmode,int stripmode)28*d5c9a868SElliott Hughes int file_read(FILE *fp, Stream_t *Source, int textmode, int stripmode)
29*d5c9a868SElliott Hughes {
30*d5c9a868SElliott Hughes char buffer[16384];
31*d5c9a868SElliott Hughes int pos;
32*d5c9a868SElliott Hughes int ret;
33*d5c9a868SElliott Hughes
34*d5c9a868SElliott Hughes if (!Source){
35*d5c9a868SElliott Hughes fprintf(stderr,"Couldn't open source file\n");
36*d5c9a868SElliott Hughes return -1;
37*d5c9a868SElliott Hughes }
38*d5c9a868SElliott Hughes
39*d5c9a868SElliott Hughes pos = 0;
40*d5c9a868SElliott Hughes while(1){
41*d5c9a868SElliott Hughes ret = Source->Class->read(Source, buffer, pos, 16384);
42*d5c9a868SElliott Hughes if (ret < 0 ){
43*d5c9a868SElliott Hughes perror("file read");
44*d5c9a868SElliott Hughes return -1;
45*d5c9a868SElliott Hughes }
46*d5c9a868SElliott Hughes if ( ret == 0)
47*d5c9a868SElliott Hughes break;
48*d5c9a868SElliott Hughes if(!fwrite(buffer, 1, ret, fp)){
49*d5c9a868SElliott Hughes perror("write");
50*d5c9a868SElliott Hughes return -1;
51*d5c9a868SElliott Hughes }
52*d5c9a868SElliott Hughes pos += ret;
53*d5c9a868SElliott Hughes }
54*d5c9a868SElliott Hughes return 0;
55*d5c9a868SElliott Hughes }
56