commit 73104096d3cfadf6f5b91e6a397de08e132be65f
parent f4a7df89629ba48942f5abc89b388766f7cfe3f7
Author: phoebos <ben@bvnf.space>
Date: Tue, 12 Oct 2021 14:16:57 +0100
ls: -l prints size or device number
POSIX doesn't specify major(3) or minor(3), and the "device info" field in ls -l
is implementation-defined. So there's not a great, portable way to print the
major and minor IDs.
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/ls.c b/ls.c
@@ -27,6 +27,7 @@ struct ent {
uid_t uid;
gid_t gid;
off_t size;
+ dev_t rdev;
};
void
@@ -105,7 +106,13 @@ printname(struct ent *e, int flags) {
} else {
printf("%s ", grp->gr_name);
}
+
/* size (or device info for character/block special files) */
+ if (S_ISBLK(e->mode) || S_ISCHR(e->mode))
+ printf("%ld ", e->rdev);
+ else
+ printf("%ld ", e->size);
+
/* date and time */
}
@@ -177,6 +184,7 @@ ls(const char *path, int flags) {
stt.st_uid,
stt.st_gid,
stt.st_size,
+ stt.st_rdev,
};
printname(&e, flags);
@@ -193,6 +201,7 @@ ls(const char *path, int flags) {
.uid = st.st_uid,
.gid = st.st_gid,
.size = st.st_size,
+ .rdev = st.st_rdev,
};
printname(&e, flags);
}