[uClibc-cvs] uClibc/test/stat .cvsignore,NONE,1.1 Makefile,1.6,1.7 stat.c,1.1,1.2

Erik Andersen andersen at codepoet.org
Fri Jan 24 16:04:39 UTC 2003


Update of /var/cvs/uClibc/test/stat
In directory winder:/tmp/cvs-serv22243

Modified Files:
	Makefile stat.c 
Added Files:
	.cvsignore 
Log Message:
Better stat tests


--- NEW FILE: .cvsignore ---
stat
stat.o
stat.out
stat64
stat64.o
stat64.out
stat64_glibc
stat64_glibc.o
stat64_glibc.out
stat_glibc
stat_glibc.o
stat_glibc.out

Index: Makefile
===================================================================
RCS file: /var/cvs/uClibc/test/stat/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile	23 Jan 2003 16:28:06 -0000	1.6
+++ Makefile	24 Jan 2003 16:04:35 -0000	1.7
@@ -19,9 +19,10 @@
 TESTDIR=../
 include $(TESTDIR)/Rules.mak
 
+CFLAGS64=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 
 
-TARGETS=stat stat_glibc
+TARGETS=stat_diff stat64_diff
 
 all: $(TARGETS)
 
@@ -41,9 +42,7 @@
 	$(CC) $(CFLAGS) -c $< -o $@.o
 	$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
 	$(STRIPTOOL) -x -R .note -R .comment $@
-	-$(LDD) $@
-	ls -l $@
-	-./$@
+	-./$@ stat.c > $@.out
 	-@ echo " "
 
 stat_glibc: stat.c Makefile
@@ -54,12 +53,49 @@
 	$(HOSTCC) $(GLIBC_CFLAGS) -c $< -o $@.o
 	$(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@
 	$(STRIPTOOL) -x -R .note -R .comment $@
-	-$(LDD) $@
-	ls -l $@
-	-./$@
+	-./$@ stat.c > $@.out
+	-@ echo " "
+
+stat_diff: stat stat_glibc
+	-@ echo "-------"
+	-@ echo " "
+	-@ echo "Diffing stat output: "
+	-@ echo " "
+	-diff -u stat_glibc.out stat.out
+	-@ echo " "
+
+stat64: stat.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC)
+	-@ echo "-------"
+	-@ echo " "
+	-@ echo "Compiling vs uClibc: "
+	-@ echo " "
+	$(CC) $(CFLAGS) $(CFLAGS64) -c $< -o $@.o
+	$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
+	$(STRIPTOOL) -x -R .note -R .comment $@
+	-./$@ stat.c > $@.out
+	-@ echo " "
+
+stat64_glibc: stat.c Makefile
+	-@ echo "-------"
+	-@ echo " "
+	-@ echo "Compiling vs GNU libc: "
+	-@ echo " "
+	$(HOSTCC) $(GLIBC_CFLAGS) $(CFLAGS64) -c $< -o $@.o
+	$(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@
+	$(STRIPTOOL) -x -R .note -R .comment $@
+	-./$@ stat.c > $@.out
+	-@ echo " "
+
+stat64_diff: stat64 stat64_glibc
+	-@ echo "-------"
+	-@ echo " "
+	-@ echo "Diffing stat64 output: "
+	-@ echo " "
+	-diff -u stat64_glibc.out stat64.out
 	-@ echo " "
 
 clean:
-	rm -f *.[oa] *~ core $(TARGETS)
+	rm -f *.[oa] *~ core stat stat_glibc stat_glibc.out stat.out \
+		stat64 stat64_glibc stat64_glibc.out stat64.out
 
 

Index: stat.c
===================================================================
RCS file: /var/cvs/uClibc/test/stat/stat.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- stat.c	25 May 2001 23:04:51 -0000	1.1
+++ stat.c	24 Jan 2003 16:04:35 -0000	1.2
@@ -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;
+    int fd, ret;
+    char *file;
+    struct stat s;
 
-	ret = stat("/",&s);
+    if (argc < 2) {
+	fprintf(stderr, "Usage: stat FILE\n");
+	exit(1);
+    }
+    file = argv[1];
 
-	if(ret<0){
-		perror("stat");
-		exit(1);
-	}
+    memset(&s, 0, sizeof(struct stat));
+    ret = stat(file, &s);
+    if(ret<0){
+	perror("stat");
+	exit(1);
+    }
+    print_struct_stat("\nTesting stat:", &s);
 
-	/* 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);
+    memset(&s, 0, sizeof(struct stat));
+    ret = lstat(file, &s);
+    if(ret<0){
+	perror("lstat");
+	exit(1);
+    }
+    print_struct_stat("\nTesting lstat:", &s);
 
-	exit(0);
+
+    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);
 }
 




More information about the uClibc-cvs mailing list