Mercurial > hg > octave-shane > gnulib-hg
comparison m4/stat.m4 @ 12258:150adbe92b27
stat: detect FreeBSD bug
Like Solaris 9, FreeBSD 7.2 mistakenly allows stat("link-to-file/").
Unlike Solaris, it correctly forbids stat("file/"). A number of
interfaces are affected (such as utimes), but replacing stat is
enough to catch several by reusing the Solaris 9 fixes.
* m4/stat.m4 (gl_FUNC_STAT): Also detect FreeBSD bug with slash on
symlink.
* doc/posix-functions/stat.texi (stat): Document the bug.
* tests/test-stat.h (test_stat_func): Add argument.
* tests/test-stat.c (main): Adjust caller.
* tests/test-fstatat.c (main): Likewise.
* modules/stat-tests (Depends-on): Add stdbool, symlink.
Reported by Jim Meyering.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Sat, 07 Nov 2009 16:59:11 -0700 |
parents | eb6b9da995d7 |
children | ea823743f290 |
comparison
equal
deleted
inserted
replaced
12257:37417e58ec13 | 12258:150adbe92b27 |
---|---|
1 # serial 2 | 1 # serial 3 |
2 | 2 |
3 # Copyright (C) 2009 Free Software Foundation, Inc. | 3 # Copyright (C) 2009 Free Software Foundation, Inc. |
4 # | 4 # |
5 # This file is free software; the Free Software Foundation | 5 # This file is free software; the Free Software Foundation |
6 # gives unlimited permission to copy and/or distribute it, | 6 # gives unlimited permission to copy and/or distribute it, |
9 AC_DEFUN([gl_FUNC_STAT], | 9 AC_DEFUN([gl_FUNC_STAT], |
10 [ | 10 [ |
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | 11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
12 AC_REQUIRE([gl_AC_DOS]) | 12 AC_REQUIRE([gl_AC_DOS]) |
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) | 13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) |
14 AC_CHECK_FUNCS_ONCE([lstat]) | |
14 dnl mingw is the only known platform where stat(".") and stat("./") differ | 15 dnl mingw is the only known platform where stat(".") and stat("./") differ |
15 AC_CACHE_CHECK([whether stat handles trailing slashes on directories], | 16 AC_CACHE_CHECK([whether stat handles trailing slashes on directories], |
16 [gl_cv_func_stat_dir_slash], | 17 [gl_cv_func_stat_dir_slash], |
17 [AC_RUN_IFELSE( | 18 [AC_RUN_IFELSE( |
18 [AC_LANG_PROGRAM( | 19 [AC_LANG_PROGRAM( |
22 [case $host_os in | 23 [case $host_os in |
23 mingw*) gl_cv_func_stat_dir_slash="guessing no";; | 24 mingw*) gl_cv_func_stat_dir_slash="guessing no";; |
24 *) gl_cv_func_stat_dir_slash="guessing yes";; | 25 *) gl_cv_func_stat_dir_slash="guessing yes";; |
25 esac])]) | 26 esac])]) |
26 dnl Solaris 9 mistakenly succeeds on stat("file/") | 27 dnl Solaris 9 mistakenly succeeds on stat("file/") |
28 dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/") | |
27 AC_CACHE_CHECK([whether stat handles trailing slashes on files], | 29 AC_CACHE_CHECK([whether stat handles trailing slashes on files], |
28 [gl_cv_func_stat_file_slash], | 30 [gl_cv_func_stat_file_slash], |
29 [touch conftest.tmp | 31 [touch conftest.tmp |
32 # Assume that if we have lstat, we can also check symlinks. | |
33 if test $ac_cv_func_lstat = yes; then | |
34 ln -s conftest.tmp conftest.lnk | |
35 fi | |
30 AC_RUN_IFELSE( | 36 AC_RUN_IFELSE( |
31 [AC_LANG_PROGRAM( | 37 [AC_LANG_PROGRAM( |
32 [[#include <sys/stat.h> | 38 [[#include <sys/stat.h> |
33 ]], [[struct stat st; return !stat ("conftest.tmp/", &st);]])], | 39 ]], [[struct stat st; |
40 if (!stat ("conftest.tmp/", &st)) return 1; | |
41 #if HAVE_LSTAT | |
42 if (!stat ("conftest.lnk/", &st)) return 2; | |
43 #endif | |
44 ]])], | |
34 [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no], | 45 [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no], |
35 [gl_cv_func_stat_file_slash="guessing no"])]) | 46 [gl_cv_func_stat_file_slash="guessing no"]) |
47 rm -f conftest.tmp conftest.lnk]) | |
36 case $gl_cv_func_stat_dir_slash in | 48 case $gl_cv_func_stat_dir_slash in |
37 *no) REPLACE_STAT=1 | 49 *no) REPLACE_STAT=1 |
38 AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs | 50 AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs |
39 help when passed a directory name with a trailing slash]);; | 51 help when passed a directory name with a trailing slash]);; |
40 esac | 52 esac |