From: Jim Meyering Date: Fri, 31 Jan 2003 18:28:39 +0000 (+0000) Subject: Include "file-type.h" X-Git-Tag: v4.5.5~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4686f1f3fd0deb1cedaf99fb23b0492616dbe89d;p=thirdparty%2Fcoreutils.git Include "file-type.h" (print_human_type): Remove function. (human_access): Rename from print_human_access. Return a string. (human_time): Rename from print_human_time. Return a string. (print_stat): Arrange so that field width and an alignment specifier are honored for the %A, %F, %x, %y, and %z formats. [%F]: Use file_type; this gives slightly different file type strings, e.g., `directory' instead of `Directory' and `regular file' or `regular empty file' instead of `Regular file'. --- diff --git a/src/stat.c b/src/stat.c index 7f2c5d2a4d..8018735c07 100644 --- a/src/stat.c +++ b/src/stat.c @@ -48,6 +48,7 @@ #include "closeout.h" #include "error.h" #include "filemode.h" +#include "file-type.h" #include "fs.h" #include "getopt.h" #include "quote.h" @@ -95,39 +96,6 @@ static struct option const long_options[] = { char *program_name; -static void -print_human_type (mode_t mode) -{ - char const *type; - switch (mode & S_IFMT) - { - case S_IFDIR: - type = "Directory"; - break; - case S_IFCHR: - type = "Character Device"; - break; - case S_IFBLK: - type = "Block Device"; - break; - case S_IFREG: - type = "Regular File"; - break; - case S_IFLNK: - type = "Symbolic Link"; - break; - case S_IFSOCK: - type = "Socket"; - break; - case S_IFIFO: - type = "Fifo File"; - break; - default: - type = "Unknown"; - } - fputs (type, stdout); -} - /* Return the type of the specified file system. Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) @@ -334,19 +302,20 @@ human_fstype (STRUCT_STATVFS const *statfsbuf) #endif } -static void -print_human_access (struct stat const *statbuf) +static char * +human_access (struct stat const *statbuf) { - char modebuf[11]; + static char modebuf[11]; mode_string (statbuf->st_mode, modebuf); modebuf[10] = 0; - fputs (modebuf, stdout); + return modebuf; } -static void -print_human_time (time_t const *t) +static char * +human_time (time_t const *t) { - char str[80]; + static char str[80]; + char *s; #if 0 /* %c is too locale-dependent. */ if (strftime (str, 40, "%c", localtime (t)) > 0) @@ -354,9 +323,11 @@ print_human_time (time_t const *t) if (nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", localtime (t), 0, 0) > 0) #endif - fputs (str, stdout); + s = str; else - printf ("Cannot calculate human readable time, sorry"); + s = _("Cannot calculate human readable time, sorry"); + + return s; } /* print statfs info */ @@ -484,14 +455,16 @@ print_stat (char *pformat, char m, char const *filename, void const *data) printf (pformat, statbuf->st_mode & 07777); break; case 'A': - print_human_access (statbuf); + strcat (pformat, "s"); + printf (pformat, human_access (statbuf)); break; case 'f': strcat (pformat, "x"); printf (pformat, statbuf->st_mode); break; case 'F': - print_human_type (statbuf->st_mode); + strcat (pformat, "s"); + printf (pformat, file_type (statbuf)); break; case 'h': strcat (pformat, "d"); @@ -538,21 +511,24 @@ print_stat (char *pformat, char m, char const *filename, void const *data) printf (pformat, (int) statbuf->st_blksize); break; case 'x': - print_human_time (&(statbuf->st_atime)); + strcat (pformat, "s"); + printf (pformat, human_time (&(statbuf->st_atime))); break; case 'X': strcat (pformat, "d"); printf (pformat, (int) statbuf->st_atime); break; case 'y': - print_human_time (&(statbuf->st_mtime)); + strcat (pformat, "s"); + printf (pformat, human_time (&(statbuf->st_mtime))); break; case 'Y': strcat (pformat, "d"); printf (pformat, (int) statbuf->st_mtime); break; case 'z': - print_human_time (&(statbuf->st_ctime)); + strcat (pformat, "s"); + printf (pformat, human_time (&(statbuf->st_ctime))); break; case 'Z': strcat (pformat, "d");