From: Laurent Mazet Date: Thu, 23 Jan 2025 23:03:31 +0000 (+0100) Subject: display link target X-Git-Tag: v1.0~9 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=a04362d7b3d7726b8e2764fa96669238c2e651fa;p=fm.git display link target --- diff --git a/fm.c b/fm.c index ffa61d6..f717a55 100644 --- 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; diff --git a/function.c b/function.c index 8a7ee41..adfb09a 100644 --- a/function.c +++ b/function.c @@ -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 c5ff5a0..95d6343 100644 --- 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;