Mercurial > msvpvf
comparison src/main.c @ 46:7cb9fad3f5ee
Patch a bug that would make files cap at 1.4 MB
seriously. wtf was i thinking?
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Fri, 20 May 2022 14:41:46 -0400 |
parents | d8ac17c6d6f2 |
children | 7cb4ca7cf257 |
comparison
equal
deleted
inserted
replaced
45:d8ac17c6d6f2 | 46:7cb9fad3f5ee |
---|---|
38 fputc(magic[i], target); | 38 fputc(magic[i], target); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 int copy_file(char* source_file, char* target_file) { | 42 int copy_file(char* source_file, char* target_file) { |
43 char ch; | |
43 FILE *source, *target; | 44 FILE *source, *target; |
44 | 45 |
45 source = fopen(source_file, "rb"); | 46 source = fopen(source_file, "rb"); |
46 | 47 |
47 if (source == NULL) return 1; | 48 if (source == NULL) |
49 return 1; | |
48 | 50 |
49 target = fopen(target_file, "wb"); | 51 target = fopen(target_file, "wb"); |
50 | 52 |
51 if (target == NULL) { | 53 if (target == NULL) { |
52 fclose(source); | 54 fclose(source); |
53 return 1; | 55 return 1; |
54 } | 56 } |
55 | 57 |
56 size_t n, m; | 58 while( ( ch = fgetc(source) ) != EOF ) |
57 unsigned char buff[8192]; | 59 fputc(ch, target); |
58 do { | |
59 n = fread(buff, 1, sizeof(buff), source); | |
60 if (n) m = fwrite(buff, 1, n, target); | |
61 else m = 0; | |
62 } while ((n > 0) && (n == m)); | |
63 | 60 |
64 fclose(target); | 61 fclose(target); |
65 fclose(source); | 62 fclose(source); |
66 return 0; | 63 return 0; |
67 } | 64 } |