You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
990 B
51 lines
990 B
#include "src/lib/syscall.h"
|
|
#include "src/lib/util.h"
|
|
#include "src/user/syscall.h"
|
|
|
|
#define BLOCK_SIZE 256
|
|
|
|
exit_code_t ls(const char *path) {
|
|
uint64_t fd = open(path, OPEN_DIRECTORY);
|
|
|
|
if (fd == (uint64_t)-1) {
|
|
ERR_S("ls: path does not exist\n");
|
|
return EXIT_CODE_GENERAL_FAILURE;
|
|
}
|
|
|
|
char buffer[BLOCK_SIZE];
|
|
uint64_t bytes;
|
|
while ((bytes = read(fd, BLOCK_SIZE, buffer))) {
|
|
if (bytes == (uint64_t)-1) {
|
|
ERR_S("ls: could not read directory\n");
|
|
close(fd);
|
|
return EXIT_CODE_GENERAL_FAILURE;
|
|
}
|
|
write(STDOUT, buffer, bytes);
|
|
OUT_S("\n");
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
}
|
|
|
|
exit_code_t main(uint64_t argc, const char **argv) {
|
|
if (argc == 1) {
|
|
return ls(".");
|
|
}
|
|
|
|
exit_code_t code = EXIT_CODE_OK;
|
|
for (uint64_t i = 1; i < argc; i++) {
|
|
if (argc > 2) {
|
|
OUT_S("\n");
|
|
OUT_D(argv[i]);
|
|
OUT_S(":\n");
|
|
}
|
|
exit_code_t c = ls(argv[i]);
|
|
if (c != EXIT_CODE_OK) {
|
|
code = c;
|
|
}
|
|
}
|
|
|
|
return code;
|
|
}
|
|
|