Hi ,

Please find attached my attempt at addressing TODO 1 in lsof.c

, that is related to measuring of the content.

i think toybox should do the same as the normal lsof does, adjust the content ?

please let me know in case this is wrong.

thanks

Haroon
From 6b53c3902cac3d02888d3e6f37c01021beb31717 Mon Sep 17 00:00:00 2001
From: Haroon Maqsood <maqsood3...@live.com>
Date: Thu, 29 Mar 2018 03:19:20 +0100
Subject: [PATCH] lsof TODO display fix attempt

---
 toys/pending/lsof.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/toys/pending/lsof.c b/toys/pending/lsof.c
index 2852f41..e24e450 100644
--- a/toys/pending/lsof.c
+++ b/toys/pending/lsof.c
@@ -46,6 +46,14 @@ struct file_info {
   ino_t st_ino;
 };
 
+static char * get_trimed_str (char * strFrom, int maxLen)
+{
+  if (strlen (strFrom) > maxLen)
+    return strndup (strFrom, maxLen);
+
+  return strFrom;
+}
+
 static void print_info(void *data)
 {
   struct file_info *fi = data;
@@ -66,16 +74,14 @@ static void print_info(void *data)
       printf("%d\n", TT.last_shown_pid = fi->pi.pid);
   } else {
     if (!TT.shown_header) {
-      // TODO: llist_traverse to measure the columns first.
-      printf("%-9s %5s %10.10s %4s   %7s %18s %9s %10s %s\n", "COMMAND", "PID",
+      printf("%-9s %5s %10.10s %4s %7s %18s %9s %10s %s\n", "COMMAND", "PID",
         "USER", "FD", "TYPE", "DEVICE", "SIZE/OFF", "NODE", "NAME");
       TT.shown_header = 1;
     }
-
-    printf("%-9s %5d %10.10s %4s%c%c %7s %18s %9s %10s %s\n",
-           fi->pi.cmd, fi->pi.pid, getusername(fi->pi.uid),
-           fi->fd, fi->rw, fi->locks, fi->type, fi->device, fi->size_off,
-           fi->node, fi->name);
+    printf("%-9s %5d %10.10s %4s %7s %18s %9s %10s %s\n",
+           get_trimed_str (fi->pi.cmd,9), fi->pi.pid, get_trimed_str (getusername(fi->pi.uid), 11),
+       get_trimed_str (fi->fd, 4), get_trimed_str (fi->type, 7), get_trimed_str(fi->device,18),
+       get_trimed_str(fi->size_off,9),get_trimed_str(fi->node, 10), fi->name);
   }
 }
 
-- 
2.7.4

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to