summaryrefslogtreecommitdiff
path: root/src/user/dirlist/main.c
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-02-17 17:59:05 -0500
committerBenji Dial <benji6283@gmail.com>2021-02-17 17:59:05 -0500
commit79973061600a2af480c4f8ec1e1e71846985b653 (patch)
treef63a54b5116bd19e2f82b14261c65584d80407f5 /src/user/dirlist/main.c
parent302666775a00b1df398ca06b97aa481a6626045d (diff)
downloadportland-os-79973061600a2af480c4f8ec1e1e71846985b653.tar.gz
dirlist program, making fat refuse to list file as directory
Diffstat (limited to 'src/user/dirlist/main.c')
-rw-r--r--src/user/dirlist/main.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/user/dirlist/main.c b/src/user/dirlist/main.c
new file mode 100644
index 0000000..64f0ddb
--- /dev/null
+++ b/src/user/dirlist/main.c
@@ -0,0 +1,27 @@
+#include <libterm/terminal.h>
+#include <knob/block.h>
+#include <knob/file.h>
+
+#define MAX_NAME_LEN 15
+#define COLUMN_SEP " - "
+
+void main(const char *path) {
+ uint32_t count;
+ _dir_info_entry_t *entries = get_directory_info(path, &count);
+ if (!entries) {
+ term_addf("Could not list %s\n", path);
+ return;
+ }
+ term_addf("Directory listing for %s:\n\n", *path ? path : "(root)");
+ if (!count) {
+ term_add_sz("(empty)\n");
+ return;
+ }
+ for (_dir_info_entry_t *i = entries; i < entries + count; ++i) {
+ str_trunc_fill(i->name, MAX_NAME_LEN);
+ if (i->is_dir)
+ term_addf_no_ww("%s" COLUMN_SEP "directory\n", i->name);
+ else
+ term_addf_no_ww("%s" COLUMN_SEP "%u bytes\n", i->name, i->size);
+ }
+} \ No newline at end of file