From f00928ec13966a05dfe83cc01858cedcfea375eb Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 21 Jul 2004 16:03:49 +0000 Subject: [PATCH] Added -s --- src/test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test.c b/src/test.c index ece407a..8b50ac4 100644 --- a/src/test.c +++ b/src/test.c @@ -45,6 +45,7 @@ static int _test(int argc, char * argv[]) /* n */ static int _is_string_not_empty(char * string); /* r */ static int _is_file_readable(char * pathname); /* S */ static int _is_file_socket(char * pathname); +/* s */ static int _is_file_size(char * pathname); /* w */ static int _is_file_writable(char * pathname); /* x */ static int _is_file_executable(char * pathname); /* z */ static int _is_string_empty(char * string); @@ -73,6 +74,8 @@ static int _test_single(char c, char * argv) return _is_file_readable(argv); case 'S': return _is_file_socket(argv); + case 's': + return _is_file_size(argv); case 'w': return _is_file_writable(argv); case 'x': @@ -199,6 +202,15 @@ static int _is_file_socket(char * pathname) return (st.st_mode & S_IFSOCK) ? 1 : 0; /* FIXME */ } +static int _is_file_size(char * pathname) +{ + struct stat st; + + if(stat(pathname, &st) != 0) + return 0; + return st.st_size > 0 ? 1 : 0; +} + static int _is_string_empty(char * string) { return *string == '\0' ? 1 : 0;