--- ls.1 | 3 +++ ls.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ls.1 b/ls.1 index 00ae32b..f10c929 100644 --- a/ls.1 +++ b/ls.1 _AT_@ -21,6 +21,9 @@ lists directories themselves, not their contents. lists detailed information about each file, including their type, permissions, links, owner, group, size, and modification time. .TP +.B \-r +reverses the sort order. +.TP .B \-t sorts files by modification time instead of by name. .TP diff --git a/ls.c b/ls.c index f61d7c5..db8742c 100644 --- a/ls.c +++ b/ls.c _AT_@ -33,6 +33,7 @@ static bool dflag = false; static bool lflag = false; static bool tflag = false; static bool Uflag = false; +static int sortorder = 1; static bool first = true; static bool many; _AT_@ -58,6 +59,9 @@ main(int argc, char *argv[]) case 'l': lflag = true; break; + case 'r': + sortorder = -1; + break; case 't': tflag = true; break; _AT_@ -89,9 +93,9 @@ entcmp(const void *va, const void *vb) const Entry *a = va, *b = vb; if(tflag) - return b->mtime - a->mtime; + return sortorder * (b->mtime - a->mtime); else - return strcmp(a->name, b->name); + return sortorder * (strcmp(a->name, b->name)); } void -- 1.8.2Received on Thu Oct 03 2013 - 18:42:08 CEST
This archive was generated by hypermail 2.3.0 : Thu Oct 03 2013 - 18:48:07 CEST