MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / stream_copy_file

Function stream_copy_file

src/foundation/compat_fs.c:1499–1529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1497#include <fcntl.h>
1498
1499static 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
1531int cbm_clone_or_copy_file(const char *src, const char *dst) {
1532 if (!src || !dst) {

Callers 1

cbm_clone_or_copy_fileFunction · 0.85

Calls 4

cbm_fopenFunction · 0.85
freadFunction · 0.85
fwriteFunction · 0.85
cbm_unlinkFunction · 0.85

Tested by

no test coverage detected