| 249 | #define COPYSIZE 4096 |
| 250 | |
| 251 | char *CopyFile(const char *from, const char *to) |
| 252 | { |
| 253 | BPTR fromFile, toFile; |
| 254 | char *buffer; |
| 255 | long size; |
| 256 | char *error = NULL; |
| 257 | |
| 258 | buffer = (char *) alloc(COPYSIZE); |
| 259 | if (fromFile = Open( (char *)from, MODE_OLDFILE)) { |
| 260 | if (toFile = Open( (char *)to, MODE_NEWFILE)) { |
| 261 | while (size = Read(fromFile, buffer, (long)COPYSIZE)) { |
| 262 | if (size == -1){ |
| 263 | error = "Read error"; |
| 264 | break; |
| 265 | } |
| 266 | if (size != Write(toFile, buffer, size)) { |
| 267 | error = "Write error"; |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | Close(toFile); |
| 272 | } else |
| 273 | error = "Cannot open destination"; |
| 274 | Close(fromFile); |
| 275 | } else |
| 276 | error = "Cannot open source (this should not occur)"; |
| 277 | free(buffer); |
| 278 | return error; |
| 279 | } |
| 280 | #endif |
| 281 | |
| 282 | #ifdef MFLOPPY |