-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
|
||
#include <kernel/uapi/uapi_syscall.h> | ||
|
||
extern int32_t syscall2(uint32_t eax, uint32_t ebx, uint32_t ecx); | ||
|
||
int rename(const char* old, const char* new) { | ||
return syscall2(SYS_RENAME, (uintptr_t) old, (uintptr_t) new); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
#define BUF_SIZE 512 | ||
|
||
bool cat(const char* path) { | ||
char buf[BUF_SIZE] = ""; | ||
FILE* f = fopen(path, "r"); | ||
|
||
if (!f) { | ||
return false; | ||
} | ||
|
||
while (true) { | ||
int read = fread(buf, 1, BUF_SIZE - 1, f); | ||
buf[read] = '\0'; | ||
|
||
printf("%s", buf); | ||
|
||
if (read < BUF_SIZE - 1) { | ||
break; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 2) { | ||
printf("usage: %s FILE...\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
for (int i = 1; i < argc; i++) { | ||
if (!cat(argv[i])) { | ||
printf("%s: failed to open '%s'\n", argv[0], argv[i]); | ||
return 2; | ||
} | ||
} | ||
|
||
return 0; | ||
} |