[hackers] [sbase] Implement -i support for ls || sin

From: <git_AT_suckless.org>
Date: Sat, 05 Oct 2013 16:29:30 +0200

commit 8c87c200540547202e25342765a8fd4250125469
Author: sin <sin_AT_2f30.org>
Date: Fri Sep 27 15:32:50 2013 +0100

    Implement -i support for ls

diff --git a/ls.1 b/ls.1
index 00ae32b..eb0b015 100644
--- a/ls.1
+++ b/ls.1
_AT_@ -3,7 +3,7 @@
 ls \- list directory contents
 .SH SYNOPSIS
 .B ls
-.RB [ \-adltU ]
+.RB [ \-adiltU ]
 .RI [ file ...]
 .SH DESCRIPTION
 .B ls
_AT_@ -17,6 +17,9 @@ shows hidden files (those beginning with '.').
 .B \-d
 lists directories themselves, not their contents.
 .TP
+.B \-i
+print the index number of each file.
+.TP
 .B \-l
 lists detailed information about each file, including their type, permissions,
 links, owner, group, size, and modification time.
diff --git a/ls.c b/ls.c
index e3a440f..98b4c3c 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -20,6 +20,7 @@ typedef struct {
         gid_t gid;
         off_t size;
         time_t mtime;
+ ino_t ino;
 } Entry;
 
 static int entcmp(const void *, const void *);
_AT_@ -30,6 +31,7 @@ static void output(Entry *);
 
 static bool aflag = false;
 static bool dflag = false;
+static bool iflag = false;
 static bool lflag = false;
 static bool tflag = false;
 static bool Uflag = false;
_AT_@ -39,7 +41,7 @@ static bool many;
 static void
 usage(void)
 {
- eprintf("usage: %s [-adltU] [FILE...]
", argv0);
+ eprintf("usage: %s [-adiltU] [FILE...]
", argv0);
 }
 
 int
_AT_@ -55,6 +57,9 @@ main(int argc, char *argv[])
         case 'd':
                 dflag = true;
                 break;
+ case 'i':
+ iflag = true;
+ break;
         case 'l':
                 lflag = true;
                 break;
_AT_@ -131,7 +136,7 @@ lsdir(const char *path)
                 if(d->d_name[0] == '.' && !aflag)
                         continue;
                 if(Uflag){
- mkent(&ent, d->d_name, lflag);
+ mkent(&ent, d->d_name, lflag || iflag);
                         output(&ent);
                 } else {
                         if(!(ents = realloc(ents, ++n * sizeof *ents)))
_AT_@ -139,7 +144,7 @@ lsdir(const char *path)
                         if(!(p = malloc((sz = strlen(d->d_name)+1))))
                                 eprintf("malloc:");
                         memcpy(p, d->d_name, sz);
- mkent(&ents[n-1], p, tflag || lflag);
+ mkent(&ents[n-1], p, tflag || lflag || iflag);
                 }
         }
         closedir(dp);
_AT_@ -172,6 +177,7 @@ mkent(Entry *ent, char *path, bool dostat)
         ent->gid = st.st_gid;
         ent->size = st.st_size;
         ent->mtime = st.st_mtime;
+ ent->ino = st.st_ino;
 }
 
 void
_AT_@ -183,6 +189,8 @@ output(Entry *ent)
         struct group *gr;
         struct passwd *pw;
 
+ if (iflag)
+ printf("%lu ", (unsigned long)ent->ino);
         if(!lflag) {
                 puts(ent->name);
                 return;
Received on Sat Oct 05 2013 - 16:29:30 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 05 2013 - 16:36:37 CEST