mirror of
https://git.checksum.fail/alec/erythros
synced 2025-12-11 13:39:55 +02:00
System/Shell/Commands/cat: Handle FileSystem.PathExists()
This commit is contained in:
@@ -20,20 +20,31 @@ I64 @shell_cmd_cat(@shell* sh, I64 argc, U8** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
I64 i;
|
I64 i;
|
||||||
I64 j;
|
I64 j;
|
||||||
|
I64 res = 0;
|
||||||
I64 size = 0;
|
I64 size = 0;
|
||||||
U8* filename = NULL;
|
U8* filename = NULL;
|
||||||
U8* buf = NULL;
|
U8* buf = NULL;
|
||||||
|
U8 msg[512];
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (!MemCmp(argv[i], "http://", 7) || !MemCmp(argv[i], "https://", 8)) {
|
if (!MemCmp(argv[i], "http://", 7) || !MemCmp(argv[i], "https://", 8)) {
|
||||||
buf = @cat_buf_from_url_string(argv[i], &size);
|
buf = @cat_buf_from_url_string(argv[i], &size);
|
||||||
} else {
|
} else {
|
||||||
filename = @shell_expand_relative_path(sh, argv[i]);
|
filename = @shell_expand_relative_path(sh, argv[i]);
|
||||||
buf = FileSystem.ReadFile(filename, &size);
|
if (!FileSystem.PathExists(filename)) {
|
||||||
|
res = 2;
|
||||||
|
StrPrint(&msg, "cat: cannot access '%s': No such file or directory\n", filename);
|
||||||
|
Stdio.WriteLine(sh, &msg);
|
||||||
|
} else {
|
||||||
|
buf = FileSystem.ReadFile(filename, &size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buf) {
|
||||||
|
for (j = 0; j < size; j++) {
|
||||||
|
FifoU8Ins(sh->output, buf[j]);
|
||||||
|
}
|
||||||
|
Free(buf);
|
||||||
}
|
}
|
||||||
for (j = 0; j < size; j++)
|
|
||||||
FifoU8Ins(sh->output, buf[j]);
|
|
||||||
Free(buf);
|
|
||||||
Free(filename);
|
Free(filename);
|
||||||
}
|
}
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user