commit a97b9c6c4884c84aa31216779336b289af1b4cbd
parent 4aab5d90ec47ab29ac7c9ac5d8218c1a1723f7e2
Author: phoebos <ben@bvnf.space>
Date: Tue, 12 Oct 2021 11:25:00 +0100
ls: add -i
Diffstat:
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/PROGRESS b/PROGRESS
@@ -22,7 +22,7 @@
[ ] id
[ ] kill
[ ] ln
-[ ] ls [-1AFap]
+[ ] ls [-1AFaip]
[ ] mkdir
[ ] more
[ ] mv
diff --git a/ls.c b/ls.c
@@ -12,17 +12,22 @@ enum {
FLAG_A = 1 << 1,
FLAG_F = 1 << 2,
FLAG_a = 1 << 3,
- FLAG_l = 1 << 4,
- FLAG_p = 1 << 5,
+ FLAG_i = 1 << 4,
+ FLAG_l = 1 << 5,
+ FLAG_p = 1 << 6,
};
struct ent {
const char *name;
+ ino_t ino;
mode_t mode;
};
int
printname(struct ent *e, int flags) {
+ if (flags & FLAG_i)
+ printf("%lu ", e->ino);
+
printf("%s", e->name);
char s = 0;
@@ -85,6 +90,7 @@ ls(const char *path, int flags) {
}
struct ent e = {
dp[i]->d_name,
+ stt.st_ino,
stt.st_mode,
};
@@ -105,7 +111,7 @@ main(int argc, char **argv) {
int c, flags, ret_val;
flags = ret_val = 0;
- while ((c = getopt(argc, argv, "1AFahlp")) != -1) {
+ while ((c = getopt(argc, argv, "1AFahilp")) != -1) {
switch (c) {
case '1':
flags |= FLAG_1;
@@ -120,8 +126,11 @@ main(int argc, char **argv) {
flags |= FLAG_a;
break;
case 'h':
- printf("usage: %s [-1AFalp]\n", argv[0]);
+ printf("usage: %s [-1AFailp]\n", argv[0]);
return 0;
+ case 'i':
+ flags |= FLAG_i;
+ break;
case 'l':
flags |= FLAG_l | FLAG_1;
break;