parent
03b3ddac73
commit
968bb02aa8
@ -0,0 +1,43 @@ |
||||
#include "src/lib/string.h" |
||||
#include "src/user/syscall.h" |
||||
|
||||
#define WRITE_S(s) write(1, s, sizeof(s) - 1); |
||||
#define WRITE_D(s) write(1, s, string_length(s)); |
||||
|
||||
uint64_t ls(const char *path) { |
||||
uint64_t i = 0; |
||||
while (1) { |
||||
char out[100]; |
||||
uint64_t s = readdir(path, i, 100, out); |
||||
if (!s) { |
||||
return 0; |
||||
} |
||||
if (s == (uint64_t)-1) { |
||||
WRITE_S("ls: path does not exist\n"); |
||||
return (uint64_t)-1; |
||||
} |
||||
WRITE_D(out); |
||||
WRITE_S("\n"); |
||||
i++; |
||||
} |
||||
} |
||||
|
||||
uint64_t main(uint64_t argc, const char **argv) { |
||||
if (argc == 1) { |
||||
return ls("."); |
||||
} |
||||
|
||||
uint64_t code = 0; |
||||
for (uint64_t i = 1; i < argc; i++) { |
||||
if (argc > 2) { |
||||
WRITE_S("\n"); |
||||
WRITE_D(argv[i]); |
||||
WRITE_S(":\n"); |
||||
} |
||||
if (ls(argv[i]) == (uint64_t)-1) { |
||||
code = (uint64_t)-1; |
||||
} |
||||
} |
||||
|
||||
return code; |
||||
} |
||||
Loading…
Reference in new issue