]> pd.if.org Git - zpackage/commitdiff
add -s option to stat to print file size
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 3 Nov 2018 14:46:10 +0000 (14:46 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 3 Nov 2018 14:49:45 +0000 (14:49 +0000)
t/stat.t
zpm-stat.c

index ead3bc6efb748a8b245e5686446939bbf49ad2f3..c2a7ed07e19a7e34acc59d476b09ebca54fc1ca4 100755 (executable)
--- 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
index d1f714b0edf7b10e6de5bb9948d84c2632a86666..b8cb9d767cb906746aae7f4bc78626360f2dee18 100644 (file)
@@ -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;