| 1497 | #include <fcntl.h> |
| 1498 | |
| 1499 | static int stream_copy_file(const char *src, const char *dst) { |
| 1500 | FILE *in = cbm_fopen(src, "rb"); |
| 1501 | if (!in) { |
| 1502 | return CBM_NOT_FOUND; |
| 1503 | } |
| 1504 | FILE *out = cbm_fopen(dst, "wb"); |
| 1505 | if (!out) { |
| 1506 | (void)fclose(in); |
| 1507 | return CBM_NOT_FOUND; |
| 1508 | } |
| 1509 | char buf[CBM_SZ_64K]; |
| 1510 | size_t n; |
| 1511 | int rc = 0; |
| 1512 | while ((n = fread(buf, 1, sizeof(buf), in)) > 0) { |
| 1513 | if (fwrite(buf, 1, n, out) != n) { |
| 1514 | rc = CBM_NOT_FOUND; |
| 1515 | break; |
| 1516 | } |
| 1517 | } |
| 1518 | if (ferror(in)) { |
| 1519 | rc = CBM_NOT_FOUND; |
| 1520 | } |
| 1521 | (void)fclose(in); |
| 1522 | if (fclose(out) != 0) { |
| 1523 | rc = CBM_NOT_FOUND; |
| 1524 | } |
| 1525 | if (rc != 0) { |
| 1526 | (void)cbm_unlink(dst); |
| 1527 | } |
| 1528 | return rc; |
| 1529 | } |
| 1530 | |
| 1531 | int cbm_clone_or_copy_file(const char *src, const char *dst) { |
| 1532 | if (!src || !dst) { |
no test coverage detected