fix(fs): resolve temporary directory and handle errors correctly

This commit is contained in:
maelstrom 2026-05-22 09:36:56 +02:00
commit 66dc722e13
2 changed files with 48 additions and 30 deletions

View file

@ -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;
}