| 2 | #include "file_copy.h" |
| 3 | |
| 4 | bool file_copy(const char* from, const char* to) |
| 5 | { |
| 6 | if (strcasecmp(from, to) == 0) |
| 7 | { |
| 8 | printf("from(%s) == to(%s)\r\n", from, to); |
| 9 | return false; |
| 10 | } |
| 11 | |
| 12 | ifstream in; |
| 13 | if (in.open_read(from) == false) |
| 14 | { |
| 15 | printf("open %s error: %s\r\n", from, last_serror()); |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | ofstream out; |
| 20 | if (out.open_write(to) == false) |
| 21 | { |
| 22 | printf("open %s error: %s\r\n", from, last_serror()); |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | string buf; |
| 27 | |
| 28 | while (!in.eof()) |
| 29 | { |
| 30 | if (in.gets(buf, false) == false) |
| 31 | break; |
| 32 | if (out.write(buf) < 0) |
| 33 | { |
| 34 | printf("write to %s error: %s\r\n", to, last_serror()); |
| 35 | return false; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | printf("create %s ok\r\n", to); |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool files_copy(const char* name, const FILE_FROM_TO* tab, |
| 44 | const char* from_path, const char* to_path) |
no test coverage detected
searching dependent graphs…