update pet for pet_transform_C_source
[ppcg.git] / rewrite.c
blob4f26003b6e66f0ddd07dc447575f6c9dc3785287
1 /*
2 * Copyright 2013 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
8 */
10 #include <assert.h>
12 #include "rewrite.h"
14 /* Copy the contents of "input" from offset "start" to "end" to "output".
16 void copy(FILE *input, FILE *output, long start, long end)
18 char buffer[1024];
19 size_t n, m;
21 if (end < 0) {
22 fseek(input, 0, SEEK_END);
23 end = ftell(input);
26 fseek(input, start, SEEK_SET);
28 while (start < end) {
29 n = end - start;
30 if (n > 1024)
31 n = 1024;
32 n = fread(buffer, 1, n, input);
33 assert(n > 0);
34 m = fwrite(buffer, 1, n, output);
35 assert(n == m);
36 start += n;