Mail Archives: djgpp-workers/2000/08/22/08:23:52
This one contains a testsuite as well, adopted version of lstat() testsuite.
Any comments?
Laurynas
Index: djgpp/src/libc/posix/sys/stat/stat.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/sys/stat/stat.c,v
retrieving revision 1.9
diff -u -p -r1.9 stat.c
--- stat.c 2000/08/10 18:09:32 1.9
+++ stat.c 2000/08/22 11:34:41
@@ -12,6 +12,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
+#include <libc/symlink.h>
#ifdef TEST
#include "xstat.h"
@@ -20,7 +21,12 @@
int
stat(const char *path, struct stat *statbuf)
{
- return lstat(path, statbuf);
+ char name_copy[FILENAME_MAX];
+
+ if (!__solve_symlinks(path, name_copy))
+ return -1;
+
+ return lstat(name_copy, statbuf); /* Real file */
}
#ifdef TEST
Index: djgpp/tests/libc/posix/sys/stat/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/posix/sys/stat/makefile,v
retrieving revision 1.3
diff -u -p -r1.3 makefile
--- makefile 2000/08/20 15:56:51 1.3
+++ makefile 2000/08/22 11:34:53
@@ -8,5 +8,6 @@ SRC += mkdir.c
SRC += stat.c
SRC += stat1.c
SRC += svsf.c
+SRC += symstat.c
include $(TOP)/../makefile.inc
Index: djgpp/tests/libc/posix/sys/stat/symstat.c
===================================================================
RCS file: symstat.c
diff -N symstat.c
--- /dev/null Tue May 5 16:32:27 1998
+++ symstat.c Tue Aug 22 07:35:01 2000
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+int main(void)
+{
+ char *tmp_file;
+ struct stat file_info;
+ if (!__file_exists("file1"))
+ {
+ fprintf(stderr, "Required data file not found\n");
+ exit(1);
+ }
+ tmp_file = tempnam("./", "sl");
+ symlink("file1", tmp_file);
+ if (stat(tmp_file, &file_info))
+ {
+ perror("Test 1 failed - unexpected stat() failure ");
+ exit(1);
+ }
+ if (file_info.st_size != 10)
+ {
+ fprintf(stderr, "Test 1 failed - stat() returns wrong file size\n");
+ exit(1);
+ }
+ if (!S_ISREG(file_info.st_mode))
+ {
+ fprintf(stderr, "Test 1 failed - stat() does not set regular file bit "
+ "for mode\n");
+ exit(1);
+ }
+ if (file_info.st_mode & !S_IFREG)
+ {
+ fprintf(stderr, "Test 1 failed - stat() sets other mode bits for file\n");
+ exit(1);
+ }
+ printf("Test 1 passed\n");
+ if (stat("file1", &file_info))
+ {
+ fprintf(stderr, "Test 2 failed - unexpected stat() failure\n");
+ exit(1);
+ }
+ if (file_info.st_size != 10)
+ {
+ fprintf(stderr, "Test 2 failed - stat() returns wrong file size\n");
+ exit(1);
+ }
+ if (!S_ISREG(file_info.st_mode))
+ {
+ fprintf(stderr, "Test 2 failed - lstat() does not set regular file bit "
+ "for mode\n");
+ exit(1);
+ }
+ if (file_info.st_mode & !S_IFREG)
+ {
+ fprintf(stderr, "Test 2 failed - lstat() sets other mode bits for file\n");
+ exit(1);
+ }
+ printf("Test 2 passed\n");
+ remove(tmp_file);
+ return 0;
+}
- Raw text -