From: Nathan Wagner Date: Sat, 3 Nov 2018 14:46:10 +0000 (+0000) Subject: add -s option to stat to print file size X-Git-Tag: v0.2.16~40 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=8d5b72e66760d0aebf364ed7b2cdf05d821bea6e add -s option to stat to print file size --- diff --git a/t/stat.t b/t/stat.t index ead3bc6..c2a7ed0 100755 --- a/t/stat.t +++ b/t/stat.t @@ -16,7 +16,7 @@ ltypetest() { okstreq "$res" "$2" "$1 is a $2" } -plan 16 +plan 18 file="/tmp/$fn" @@ -30,6 +30,12 @@ tryrun rmdir $file tryrun touch $file typetest $file regular ltypetest $file regular +size=$(zpm stat -f '%s' $file) +okstreq "$size" 0 'file size is zero' +echo foo > $file +size=$(zpm stat -f '%s' $file) +okstreq "$size" 4 'file foo size is four' + # symlink require ln -s $file $file.symlink diff --git a/zpm-stat.c b/zpm-stat.c index d1f714b..b8cb9d7 100644 --- a/zpm-stat.c +++ b/zpm-stat.c @@ -82,6 +82,9 @@ void stat_one(char *fmt, char *timefmt, char *filename, struct stat *buf) { timestr[1023] = 0; printf("%s", timestr); break; + case 's': + printf("%jd", (intmax_t)buf->st_size); + break; case 'a': /* octal mode */ printf("%o", (int)buf->st_mode & 07777); break;