source: trunk/minix/commands/i386/mtools-3.9.7/copyfile.c@ 11

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

Minix 3.1.2a

File size: 1.1 KB
Line 
1#include "sysincludes.h"
2#include "msdos.h"
3#include "mtools.h"
4#include "file.h"
5#include "llong.h"
6
7/*
8 * Copy the data from source to target
9 */
10
11int copyfile(Stream_t *Source, Stream_t *Target)
12{
13 char buffer[8*16384];
14 int pos;
15 int ret, retw;
16 size_t len;
17 mt_size_t mt_len;
18
19 if (!Source){
20 fprintf(stderr,"Couldn't open source file\n");
21 return -1;
22 }
23
24 if (!Target){
25 fprintf(stderr,"Couldn't open target file\n");
26 return -1;
27 }
28
29 pos = 0;
30 GET_DATA(Source, 0, &mt_len, 0, 0);
31 if (mt_len & ~max_off_t_31) {
32 fprintf(stderr, "File too big\n");
33 return -1;
34 }
35 len = truncBytes32(mt_len);
36 while(1){
37 ret = READS(Source, buffer, (mt_off_t) pos, 8*16384);
38 if (ret < 0 ){
39 perror("file read");
40 return -1;
41 }
42 if(!ret)
43 break;
44 if(got_signal)
45 return -1;
46 if (ret == 0)
47 break;
48 if ((retw = force_write(Target, buffer, (mt_off_t) pos, ret)) != ret){
49 if(retw < 0 )
50 perror("write in copy");
51 else
52 fprintf(stderr,
53 "Short write %d instead of %d\n", retw,
54 ret);
55 if(errno == ENOSPC)
56 got_signal = 1;
57 return ret;
58 }
59 pos += ret;
60 }
61 return pos;
62}
Note: See TracBrowser for help on using the repository browser.