Added .o -> .sys rule to simplify driver makefiles
[reactos.git] / reactos / rcopy.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 char* convert_path(char* origpath)
6 {
7 char* newpath;
8 int i;
9
10 newpath = strdup(origpath);
11
12 i = 0;
13 while (newpath[i] != 0)
14 {
15 #ifdef UNIX_PATHS
16 if (newpath[i] == '\\')
17 {
18 newpath[i] = '/';
19 }
20 #else
21 #ifdef DOS_PATHS
22 if (newpath[i] == '/');
23 {
24 newpath[i] = '\\';
25 }
26 #endif
27 #endif
28 i++;
29 }
30 return(newpath);
31 }
32
33 #define TRANSFER_SIZE (65536)
34
35 int main(int argc, char* argv[])
36 {
37 char* path1;
38 char* path2;
39 FILE* in;
40 FILE* out;
41 char* buf;
42 int n_in;
43 int n_out;
44
45 if (argc != 3)
46 {
47 fprintf(stderr, "Too many arguments\n");
48 exit(1);
49 }
50
51 path1 = convert_path(argv[1]);
52 path2 = convert_path(argv[2]);
53
54 in = fopen(path1, "rb");
55 if (in == NULL)
56 {
57 perror("Cannot open input file");
58 exit(1);
59 }
60
61
62
63 out = fopen(path2, "wb");
64 if (out == NULL)
65 {
66 perror("Cannot open output file");
67 fclose(in);
68 exit(1);
69 }
70
71 buf = malloc(TRANSFER_SIZE);
72
73 while (!feof(in))
74 {
75 n_in = fread(buf, 1, TRANSFER_SIZE, in);
76 n_out = fwrite(buf, 1, n_in, out);
77 if (n_in != n_out)
78 {
79 perror("Failed to write to output file\n");
80 free(buf);
81 fclose(in);
82 fclose(out);
83 exit(1);
84 }
85 }
86 exit(0);
87 }