Skip to content

Commit

Permalink
修复apps/filereader的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Jan 23, 2025
1 parent f3dd64c commit 36373e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions apps/filereader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ int main(int argc, const char **argv) {
printf("Usage: %s filename\n", argv[0]);
return 1;
}
size_t size = __syscall(SYSCALL_FILE_SIZE, argv[1]);
byte *buf = (byte *)xmalloc(size);
__syscall(SYSCALL_LOAD_FILE, argv[1], buf, size);
isize size = __syscall(SYSCALL_FILE_SIZE, argv[1]);
if (size < 0) {
printf("File not found: %s\n", argv[1]);
return 1;
}
byte *buf = (byte *)xmalloc(size);
if (__syscall(SYSCALL_LOAD_FILE, argv[1], buf, size) < 0) {
printf("Failed to load file: %s\n", argv[1]);
free(buf);
return 1;
}
printf("\033[1;35mHEX DUMP\033[0m ");
for (usize j = 0; j < 16; j++) {
printf("\033[1;37m%02x\033[0m ", j);
Expand All @@ -30,10 +38,11 @@ int main(int argc, const char **argv) {
printf(" ");
for (usize j = 0; j < 16; j++) {
if (i + j >= size) break;
if (isprint(buf[i + j]))
if (isprint(buf[i + j])) {
printf("\033[1;32m%c\033[0m", buf[i + j]);
else
} else {
printf("\033[1;30m.\033[0m");
}
}
printf("\n");
}
Expand Down
1 change: 1 addition & 0 deletions include/data-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern "C" {
#include "data-structure/sorted-map/rbtree-strptr.h"
#include "data-structure/sorted-map/rbtree.h"
#include "data-structure/sorted-map/trie.h"
#include "data-structure/unordered-map/st.h"
#ifdef __cplusplus
}
#endif

0 comments on commit 36373e0

Please sign in to comment.