feat: example for copy
This commit is contained in:
parent
66dc722e13
commit
486a279270
1 changed files with 10 additions and 2 deletions
12
examples/cache/src/main.c
vendored
12
examples/cache/src/main.c
vendored
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue