Files
dat-thang/tests/test_paths.c
T
divorce b735900f2e 0.0.002
ddat interop with dat js
cable interop with cabal js
ddat's frontend = dat-thang
cable fe = cable-thang
dillo support based on cel's dillo-dat
bootstrap node
xplatform support

Signed-off-by: divo <418@cryspace.space>
2026-10-19 00:17:02 -04:00

43 lines
1.1 KiB
C

#include "dat_paths.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <process.h>
#define test_pid _getpid
#else
#include <unistd.h>
#define test_pid getpid
#endif
static void write_text(const char *path, const char *text)
{
FILE *file = fopen(path, "wb");
assert(file);
assert(fwrite(text, 1, strlen(text), file) == strlen(text));
assert(fclose(file) == 0);
}
int main(void)
{
char destination[256], temporary[256], contents[32];
FILE *file;
int n;
n = snprintf(destination, sizeof(destination), "build/test-paths-%ld", (long)test_pid());
assert(n > 0 && (size_t)n < sizeof(destination));
n = snprintf(temporary, sizeof(temporary), "%s.tmp", destination);
assert(n > 0 && (size_t)n < sizeof(temporary));
write_text(destination, "before");
write_text(temporary, "after");
assert(dat_replace_file(temporary, destination) == 0);
file = fopen(destination, "rb");
assert(file);
assert(fgets(contents, sizeof(contents), file));
assert(fclose(file) == 0);
assert(strcmp(contents, "after") == 0);
assert(remove(destination) == 0);
puts("user-state atomic replacement: PASS");
return 0;
}