feat: example for copy

This commit is contained in:
maelstrom 2026-05-22 09:42:27 +02:00
commit 486a279270

View file

@ -3,21 +3,29 @@
#include <stdio.h>
#include <stddef.h>
#include <limits.h>
#include <unistd.h>
#include "onus/err.h"
#include "onus/fs.h"
int main() {
char tmp[PATH_MAX], tmpfile[PATH_MAX];
char tmp[PATH_MAX], tmpfile[PATH_MAX], dest[PATH_MAX];
FILE *f;
int status;
status = onus_fs_make_tmp(tmp, sizeof(tmp), NULL);
printf("onus_fs_make_tmp: %d. Path: %s\n", status, tmp);
if (status != ONUS_SUCCESS) return -1;
/* TODO: Unsafe code */
sprintf(tmpfile, "%s/test.txt", tmp);
f = fopen(tmpfile, "w");
printf("fopen: %d\n", f ? 0 : errno);
if (f) fclose(f);
sprintf(dest, "%s/target.txt", tmp);
status = onus_fs_copy_file(tmpfile, dest);
printf("onus_fs_copy_file: %d\n", status);
printf("file exists: %d\n", !access(dest, 0));
status = onus_fs_del_tmp(tmp);
printf("onus_fs_del_tmp: %d\n", status);