Message-ID: <39A26832.B7DC67C9@softhome.net> Date: Tue, 22 Aug 2000 13:46:58 +0200 From: Laurynas Biveinis X-Mailer: Mozilla 4.74 [en] (Win98; U) X-Accept-Language: lt,en MIME-Version: 1.0 To: DJGPP Workers Subject: Patch: symlinks in stat() Content-Type: text/plain; charset=iso-8859-4 Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com 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 #include #include +#include #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 +#include +#include +#include + +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; +}