Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Globbing feature suggestion



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Urk.  Sorry about that; I don't actually *have* any files with unknown
> uid/gid on my system, but I had assumed "stat" would return the numeric
> ID in the absence of a name, the way "ls -l" does.
> 
> In fact I think it's pretty darn useless to return '???' for all unknown
> IDs, as if they were equivalent.  Would anyone seriously object if that
> were changed?

I don't see why not.  I think it was that way because you can get both (with
stat -rs).

Index: Src/Modules/stat.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/stat.c,v
retrieving revision 1.9
diff -u -r1.9 stat.c
--- Src/Modules/stat.c	2 Nov 2005 19:29:53 -0000	1.9
+++ Src/Modules/stat.c	15 Dec 2005 10:42:17 -0000
@@ -140,10 +140,16 @@
 #ifdef HAVE_GETPWUID
 	struct passwd *pwd;
 	pwd = getpwuid(uid);
-	strcat(outbuf, pwd ? pwd->pw_name : "???");
-#else /* !HAVE_GETPWUID */
-	strcat(outbuf, "???");
+	if (pwd)
+	    strcat(outbuf, pwd->pw_name);
+	else
 #endif /* !HAVE_GETPWUID */
+	{
+	    char *optr;
+	    for (optr = outbuf; *optr; optr++)
+		;
+	    sprintf(optr, "%lu", (unsigned long)uid);
+	}
 	if (flags & STF_RAW)
 	    strcat(outbuf, ")");
     }
@@ -163,10 +169,16 @@
 #ifdef HAVE_GETGRGID
 	struct group *gr;
 	gr = getgrgid(gid);
-	strcat(outbuf, gr ? gr->gr_name : "???");
-#else /* !HAVE_GETGRGID */
-	strcat(outbuf, "???");
+	if (gr)
+	    strcat(outbuf, gr->gr_name);
+	else
 #endif /* !HAVE_GETGRGID */
+	{
+	    char *optr;
+	    for (optr = outbuf; *optr; optr++)
+		;
+	    sprintf(optr, "%lu", (unsigned long)gid);
+	}
 	if (flags & STF_RAW)
 	    strcat(outbuf, ")");
     }


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



Messages sorted by: Reverse Date, Date, Thread, Author