display link target
authorLaurent Mazet <mazet@softndesign.org>
Thu, 23 Jan 2025 23:03:31 +0000 (00:03 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 23 Jan 2025 23:03:31 +0000 (00:03 +0100)
fm.c
function.c
type.h

diff --git a/fm.c b/fm.c
index ffa61d69c1ea36c95eee991148ecbddd032d4bea..f717a55f419f57b5464c5cb104156aff0265fe88 100644 (file)
--- a/fm.c
+++ b/fm.c
@@ -21,7 +21,7 @@
 #define MAXPANELS 2
 #define MAXFILTER 32
 #define MAXFNAME 64
-#define MAXSTATUS 128
+#define MAXSTATUS 256
 
 /* static variables */
 char *progname = NULL;
index 8a7ee41a10e2308fd80432d81637cc1596472a5a..adfb09adcfb8a94825554cda0355b4e31a16716a 100644 (file)
@@ -21,6 +21,7 @@
 #include "function.h"
 
 #define BUFMAX 4096
+#define MAXLEN 256
 
 int strmaxlen (char *str, char ch)
 {
@@ -249,11 +250,8 @@ void getinfo (char *dirname, elem_t *elem)
 
     struct stat sb = {0};
     int error = (STAT (name, &sb) == -1);
-    free (name);
 
-#ifdef WIN32
-    elem->uid = strdup ("");
-#else /* Linux*/
+#ifndef WIN32
     if (!error) {
         struct passwd *pwd = getpwuid (sb.st_uid);
         if (pwd) {
@@ -267,9 +265,7 @@ void getinfo (char *dirname, elem_t *elem)
     }
 #endif
 
-#ifdef WIN32
-    elem->gid = strdup ("");
-#else /* Linux*/
+#ifndef WIN32
     if (!error) {
         struct group *grp = getgrgid (sb.st_gid);
         if (grp) {
@@ -283,6 +279,18 @@ void getinfo (char *dirname, elem_t *elem)
     }
 #endif
 
+#ifndef WIN32
+    if ((elem->type == type_symb_e) || (elem->type == type_ldir_e) || (elem->type == type_lreg_e) || (elem->type == type_erlk_e)) {
+        char lname[MAXLEN + 1] = {0};
+        int len = readlink (name, lname, MAXLEN);
+        if (len != -1) {
+            elem->link = strdup (lname);
+        }
+    }
+#endif
+
+    free (name);
+
     elem->nlk = sb.st_nlink;
 }
 
@@ -351,7 +359,10 @@ void createstatus (char *status, elem_t *elem)
         break;
     }
 
-    if (elem->uid && *elem->uid) {
+    if (elem->link) {
+        strcat (status, " -> ");
+        strcat (status, elem->link);
+    } else if (elem->uid && *elem->uid) {
         strcat (status, " ");
         strcat (status, elem->uid);
         strcat (status, "/");
@@ -364,6 +375,7 @@ void freelist (list_t *list)
     if (list) {
         while (list->nb--) {
             free ((list->tab + list->nb)->gid);
+            free ((list->tab + list->nb)->link);
             free ((list->tab + list->nb)->name);
             free ((list->tab + list->nb)->uid);
         }
diff --git a/type.h b/type.h
index c5ff5a05164d65c861706baaae3c5842973e4726..95d6343bed8f858c8906ee1e3928b1129baace0d 100644 (file)
--- a/type.h
+++ b/type.h
@@ -17,6 +17,7 @@ typedef enum {
 
 typedef struct {
     char *gid;
+    char *link;
     unsigned short mode;
     char *name;
     int nlk;