summaryrefslogtreecommitdiff
path: root/test/stat/stat.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-01-24 16:04:35 +0000
committerEric Andersen <andersen@codepoet.org>2003-01-24 16:04:35 +0000
commitce464b8b54384bbc7a63dbfdc6add6cc1997c21e (patch)
tree49582cbcde0733e0a9440b62a4949269c4139af1 /test/stat/stat.c
parent14c6293257eae377415d84ede9d118988e6474ce (diff)
Better stat tests
Diffstat (limited to 'test/stat/stat.c')
-rw-r--r--test/stat/stat.c91
1 files changed, 62 insertions, 29 deletions
diff --git a/test/stat/stat.c b/test/stat/stat.c
index eb99dbc64..9de2b3ef6 100644
--- a/test/stat/stat.c
+++ b/test/stat/stat.c
@@ -1,35 +1,68 @@
-
-#include <sys/stat.h>
#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+void print_struct_stat(char *msg, struct stat *s)
+{
+ printf("%s\n", msg);
+ /* The casts are because glibc thinks it's cool */
+ printf("device : 0x%x\n",(unsigned int)s->st_dev);
+ printf("inode : %d\n",(int)s->st_ino);
+ printf("mode : 0x%x\n",s->st_mode);
+ printf("nlink : %d\n",s->st_nlink);
+ printf("uid : %d\n",s->st_uid);
+ printf("gid : %d\n",s->st_gid);
+ printf("rdev : 0x%x\n",(unsigned int)s->st_rdev);
+ printf("size : %ld\n",s->st_size);
+ printf("blksize : %ld\n",s->st_blksize);
+ printf("blocks : %ld\n",s->st_blocks);
+ printf("atime : %ld\n",s->st_atime);
+ printf("mtime : %ld\n",s->st_mtime);
+ printf("ctime : %ld\n",s->st_ctime);
+}
-int main(int argc,char *argv[])
+int main(int argc,char **argv)
{
- struct stat s;
- int ret;
-
- ret = stat("/",&s);
-
- if(ret<0){
- perror("stat");
- exit(1);
- }
-
- /* The casts are because glibc thinks it's cool */
- printf("device : 0x%x\n",(unsigned int)s.st_dev);
- printf("inode : %d\n",(int)s.st_ino);
- printf("mode : 0x%x\n",s.st_mode);
- printf("nlink : %d\n",s.st_nlink);
- printf("uid : %d\n",s.st_uid);
- printf("gid : %d\n",s.st_gid);
- printf("rdev : 0x%x\n",(unsigned int)s.st_rdev);
- printf("size : %ld\n",s.st_size);
- printf("blksize : %ld\n",s.st_blksize);
- printf("blocks : %ld\n",s.st_blocks);
- printf("atime : %ld\n",s.st_atime);
- printf("mtime : %ld\n",s.st_mtime);
- printf("ctime : %ld\n",s.st_ctime);
-
- exit(0);
+ int fd, ret;
+ char *file;
+ struct stat s;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: stat FILE\n");
+ exit(1);
+ }
+ file = argv[1];
+
+ memset(&s, 0, sizeof(struct stat));
+ ret = stat(file, &s);
+ if(ret<0){
+ perror("stat");
+ exit(1);
+ }
+ print_struct_stat("\nTesting stat:", &s);
+
+ memset(&s, 0, sizeof(struct stat));
+ ret = lstat(file, &s);
+ if(ret<0){
+ perror("lstat");
+ exit(1);
+ }
+ print_struct_stat("\nTesting lstat:", &s);
+
+
+ fd = open(file, O_RDONLY);
+ if(fd<0){
+ perror("open");
+ exit(1);
+ }
+ memset(&s, 0, sizeof(struct stat));
+ ret = fstat(fd,&s);
+ if(ret<0){
+ perror("fstat");
+ exit(1);
+ }
+ print_struct_stat("\nTesting fstat:", &s);
+
+ exit(0);
}