Skip to content

Commit d408c8a

Browse files
author
di
committed
[FS] write full file [PRINT] only print to stdout on redacted
1 parent 1d9d24b commit d408c8a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

shared/syscalls/syscalls.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ int print(const char *fmt, ...){
1212
va_end(args);
1313
if (n >= sizeof(log_buf)) log_buf[sizeof(log_buf)-1] = '\0';
1414
printl(log_buf);
15+
#ifndef CROSS
1516
file fd2 = { .id = 2 };
1617
writef(&fd2, log_buf, sizeof(log_buf));
18+
#endif
1719
return 0;
1820
}
1921

@@ -25,8 +27,10 @@ int printf(const char *fmt, ...){
2527
va_end(args);
2628
if (n >= sizeof(li)) li[sizeof(li)-1] = '\0';
2729
printl(li);
30+
#ifndef CROSS
2831
file fd2 = { .id = 2 };
2932
writef(&fd2, li, sizeof(li));
33+
#endif
3034
return 0;
3135
}
3236

@@ -76,7 +80,7 @@ void* zalloc(size_t size){
7680
char *read_full_file(const char *path){
7781

7882
file fd = {};
79-
openf(path, &fd);
83+
if (openf(path, &fd) != FS_RESULT_SUCCESS) return false;
8084
char *fcontent = (char*)malloc(fd.size + 1);
8185

8286
readf(&fd, fcontent, fd.size);
@@ -86,4 +90,15 @@ char *read_full_file(const char *path){
8690
return fcontent;
8791
}
8892

93+
bool write_full_file(const char *path, void* buf, size_t size){
94+
file fd = {};
95+
if (openf(path, &fd) != FS_RESULT_SUCCESS) return false;
96+
97+
size_t res = writef(&fd, buf, size);
98+
99+
closef(&fd);
100+
101+
return res > 0;
102+
}
103+
89104
#endif

shared/syscalls/syscalls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ sizedptr dir_list(const char *path);
6767
int print(const char *fmt, ...);
6868
char *read_full_file(const char *path);
6969

70+
bool write_full_file(const char *path, void* buf, size_t size);
71+
7072
static inline void yield(){
7173
msleep(0);
7274
}

0 commit comments

Comments
 (0)