ls: add option to reverse the sort order

Now you can list directory contents ordered by mtime with the
latest file displayed last in the output.
This commit is contained in:
Markus Teich
2013-10-04 11:12:11 +01:00
committed by sin
parent 96c8c5f389
commit 3a3cd24092
2 changed files with 9 additions and 2 deletions

8
ls.c
View File

@@ -35,6 +35,7 @@ static bool iflag = false;
static bool lflag = false;
static bool tflag = false;
static bool Uflag = false;
static int sortorder = 1;
static bool first = true;
static bool many;
@@ -63,6 +64,9 @@ main(int argc, char *argv[])
case 'l':
lflag = true;
break;
case 'r':
sortorder = -1;
break;
case 't':
tflag = true;
break;
@@ -94,9 +98,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