fix(fs): resolve temporary directory and handle errors correctly
This commit is contained in:
parent
80fc29a8d3
commit
66dc722e13
2 changed files with 48 additions and 30 deletions
23
examples/cache/src/main.c
vendored
23
examples/cache/src/main.c
vendored
|
|
@ -1,12 +1,25 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <linux/limits.h>
|
||||
#include <limits.h>
|
||||
#include "onus/fs.h"
|
||||
|
||||
int main() {
|
||||
char tmp[PATH_MAX];
|
||||
int status = onus_fs_make_tmp(tmp, sizeof(tmp), NULL);
|
||||
printf("Got status: %d. Path: %s\n", status, tmp);
|
||||
// onus_fs_del_tmp(tmp);
|
||||
char tmp[PATH_MAX], tmpfile[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);
|
||||
|
||||
/* TODO: Unsafe code */
|
||||
sprintf(tmpfile, "%s/test.txt", tmp);
|
||||
f = fopen(tmpfile, "w");
|
||||
printf("fopen: %d\n", f ? 0 : errno);
|
||||
if (f) fclose(f);
|
||||
|
||||
status = onus_fs_del_tmp(tmp);
|
||||
printf("onus_fs_del_tmp: %d\n", status);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue