[hackers] [sbase] Implement -u support for ls(1) || sin
commit 2a3f82a5cd9b6712b4e8d501d4f529ec8578c62f
Author: sin <sin_AT_2f30.org>
Date: Wed Feb 18 16:29:46 2015 +0000
Implement -u support for ls(1)
diff --git a/README b/README
index f8b92da..42f48d8 100644
--- a/README
+++ b/README
_AT_@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* ln yes none
=* logger yes none
=* logname yes none
-= ls no -C, -R, -u
+= ls no -C, -R
=* md5sum non-posix none
=* mkdir yes none
=* mkfifo yes none
diff --git a/ls.1 b/ls.1
index 7389350..5d8f1b2 100644
--- a/ls.1
+++ b/ls.1
_AT_@ -1,4 +1,4 @@
-.Dd February 17, 2015
+.Dd February 18, 2015
.Dt LS 1
.Os sbase
.Sh NAME
_AT_@ -6,7 +6,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
-.Op Fl 1acdFHhiLlqrtU
+.Op Fl 1acdFHhiLlqrtUu
.Op Ar file ...
.Sh DESCRIPTION
.Nm
_AT_@ -44,6 +44,9 @@ Reverse the sort order.
Sort files by last file status/modification time instead of by name.
.It Fl U
Keep the list unsorted.
+.It Fl u
+Use file's last access time instead of last modification time for
+sorting or printing.
.El
.Sh SEE ALSO
.Xr stat 2
diff --git a/ls.c b/ls.c
index ab9d4c3..bb249ed 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -37,6 +37,7 @@ static int qflag = 0;
static int rflag = 0;
static int tflag = 0;
static int Uflag = 0;
+static int uflag = 0;
static int first = 1;
static int many;
_AT_@ -55,7 +56,12 @@ mkent(struct entry *ent, char *path, int dostat, int follow)
ent->uid = st.st_uid;
ent->gid = st.st_gid;
ent->size = st.st_size;
- ent->t = cflag ? st.st_ctime : st.st_mtime;
+ if (cflag)
+ ent->t = st.st_ctime;
+ else if (uflag)
+ ent->t = st.st_atime;
+ else
+ ent->t = st.st_mtime;
ent->ino = st.st_ino;
if (S_ISLNK(ent->mode))
ent->tmode = stat(path, &st) == 0 ? st.st_mode : 0;
_AT_@ -247,7 +253,7 @@ ls(const struct entry *ent)
static void
usage(void)
{
- eprintf("usage: %s [-1acdFHhiLlqrtU] [file ...]\n", argv0);
+ eprintf("usage: %s [-1acdFHhiLlqrtUu] [file ...]\n", argv0);
}
int
_AT_@ -265,6 +271,7 @@ main(int argc, char *argv[])
break;
case 'c':
cflag = 1;
+ uflag = 0;
break;
case 'd':
dflag = 1;
_AT_@ -299,6 +306,10 @@ main(int argc, char *argv[])
case 'U':
Uflag = 1;
break;
+ case 'u':
+ uflag = 1;
+ cflag = 0;
+ break;
default:
usage();
} ARGEND;
Received on Tue Mar 24 2015 - 23:53:53 CET
This archive was generated by hypermail 2.3.0
: Wed Mar 25 2015 - 00:10:27 CET