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

Function cbm_copy_file

src/cli/cli.c:1222–1256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1220/* ── File utilities ───────────────────────────────────────────── */
1221
1222int cbm_copy_file(const char *src, const char *dst) {
1223 FILE *in = fopen(src, "rb");
1224 if (!in) {
1225 return CLI_ERR;
1226 }
1227
1228 FILE *out = fopen(dst, "wb");
1229 if (!out) {
1230 (void)fclose(in);
1231 return CLI_ERR;
1232 }
1233
1234 char buf[CLI_BUF_8K];
1235 int err = 0;
1236 while (!feof(in) && !ferror(in)) {
1237 size_t n = fread(buf, CLI_ELEM_SIZE, sizeof(buf), in);
1238 if (n == 0) {
1239 break;
1240 }
1241 if (fwrite(buf, CLI_ELEM_SIZE, n, out) != n) {
1242 err = CLI_TRUE;
1243 break;
1244 }
1245 }
1246
1247 if (err || ferror(in)) {
1248 (void)fclose(in);
1249 (void)fclose(out);
1250 return CLI_ERR;
1251 }
1252
1253 (void)fclose(in);
1254 int rc = fclose(out);
1255 return rc == 0 ? 0 : CLI_ERR;
1256}
1257
1258/* Return true if two paths refer to the same on-disk file. Used to avoid
1259 * copying the running binary onto itself during install (cbm_copy_file would

Callers 3

test_cli.cFile · 0.85
test_httpd.cFile · 0.85

Calls 3

fopenFunction · 0.85
freadFunction · 0.85
fwriteFunction · 0.85

Tested by

no test coverage detected