aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2011-03-01 21:25:09 -0800
committerPaul Eggert2011-03-01 21:25:09 -0800
commit6c0dea8a89bdfbdad454a9609f0bed8db4c9fccf (patch)
treefbde0220480ce4d37903e98c74c5103a0f320f16
parent8889f4e2c332b0ecedc9e6088252f4cbae301236 (diff)
parent4a8b879b87962d5f37c05d3650f43cc571b22bc7 (diff)
downloademacs-6c0dea8a89bdfbdad454a9609f0bed8db4c9fccf.tar.gz
emacs-6c0dea8a89bdfbdad454a9609f0bed8db4c9fccf.zip
Merge: Work around some portability problems with symlinks.
-rw-r--r--ChangeLog13
-rw-r--r--Makefile.in2
-rw-r--r--aclocal.m44
-rwxr-xr-xconfig.sub4
-rwxr-xr-xconfigure602
-rw-r--r--configure.in9
-rw-r--r--lib/Makefile.in30
-rw-r--r--lib/dosname.h53
-rw-r--r--lib/gnulib.mk45
-rw-r--r--lib/lstat.c91
-rw-r--r--lib/readlink.c74
-rw-r--r--lib/stat.c105
-rw-r--r--lib/symlink.c57
-rw-r--r--m4/gl-comp.m427
-rw-r--r--m4/lstat.m469
-rw-r--r--m4/readlink.m462
-rw-r--r--m4/stat.m466
-rw-r--r--m4/symlink.m445
-rw-r--r--src/ChangeLog13
-rw-r--r--src/config.in21
-rw-r--r--src/fileio.c41
21 files changed, 1283 insertions, 150 deletions
diff --git a/ChangeLog b/ChangeLog
index f7bef44ef55..3bb49ce27f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
12011-03-02 Paul Eggert <eggert@cs.ucla.edu>
2
3 Work around some portability problems with symlinks.
4
5 * Makefile.in (GNULIB_MODULES): Add lstat, readlink, symlink.
6 * configure.in (lstat, HAVE_LSTAT): Remove special hack.
7 * lib/dosname.h, lib/lstat.c, lib/readlink.c, lib/stat.c:
8 * lib/symlink.c, m4/lstat.m4, m4/readlink.m4, m4/stat.m4:
9 * m4/symlink.m4:
10 New files, automatically generated from gnulib.
11 * aclocal.m4, configure, lib/Makefile.in, lib/gnulib.mk:
12 * m4/gl-comp.m4, src/config.in, config.sub: Regenerate.
13
12011-02-26 Eli Zaretskii <eliz@gnu.org> 142011-02-26 Eli Zaretskii <eliz@gnu.org>
2 15
3 * .bzrignore: Ignore new lib/*.in-h files. 16 * .bzrignore: Ignore new lib/*.in-h files.
diff --git a/Makefile.in b/Makefile.in
index 489409afe5b..7bd4318bfba 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -332,7 +332,7 @@ DOS_gnulib_comp.m4 = gl-comp.m4
332# as per $(gnulib_srcdir)/DEPENDENCIES. 332# as per $(gnulib_srcdir)/DEPENDENCIES.
333GNULIB_MODULES = \ 333GNULIB_MODULES = \
334 crypto/md5 dtoastr filemode getloadavg getopt-gnu \ 334 crypto/md5 dtoastr filemode getloadavg getopt-gnu \
335 ignore-value mktime strftime sys_stat 335 ignore-value lstat mktime readlink strftime symlink sys_stat
336GNULIB_TOOL_FLAGS = \ 336GNULIB_TOOL_FLAGS = \
337 --import --no-changelog --no-vc-files --makefile-name=gnulib.mk 337 --import --no-changelog --no-vc-files --makefile-name=gnulib.mk
338sync-from-gnulib: $(gnulib_srcdir) 338sync-from-gnulib: $(gnulib_srcdir)
diff --git a/aclocal.m4 b/aclocal.m4
index 880166dc34e..1536f3b48b5 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -994,15 +994,19 @@ m4_include([m4/gl-comp.m4])
994m4_include([m4/gnulib-common.m4]) 994m4_include([m4/gnulib-common.m4])
995m4_include([m4/include_next.m4]) 995m4_include([m4/include_next.m4])
996m4_include([m4/longlong.m4]) 996m4_include([m4/longlong.m4])
997m4_include([m4/lstat.m4])
997m4_include([m4/md5.m4]) 998m4_include([m4/md5.m4])
998m4_include([m4/mktime.m4]) 999m4_include([m4/mktime.m4])
999m4_include([m4/multiarch.m4]) 1000m4_include([m4/multiarch.m4])
1001m4_include([m4/readlink.m4])
1000m4_include([m4/st_dm_mode.m4]) 1002m4_include([m4/st_dm_mode.m4])
1003m4_include([m4/stat.m4])
1001m4_include([m4/stdbool.m4]) 1004m4_include([m4/stdbool.m4])
1002m4_include([m4/stddef_h.m4]) 1005m4_include([m4/stddef_h.m4])
1003m4_include([m4/stdint.m4]) 1006m4_include([m4/stdint.m4])
1004m4_include([m4/stdlib_h.m4]) 1007m4_include([m4/stdlib_h.m4])
1005m4_include([m4/strftime.m4]) 1008m4_include([m4/strftime.m4])
1009m4_include([m4/symlink.m4])
1006m4_include([m4/sys_stat_h.m4]) 1010m4_include([m4/sys_stat_h.m4])
1007m4_include([m4/time_h.m4]) 1011m4_include([m4/time_h.m4])
1008m4_include([m4/time_r.m4]) 1012m4_include([m4/time_r.m4])
diff --git a/config.sub b/config.sub
index 83da3565c17..0ef29b072ed 100755
--- a/config.sub
+++ b/config.sub
@@ -4,7 +4,7 @@
4# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 4# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5# 2011 Free Software Foundation, Inc. 5# 2011 Free Software Foundation, Inc.
6 6
7timestamp='2011-02-02' 7timestamp='2011-02-24'
8 8
9# This file is (in principle) common to ALL GNU software. 9# This file is (in principle) common to ALL GNU software.
10# The presence of a machine in this file suggests that SOME GNU software 10# The presence of a machine in this file suggests that SOME GNU software
@@ -76,7 +76,7 @@ version="\
76GNU config.sub ($timestamp) 76GNU config.sub ($timestamp)
77 77
78Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 78Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
792001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free 792001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free
80Software Foundation, Inc. 80Software Foundation, Inc.
81 81
82This is free software; see the source for copying conditions. There is NO 82This is free software; see the source for copying conditions. There is NO
diff --git a/configure b/configure
index f3fae2fb85f..68447e985f0 100755
--- a/configure
+++ b/configure
@@ -679,38 +679,6 @@ NEXT_AS_FIRST_DIRECTIVE_TIME_H
679NEXT_TIME_H 679NEXT_TIME_H
680NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H 680NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H
681NEXT_SYS_STAT_H 681NEXT_SYS_STAT_H
682REPLACE_UTIMENSAT
683REPLACE_STAT
684REPLACE_MKNOD
685REPLACE_MKFIFO
686REPLACE_MKDIR
687REPLACE_LSTAT
688REPLACE_FUTIMENS
689REPLACE_FSTATAT
690REPLACE_FSTAT
691HAVE_UTIMENSAT
692HAVE_MKNODAT
693HAVE_MKNOD
694HAVE_MKFIFOAT
695HAVE_MKFIFO
696HAVE_MKDIRAT
697HAVE_LSTAT
698HAVE_LCHMOD
699HAVE_FUTIMENS
700HAVE_FSTATAT
701HAVE_FCHMODAT
702GNULIB_UTIMENSAT
703GNULIB_STAT
704GNULIB_MKNODAT
705GNULIB_MKNOD
706GNULIB_MKFIFOAT
707GNULIB_MKFIFO
708GNULIB_MKDIRAT
709GNULIB_LSTAT
710GNULIB_LCHMOD
711GNULIB_FUTIMENS
712GNULIB_FSTATAT
713GNULIB_FCHMODAT
714NEXT_AS_FIRST_DIRECTIVE_STDLIB_H 682NEXT_AS_FIRST_DIRECTIVE_STDLIB_H
715NEXT_STDLIB_H 683NEXT_STDLIB_H
716STDINT_H 684STDINT_H
@@ -758,6 +726,38 @@ GNULIB_TIMEGM
758GNULIB_STRPTIME 726GNULIB_STRPTIME
759GNULIB_NANOSLEEP 727GNULIB_NANOSLEEP
760GNULIB_MKTIME 728GNULIB_MKTIME
729REPLACE_UTIMENSAT
730REPLACE_STAT
731REPLACE_MKNOD
732REPLACE_MKFIFO
733REPLACE_MKDIR
734REPLACE_LSTAT
735REPLACE_FUTIMENS
736REPLACE_FSTATAT
737REPLACE_FSTAT
738HAVE_UTIMENSAT
739HAVE_MKNODAT
740HAVE_MKNOD
741HAVE_MKFIFOAT
742HAVE_MKFIFO
743HAVE_MKDIRAT
744HAVE_LSTAT
745HAVE_LCHMOD
746HAVE_FUTIMENS
747HAVE_FSTATAT
748HAVE_FCHMODAT
749GNULIB_UTIMENSAT
750GNULIB_STAT
751GNULIB_MKNODAT
752GNULIB_MKNOD
753GNULIB_MKFIFOAT
754GNULIB_MKFIFO
755GNULIB_MKDIRAT
756GNULIB_LSTAT
757GNULIB_LCHMOD
758GNULIB_FUTIMENS
759GNULIB_FSTATAT
760GNULIB_FCHMODAT
761LTLIBINTL 761LTLIBINTL
762LIBINTL 762LIBINTL
763GETOPT_H 763GETOPT_H
@@ -1165,9 +1165,6 @@ LDFLAGS
1165LIBS 1165LIBS
1166CPPFLAGS 1166CPPFLAGS
1167CPP 1167CPP
1168CPPFLAGS
1169CPP
1170CPPFLAGS
1171XMKMF' 1168XMKMF'
1172 1169
1173 1170
@@ -2960,14 +2957,16 @@ as_fn_append ac_header_list " unistd.h"
2960as_fn_append ac_header_list " sys/param.h" 2957as_fn_append ac_header_list " sys/param.h"
2961gl_getopt_required=GNU 2958gl_getopt_required=GNU
2962as_fn_append ac_header_list " getopt.h" 2959as_fn_append ac_header_list " getopt.h"
2960as_fn_append ac_func_list " lstat"
2963as_fn_append ac_func_list " alarm" 2961as_fn_append ac_func_list " alarm"
2962as_fn_append ac_func_list " readlink"
2964as_fn_append ac_header_list " wchar.h" 2963as_fn_append ac_header_list " wchar.h"
2965as_fn_append ac_header_list " stdint.h" 2964as_fn_append ac_header_list " stdint.h"
2966as_fn_append ac_func_list " tzset" 2965as_fn_append ac_func_list " tzset"
2966as_fn_append ac_func_list " symlink"
2967as_fn_append ac_header_list " sys/stat.h" 2967as_fn_append ac_header_list " sys/stat.h"
2968as_fn_append ac_header_list " sys/time.h" 2968as_fn_append ac_header_list " sys/time.h"
2969as_fn_append ac_func_list " localtime_r" 2969as_fn_append ac_func_list " localtime_r"
2970as_fn_append ac_func_list " lstat"
2971# Check that the precious variables saved in the cache have kept the same 2970# Check that the precious variables saved in the cache have kept the same
2972# value. 2971# value.
2973ac_cache_corrupted=false 2972ac_cache_corrupted=false
@@ -6126,6 +6125,7 @@ $as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
6126 # Code from module arg-nonnull: 6125 # Code from module arg-nonnull:
6127 # Code from module c++defs: 6126 # Code from module c++defs:
6128 # Code from module crypto/md5: 6127 # Code from module crypto/md5:
6128 # Code from module dosname:
6129 # Code from module dtoastr: 6129 # Code from module dtoastr:
6130 # Code from module extensions: 6130 # Code from module extensions:
6131 6131
@@ -6137,13 +6137,17 @@ $as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
6137 # Code from module ignore-value: 6137 # Code from module ignore-value:
6138 # Code from module include_next: 6138 # Code from module include_next:
6139 # Code from module intprops: 6139 # Code from module intprops:
6140 # Code from module lstat:
6140 # Code from module mktime: 6141 # Code from module mktime:
6141 # Code from module multiarch: 6142 # Code from module multiarch:
6143 # Code from module readlink:
6144 # Code from module stat:
6142 # Code from module stdbool: 6145 # Code from module stdbool:
6143 # Code from module stddef: 6146 # Code from module stddef:
6144 # Code from module stdint: 6147 # Code from module stdint:
6145 # Code from module stdlib: 6148 # Code from module stdlib:
6146 # Code from module strftime: 6149 # Code from module strftime:
6150 # Code from module symlink:
6147 # Code from module sys_stat: 6151 # Code from module sys_stat:
6148 # Code from module time: 6152 # Code from module time:
6149 # Code from module time_r: 6153 # Code from module time_r:
@@ -14500,19 +14504,38 @@ fi
14500 14504
14501 14505
14502 14506
14503 GNULIB_MKTIME=0; 14507 GNULIB_FCHMODAT=0;
14504 GNULIB_NANOSLEEP=0; 14508 GNULIB_FSTATAT=0;
14505 GNULIB_STRPTIME=0; 14509 GNULIB_FUTIMENS=0;
14506 GNULIB_TIMEGM=0; 14510 GNULIB_LCHMOD=0;
14507 GNULIB_TIME_R=0; 14511 GNULIB_LSTAT=0;
14508 HAVE_DECL_LOCALTIME_R=1; 14512 GNULIB_MKDIRAT=0;
14509 HAVE_NANOSLEEP=1; 14513 GNULIB_MKFIFO=0;
14510 HAVE_STRPTIME=1; 14514 GNULIB_MKFIFOAT=0;
14511 HAVE_TIMEGM=1; 14515 GNULIB_MKNOD=0;
14512 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; 14516 GNULIB_MKNODAT=0;
14513 REPLACE_MKTIME=GNULIB_PORTCHECK; 14517 GNULIB_STAT=0;
14514 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; 14518 GNULIB_UTIMENSAT=0;
14515 REPLACE_TIMEGM=GNULIB_PORTCHECK; 14519 HAVE_FCHMODAT=1;
14520 HAVE_FSTATAT=1;
14521 HAVE_FUTIMENS=1;
14522 HAVE_LCHMOD=1;
14523 HAVE_LSTAT=1;
14524 HAVE_MKDIRAT=1;
14525 HAVE_MKFIFO=1;
14526 HAVE_MKFIFOAT=1;
14527 HAVE_MKNOD=1;
14528 HAVE_MKNODAT=1;
14529 HAVE_UTIMENSAT=1;
14530 REPLACE_FSTAT=0;
14531 REPLACE_FSTATAT=0;
14532 REPLACE_FUTIMENS=0;
14533 REPLACE_LSTAT=0;
14534 REPLACE_MKDIR=0;
14535 REPLACE_MKFIFO=0;
14536 REPLACE_MKNOD=0;
14537 REPLACE_STAT=0;
14538 REPLACE_UTIMENSAT=0;
14516 14539
14517 14540
14518 14541
@@ -14532,6 +14555,93 @@ done
14532 14555
14533 14556
14534 14557
14558 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5
14559$as_echo_n "checking whether lstat correctly handles trailing slash... " >&6; }
14560if ${ac_cv_func_lstat_dereferences_slashed_symlink+:} false; then :
14561 $as_echo_n "(cached) " >&6
14562else
14563 rm -f conftest.sym conftest.file
14564 echo >conftest.file
14565 if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
14566 if test "$cross_compiling" = yes; then :
14567 # When cross-compiling, be pessimistic so we will end up using the
14568 # replacement version of lstat that checks for trailing slashes and
14569 # calls lstat a second time when necessary.
14570 ac_cv_func_lstat_dereferences_slashed_symlink=no
14571
14572else
14573 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14574/* end confdefs.h. */
14575$ac_includes_default
14576int
14577main ()
14578{
14579struct stat sbuf;
14580 /* Linux will dereference the symlink and fail, as required by
14581 POSIX. That is better in the sense that it means we will not
14582 have to compile and use the lstat wrapper. */
14583 return lstat ("conftest.sym/", &sbuf) == 0;
14584
14585 ;
14586 return 0;
14587}
14588_ACEOF
14589if ac_fn_c_try_run "$LINENO"; then :
14590 ac_cv_func_lstat_dereferences_slashed_symlink=yes
14591else
14592 ac_cv_func_lstat_dereferences_slashed_symlink=no
14593fi
14594rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
14595 conftest.$ac_objext conftest.beam conftest.$ac_ext
14596fi
14597
14598 else
14599 # If the 'ln -s' command failed, then we probably don't even
14600 # have an lstat function.
14601 ac_cv_func_lstat_dereferences_slashed_symlink=no
14602 fi
14603 rm -f conftest.sym conftest.file
14604
14605fi
14606{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5
14607$as_echo "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; }
14608 test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
14609
14610cat >>confdefs.h <<_ACEOF
14611#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
14612_ACEOF
14613
14614 if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then
14615
14616
14617
14618
14619
14620
14621
14622
14623 gl_LIBOBJS="$gl_LIBOBJS lstat.$ac_objext"
14624
14625 fi
14626
14627
14628 GNULIB_MKTIME=0;
14629 GNULIB_NANOSLEEP=0;
14630 GNULIB_STRPTIME=0;
14631 GNULIB_TIMEGM=0;
14632 GNULIB_TIME_R=0;
14633 HAVE_DECL_LOCALTIME_R=1;
14634 HAVE_NANOSLEEP=1;
14635 HAVE_STRPTIME=1;
14636 HAVE_TIMEGM=1;
14637 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;
14638 REPLACE_MKTIME=GNULIB_PORTCHECK;
14639 REPLACE_NANOSLEEP=GNULIB_PORTCHECK;
14640 REPLACE_TIMEGM=GNULIB_PORTCHECK;
14641
14642
14643
14644
14535 gl_cv_c_multiarch=no 14645 gl_cv_c_multiarch=no
14536 cat confdefs.h - <<_ACEOF >conftest.$ac_ext 14646 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14537/* end confdefs.h. */ 14647/* end confdefs.h. */
@@ -14573,6 +14683,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
14573 fi 14683 fi
14574 14684
14575 14685
14686
14687
14576{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5 14688{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
14577$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; } 14689$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
14578if ${ac_cv_header_stdbool_h+:} false; then : 14690if ${ac_cv_header_stdbool_h+:} false; then :
@@ -14832,38 +14944,6 @@ fi
14832 14944
14833 14945
14834 14946
14835 GNULIB_FCHMODAT=0;
14836 GNULIB_FSTATAT=0;
14837 GNULIB_FUTIMENS=0;
14838 GNULIB_LCHMOD=0;
14839 GNULIB_LSTAT=0;
14840 GNULIB_MKDIRAT=0;
14841 GNULIB_MKFIFO=0;
14842 GNULIB_MKFIFOAT=0;
14843 GNULIB_MKNOD=0;
14844 GNULIB_MKNODAT=0;
14845 GNULIB_STAT=0;
14846 GNULIB_UTIMENSAT=0;
14847 HAVE_FCHMODAT=1;
14848 HAVE_FSTATAT=1;
14849 HAVE_FUTIMENS=1;
14850 HAVE_LCHMOD=1;
14851 HAVE_LSTAT=1;
14852 HAVE_MKDIRAT=1;
14853 HAVE_MKFIFO=1;
14854 HAVE_MKFIFOAT=1;
14855 HAVE_MKNOD=1;
14856 HAVE_MKNODAT=1;
14857 HAVE_UTIMENSAT=1;
14858 REPLACE_FSTAT=0;
14859 REPLACE_FSTATAT=0;
14860 REPLACE_FUTIMENS=0;
14861 REPLACE_LSTAT=0;
14862 REPLACE_MKDIR=0;
14863 REPLACE_MKFIFO=0;
14864 REPLACE_MKNOD=0;
14865 REPLACE_STAT=0;
14866 REPLACE_UTIMENSAT=0;
14867 14947
14868{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5 14948{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5
14869$as_echo_n "checking whether stat file-mode macros are broken... " >&6; } 14949$as_echo_n "checking whether stat file-mode macros are broken... " >&6; }
@@ -15169,6 +15249,7 @@ fi
15169 15249
15170 : 15250 :
15171 15251
15252 # Code from module dosname:
15172 # Code from module dtoastr: 15253 # Code from module dtoastr:
15173 15254
15174 # Code from module extensions: 15255 # Code from module extensions:
@@ -15776,6 +15857,28 @@ fi
15776 15857
15777 # Code from module include_next: 15858 # Code from module include_next:
15778 # Code from module intprops: 15859 # Code from module intprops:
15860 # Code from module lstat:
15861
15862
15863
15864 if test $ac_cv_func_lstat = yes; then
15865
15866 if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
15867 REPLACE_LSTAT=1
15868 fi
15869 # Prerequisites of lib/lstat.c.
15870
15871 else
15872 HAVE_LSTAT=0
15873 fi
15874
15875
15876
15877
15878 GNULIB_LSTAT=1
15879
15880
15881
15779 # Code from module mktime: 15882 # Code from module mktime:
15780 15883
15781 15884
@@ -16033,6 +16136,246 @@ fi
16033 16136
16034 # Code from module multiarch: 16137 # Code from module multiarch:
16035 16138
16139 # Code from module readlink:
16140
16141
16142
16143 if test $ac_cv_func_readlink = no; then
16144 HAVE_READLINK=0
16145
16146
16147
16148
16149
16150
16151
16152
16153 gl_LIBOBJS="$gl_LIBOBJS readlink.$ac_objext"
16154
16155
16156 :
16157
16158 else
16159 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether readlink signature is correct" >&5
16160$as_echo_n "checking whether readlink signature is correct... " >&6; }
16161if ${gl_cv_decl_readlink_works+:} false; then :
16162 $as_echo_n "(cached) " >&6
16163else
16164 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16165/* end confdefs.h. */
16166#include <unistd.h>
16167 /* Cause compilation failure if original declaration has wrong type. */
16168 ssize_t readlink (const char *, char *, size_t);
16169int
16170main ()
16171{
16172
16173 ;
16174 return 0;
16175}
16176_ACEOF
16177if ac_fn_c_try_compile "$LINENO"; then :
16178 gl_cv_decl_readlink_works=yes
16179else
16180 gl_cv_decl_readlink_works=no
16181fi
16182rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
16183fi
16184{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_decl_readlink_works" >&5
16185$as_echo "$gl_cv_decl_readlink_works" >&6; }
16186 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether readlink handles trailing slash correctly" >&5
16187$as_echo_n "checking whether readlink handles trailing slash correctly... " >&6; }
16188if ${gl_cv_func_readlink_works+:} false; then :
16189 $as_echo_n "(cached) " >&6
16190else
16191 # We have readlink, so assume ln -s works.
16192 ln -s conftest.no-such conftest.link
16193 ln -s conftest.link conftest.lnk2
16194 if test "$cross_compiling" = yes; then :
16195 gl_cv_func_readlink_works="guessing no"
16196else
16197 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16198/* end confdefs.h. */
16199#include <unistd.h>
16200
16201int
16202main ()
16203{
16204char buf[20];
16205 return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;
16206 ;
16207 return 0;
16208}
16209_ACEOF
16210if ac_fn_c_try_run "$LINENO"; then :
16211 gl_cv_func_readlink_works=yes
16212else
16213 gl_cv_func_readlink_works=no
16214fi
16215rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
16216 conftest.$ac_objext conftest.beam conftest.$ac_ext
16217fi
16218
16219 rm -f conftest.link conftest.lnk2
16220fi
16221{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_readlink_works" >&5
16222$as_echo "$gl_cv_func_readlink_works" >&6; }
16223 if test "$gl_cv_func_readlink_works" != yes; then
16224
16225$as_echo "#define READLINK_TRAILING_SLASH_BUG 1" >>confdefs.h
16226
16227 REPLACE_READLINK=1
16228
16229
16230
16231
16232
16233
16234
16235
16236 gl_LIBOBJS="$gl_LIBOBJS readlink.$ac_objext"
16237
16238 elif test "$gl_cv_decl_readlink_works" != yes; then
16239 REPLACE_READLINK=1
16240
16241
16242
16243
16244
16245
16246
16247
16248 gl_LIBOBJS="$gl_LIBOBJS readlink.$ac_objext"
16249
16250 fi
16251 fi
16252
16253
16254
16255
16256 GNULIB_READLINK=1
16257
16258
16259
16260 # Code from module stat:
16261
16262
16263
16264 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat handles trailing slashes on directories" >&5
16265$as_echo_n "checking whether stat handles trailing slashes on directories... " >&6; }
16266if ${gl_cv_func_stat_dir_slash+:} false; then :
16267 $as_echo_n "(cached) " >&6
16268else
16269 if test "$cross_compiling" = yes; then :
16270 case $host_os in
16271 mingw*) gl_cv_func_stat_dir_slash="guessing no";;
16272 *) gl_cv_func_stat_dir_slash="guessing yes";;
16273 esac
16274else
16275 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16276/* end confdefs.h. */
16277#include <sys/stat.h>
16278
16279int
16280main ()
16281{
16282struct stat st; return stat (".", &st) != stat ("./", &st);
16283 ;
16284 return 0;
16285}
16286_ACEOF
16287if ac_fn_c_try_run "$LINENO"; then :
16288 gl_cv_func_stat_dir_slash=yes
16289else
16290 gl_cv_func_stat_dir_slash=no
16291fi
16292rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
16293 conftest.$ac_objext conftest.beam conftest.$ac_ext
16294fi
16295
16296fi
16297{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_stat_dir_slash" >&5
16298$as_echo "$gl_cv_func_stat_dir_slash" >&6; }
16299 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat handles trailing slashes on files" >&5
16300$as_echo_n "checking whether stat handles trailing slashes on files... " >&6; }
16301if ${gl_cv_func_stat_file_slash+:} false; then :
16302 $as_echo_n "(cached) " >&6
16303else
16304 touch conftest.tmp
16305 # Assume that if we have lstat, we can also check symlinks.
16306 if test $ac_cv_func_lstat = yes; then
16307 ln -s conftest.tmp conftest.lnk
16308 fi
16309 if test "$cross_compiling" = yes; then :
16310 gl_cv_func_stat_file_slash="guessing no"
16311else
16312 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16313/* end confdefs.h. */
16314#include <sys/stat.h>
16315
16316int
16317main ()
16318{
16319int result = 0;
16320 struct stat st;
16321 if (!stat ("conftest.tmp/", &st))
16322 result |= 1;
16323#if HAVE_LSTAT
16324 if (!stat ("conftest.lnk/", &st))
16325 result |= 2;
16326#endif
16327 return result;
16328
16329 ;
16330 return 0;
16331}
16332_ACEOF
16333if ac_fn_c_try_run "$LINENO"; then :
16334 gl_cv_func_stat_file_slash=yes
16335else
16336 gl_cv_func_stat_file_slash=no
16337fi
16338rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
16339 conftest.$ac_objext conftest.beam conftest.$ac_ext
16340fi
16341
16342 rm -f conftest.tmp conftest.lnk
16343fi
16344{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_stat_file_slash" >&5
16345$as_echo "$gl_cv_func_stat_file_slash" >&6; }
16346 case $gl_cv_func_stat_dir_slash in
16347 *no) REPLACE_STAT=1
16348
16349$as_echo "#define REPLACE_FUNC_STAT_DIR 1" >>confdefs.h
16350;;
16351 esac
16352 case $gl_cv_func_stat_file_slash in
16353 *no) REPLACE_STAT=1
16354
16355$as_echo "#define REPLACE_FUNC_STAT_FILE 1" >>confdefs.h
16356;;
16357 esac
16358 if test $REPLACE_STAT = 1; then
16359
16360
16361
16362
16363
16364
16365
16366
16367 gl_LIBOBJS="$gl_LIBOBJS stat.$ac_objext"
16368
16369
16370 fi
16371
16372
16373
16374
16375 GNULIB_STAT=1
16376
16377
16378
16036 # Code from module stdbool: 16379 # Code from module stdbool:
16037 16380
16038 16381
@@ -16937,6 +17280,86 @@ $as_echo "#define my_strftime nstrftime" >>confdefs.h
16937 17280
16938 17281
16939 17282
17283 # Code from module symlink:
17284
17285
17286
17287 if test $ac_cv_func_symlink = no; then
17288 HAVE_SYMLINK=0
17289
17290
17291
17292
17293
17294
17295
17296
17297 gl_LIBOBJS="$gl_LIBOBJS symlink.$ac_objext"
17298
17299 else
17300 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether symlink handles trailing slash correctly" >&5
17301$as_echo_n "checking whether symlink handles trailing slash correctly... " >&6; }
17302if ${gl_cv_func_symlink_works+:} false; then :
17303 $as_echo_n "(cached) " >&6
17304else
17305 if test "$cross_compiling" = yes; then :
17306 gl_cv_func_symlink_works="guessing no"
17307else
17308 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17309/* end confdefs.h. */
17310#include <unistd.h>
17311
17312int
17313main ()
17314{
17315int result = 0;
17316 if (!symlink ("a", "conftest.link/"))
17317 result |= 1;
17318 if (symlink ("conftest.f", "conftest.lnk2"))
17319 result |= 2;
17320 else if (!symlink ("a", "conftest.lnk2/"))
17321 result |= 4;
17322 return result;
17323
17324 ;
17325 return 0;
17326}
17327_ACEOF
17328if ac_fn_c_try_run "$LINENO"; then :
17329 gl_cv_func_symlink_works=yes
17330else
17331 gl_cv_func_symlink_works=no
17332fi
17333rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
17334 conftest.$ac_objext conftest.beam conftest.$ac_ext
17335fi
17336
17337 rm -f conftest.f conftest.link conftest.lnk2
17338fi
17339{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_symlink_works" >&5
17340$as_echo "$gl_cv_func_symlink_works" >&6; }
17341 if test "$gl_cv_func_symlink_works" != yes; then
17342 REPLACE_SYMLINK=1
17343
17344
17345
17346
17347
17348
17349
17350
17351 gl_LIBOBJS="$gl_LIBOBJS symlink.$ac_objext"
17352
17353 fi
17354 fi
17355
17356
17357
17358
17359 GNULIB_SYMLINK=1
17360
17361
17362
16940 # Code from module sys_stat: 17363 # Code from module sys_stat:
16941 17364
16942 17365
@@ -17220,23 +17643,6 @@ $as_echo "$gl_cv_next_unistd_h" >&6; }
17220 17643
17221 17644
17222 17645
17223# Emacs does not care about lstat's behavior on files whose names end in
17224# trailing slashes, so it does not use the gnulib lstat module.
17225# However, Emacs does want the "#define lstat stat" in sys/stat.h
17226# when lstat does not exist, so it pretends to use the lstat module
17227# even though it implements only the lstat-checking part of that module.
17228
17229
17230
17231test $ac_cv_func_lstat = yes || HAVE_LSTAT=0
17232
17233
17234
17235 GNULIB_LSTAT=1
17236
17237
17238
17239
17240# UNIX98 PTYs. 17646# UNIX98 PTYs.
17241for ac_func in grantpt 17647for ac_func in grantpt
17242do : 17648do :
diff --git a/configure.in b/configure.in
index b832b79994e..710f0945066 100644
--- a/configure.in
+++ b/configure.in
@@ -2661,15 +2661,6 @@ gl_ASSERT_NO_GNULIB_POSIXCHECK
2661gl_ASSERT_NO_GNULIB_TESTS 2661gl_ASSERT_NO_GNULIB_TESTS
2662gl_INIT 2662gl_INIT
2663 2663
2664# Emacs does not care about lstat's behavior on files whose names end in
2665# trailing slashes, so it does not use the gnulib lstat module.
2666# However, Emacs does want the "#define lstat stat" in sys/stat.h
2667# when lstat does not exist, so it pretends to use the lstat module
2668# even though it implements only the lstat-checking part of that module.
2669AC_CHECK_FUNCS_ONCE([lstat])
2670test $ac_cv_func_lstat = yes || HAVE_LSTAT=0
2671gl_SYS_STAT_MODULE_INDICATOR([lstat])
2672
2673# UNIX98 PTYs. 2664# UNIX98 PTYs.
2674AC_CHECK_FUNCS(grantpt) 2665AC_CHECK_FUNCS(grantpt)
2675 2666
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 7135d3ebbf9..04ee541a09c 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -24,7 +24,7 @@
24# the same distribution terms as the rest of that program. 24# the same distribution terms as the rest of that program.
25# 25#
26# Generated by gnulib-tool. 26# Generated by gnulib-tool.
27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value mktime strftime sys_stat 27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value lstat mktime readlink strftime symlink sys_stat
28 28
29VPATH = @srcdir@ 29VPATH = @srcdir@
30pkgdatadir = $(datadir)/@PACKAGE@ 30pkgdatadir = $(datadir)/@PACKAGE@
@@ -55,11 +55,13 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \
55 $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/gl-comp.m4 \ 55 $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/gl-comp.m4 \
56 $(top_srcdir)/m4/gnulib-common.m4 \ 56 $(top_srcdir)/m4/gnulib-common.m4 \
57 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/longlong.m4 \ 57 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/longlong.m4 \
58 $(top_srcdir)/m4/md5.m4 $(top_srcdir)/m4/mktime.m4 \ 58 $(top_srcdir)/m4/lstat.m4 $(top_srcdir)/m4/md5.m4 \
59 $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/st_dm_mode.m4 \ 59 $(top_srcdir)/m4/mktime.m4 $(top_srcdir)/m4/multiarch.m4 \
60 $(top_srcdir)/m4/stdbool.m4 $(top_srcdir)/m4/stddef_h.m4 \ 60 $(top_srcdir)/m4/readlink.m4 $(top_srcdir)/m4/st_dm_mode.m4 \
61 $(top_srcdir)/m4/stdint.m4 $(top_srcdir)/m4/stdlib_h.m4 \ 61 $(top_srcdir)/m4/stat.m4 $(top_srcdir)/m4/stdbool.m4 \
62 $(top_srcdir)/m4/strftime.m4 $(top_srcdir)/m4/sys_stat_h.m4 \ 62 $(top_srcdir)/m4/stddef_h.m4 $(top_srcdir)/m4/stdint.m4 \
63 $(top_srcdir)/m4/stdlib_h.m4 $(top_srcdir)/m4/strftime.m4 \
64 $(top_srcdir)/m4/symlink.m4 $(top_srcdir)/m4/sys_stat_h.m4 \
63 $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \ 65 $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \
64 $(top_srcdir)/m4/tm_gmtoff.m4 $(top_srcdir)/m4/unistd_h.m4 \ 66 $(top_srcdir)/m4/tm_gmtoff.m4 $(top_srcdir)/m4/unistd_h.m4 \
65 $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/configure.in 67 $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/configure.in
@@ -602,10 +604,11 @@ BUILT_SOURCES = arg-nonnull.h c++defs.h $(GETOPT_H) $(STDBOOL_H) \
602 $(STDDEF_H) $(STDINT_H) stdlib.h sys/stat.h time.h unistd.h \ 604 $(STDDEF_H) $(STDINT_H) stdlib.h sys/stat.h time.h unistd.h \
603 warn-on-use.h 605 warn-on-use.h
604EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \ 606EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \
605 md5.c md5.h ftoastr.c ftoastr.h filemode.c filemode.h \ 607 md5.c md5.h dosname.h ftoastr.c ftoastr.h filemode.c \
606 getloadavg.c getopt.c getopt.in.h getopt1.c getopt_int.h \ 608 filemode.h getloadavg.c getopt.c getopt.in.h getopt1.c \
607 intprops.h mktime-internal.h mktime.c stdbool.in.h stddef.in.h \ 609 getopt_int.h intprops.h lstat.c mktime-internal.h mktime.c \
608 stdint.in.h stdlib.in.h strftime.c strftime.h sys_stat.in.h \ 610 readlink.c stat.c stdbool.in.h stddef.in.h stdint.in.h \
611 stdlib.in.h strftime.c strftime.h symlink.c sys_stat.in.h \
609 time.in.h time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h 612 time.in.h time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h
610MOSTLYCLEANDIRS = sys 613MOSTLYCLEANDIRS = sys
611MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \ 614MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \
@@ -619,7 +622,8 @@ libgnu_a_SOURCES = dtoastr.c gettext.h ignore-value.h
619libgnu_a_LIBADD = $(gl_LIBOBJS) 622libgnu_a_LIBADD = $(gl_LIBOBJS)
620libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 623libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
621EXTRA_libgnu_a_SOURCES = md5.c ftoastr.c filemode.c getloadavg.c \ 624EXTRA_libgnu_a_SOURCES = md5.c ftoastr.c filemode.c getloadavg.c \
622 getopt.c getopt1.c mktime.c strftime.c time_r.c 625 getopt.c getopt1.c lstat.c mktime.c readlink.c stat.c \
626 strftime.c symlink.c time_r.c
623ARG_NONNULL_H = arg-nonnull.h 627ARG_NONNULL_H = arg-nonnull.h
624CXXDEFS_H = c++defs.h 628CXXDEFS_H = c++defs.h
625WARN_ON_USE_H = warn-on-use.h 629WARN_ON_USE_H = warn-on-use.h
@@ -678,9 +682,13 @@ distclean-compile:
678@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getloadavg.Po@am__quote@ 682@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getloadavg.Po@am__quote@
679@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ 683@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
680@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@ 684@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
685@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
681@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@ 686@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@
682@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@ 687@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@
688@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readlink.Po@am__quote@
689@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@
683@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strftime.Po@am__quote@ 690@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strftime.Po@am__quote@
691@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/symlink.Po@am__quote@
684@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_r.Po@am__quote@ 692@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_r.Po@am__quote@
685 693
686.c.o: 694.c.o:
diff --git a/lib/dosname.h b/lib/dosname.h
new file mode 100644
index 00000000000..acdd03b156e
--- /dev/null
+++ b/lib/dosname.h
@@ -0,0 +1,53 @@
1/* File names on MS-DOS/Windows systems.
2
3 Copyright (C) 2000-2001, 2004-2006, 2009-2011 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 From Paul Eggert and Jim Meyering. */
19
20#ifndef _DOSNAME_H
21#define _DOSNAME_H
22
23#if (defined _WIN32 || defined __WIN32__ || \
24 defined __MSDOS__ || defined __CYGWIN__ || \
25 defined __EMX__ || defined __DJGPP__)
26 /* This internal macro assumes ASCII, but all hosts that support drive
27 letters use ASCII. */
28# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \
29 <= 'z' - 'a')
30# define FILE_SYSTEM_PREFIX_LEN(Filename) \
31 (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
32# ifndef __CYGWIN__
33# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
34# endif
35# define ISSLASH(C) ((C) == '/' || (C) == '\\')
36#else
37# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
38# define ISSLASH(C) ((C) == '/')
39#endif
40
41#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
42# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
43#endif
44
45#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
46# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
47# else
48# define IS_ABSOLUTE_FILE_NAME(F) \
49 (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
50#endif
51#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
52
53#endif /* DOSNAME_H_ */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 53cc3815254..b5fd4a358db 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -9,7 +9,7 @@
9# the same distribution terms as the rest of that program. 9# the same distribution terms as the rest of that program.
10# 10#
11# Generated by gnulib-tool. 11# Generated by gnulib-tool.
12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value mktime strftime sys_stat 12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value lstat mktime readlink strftime symlink sys_stat
13 13
14 14
15MOSTLYCLEANFILES += core *.stackdump 15MOSTLYCLEANFILES += core *.stackdump
@@ -78,6 +78,13 @@ EXTRA_libgnu_a_SOURCES += md5.c
78 78
79## end gnulib module crypto/md5 79## end gnulib module crypto/md5
80 80
81## begin gnulib module dosname
82
83
84EXTRA_DIST += dosname.h
85
86## end gnulib module dosname
87
81## begin gnulib module dtoastr 88## begin gnulib module dtoastr
82 89
83libgnu_a_SOURCES += dtoastr.c 90libgnu_a_SOURCES += dtoastr.c
@@ -151,6 +158,15 @@ EXTRA_DIST += intprops.h
151 158
152## end gnulib module intprops 159## end gnulib module intprops
153 160
161## begin gnulib module lstat
162
163
164EXTRA_DIST += lstat.c
165
166EXTRA_libgnu_a_SOURCES += lstat.c
167
168## end gnulib module lstat
169
154## begin gnulib module mktime 170## begin gnulib module mktime
155 171
156 172
@@ -160,6 +176,24 @@ EXTRA_libgnu_a_SOURCES += mktime.c
160 176
161## end gnulib module mktime 177## end gnulib module mktime
162 178
179## begin gnulib module readlink
180
181
182EXTRA_DIST += readlink.c
183
184EXTRA_libgnu_a_SOURCES += readlink.c
185
186## end gnulib module readlink
187
188## begin gnulib module stat
189
190
191EXTRA_DIST += stat.c
192
193EXTRA_libgnu_a_SOURCES += stat.c
194
195## end gnulib module stat
196
163## begin gnulib module stdbool 197## begin gnulib module stdbool
164 198
165BUILT_SOURCES += $(STDBOOL_H) 199BUILT_SOURCES += $(STDBOOL_H)
@@ -344,6 +378,15 @@ EXTRA_libgnu_a_SOURCES += strftime.c
344 378
345## end gnulib module strftime 379## end gnulib module strftime
346 380
381## begin gnulib module symlink
382
383
384EXTRA_DIST += symlink.c
385
386EXTRA_libgnu_a_SOURCES += symlink.c
387
388## end gnulib module symlink
389
347## begin gnulib module sys_stat 390## begin gnulib module sys_stat
348 391
349BUILT_SOURCES += sys/stat.h 392BUILT_SOURCES += sys/stat.h
diff --git a/lib/lstat.c b/lib/lstat.c
new file mode 100644
index 00000000000..b26065ede28
--- /dev/null
+++ b/lib/lstat.c
@@ -0,0 +1,91 @@
1/* Work around a bug of lstat on some systems
2
3 Copyright (C) 1997-2006, 2008-2011 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* written by Jim Meyering */
19
20#include <config.h>
21
22#if !HAVE_LSTAT
23/* On systems that lack symlinks, our replacement <sys/stat.h> already
24 defined lstat as stat, so there is nothing further to do other than
25 avoid an empty file. */
26typedef int dummy;
27#else /* HAVE_LSTAT */
28
29/* Get the original definition of lstat. It might be defined as a macro. */
30# define __need_system_sys_stat_h
31# include <sys/types.h>
32# include <sys/stat.h>
33# undef __need_system_sys_stat_h
34
35static inline int
36orig_lstat (const char *filename, struct stat *buf)
37{
38 return lstat (filename, buf);
39}
40
41/* Specification. */
42# include <sys/stat.h>
43
44# include <string.h>
45# include <errno.h>
46
47/* lstat works differently on Linux and Solaris systems. POSIX (see
48 `pathname resolution' in the glossary) requires that programs like
49 `ls' take into consideration the fact that FILE has a trailing slash
50 when FILE is a symbolic link. On Linux and Solaris 10 systems, the
51 lstat function already has the desired semantics (in treating
52 `lstat ("symlink/", sbuf)' just like `lstat ("symlink/.", sbuf)',
53 but on Solaris 9 and earlier it does not.
54
55 If FILE has a trailing slash and specifies a symbolic link,
56 then use stat() to get more info on the referent of FILE.
57 If the referent is a non-directory, then set errno to ENOTDIR
58 and return -1. Otherwise, return stat's result. */
59
60int
61rpl_lstat (const char *file, struct stat *sbuf)
62{
63 size_t len;
64 int lstat_result = orig_lstat (file, sbuf);
65
66 if (lstat_result != 0)
67 return lstat_result;
68
69 /* This replacement file can blindly check against '/' rather than
70 using the ISSLASH macro, because all platforms with '\\' either
71 lack symlinks (mingw) or have working lstat (cygwin) and thus do
72 not compile this file. 0 len should have already been filtered
73 out above, with a failure return of ENOENT. */
74 len = strlen (file);
75 if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
76 return 0;
77
78 /* At this point, a trailing slash is only permitted on
79 symlink-to-dir; but it should have found information on the
80 directory, not the symlink. Call stat() to get info about the
81 link's referent. Our replacement stat guarantees valid results,
82 even if the symlink is not pointing to a directory. */
83 if (!S_ISLNK (sbuf->st_mode))
84 {
85 errno = ENOTDIR;
86 return -1;
87 }
88 return stat (file, sbuf);
89}
90
91#endif /* HAVE_LSTAT */
diff --git a/lib/readlink.c b/lib/readlink.c
new file mode 100644
index 00000000000..35d045b9a12
--- /dev/null
+++ b/lib/readlink.c
@@ -0,0 +1,74 @@
1/* Stub for readlink().
2 Copyright (C) 2003-2007, 2009-2011 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <unistd.h>
21
22#include <errno.h>
23#include <string.h>
24#include <sys/stat.h>
25
26#if !HAVE_READLINK
27
28/* readlink() substitute for systems that don't have a readlink() function,
29 such as DJGPP 2.03 and mingw32. */
30
31ssize_t
32readlink (const char *name, char *buf _GL_UNUSED,
33 size_t bufsize _GL_UNUSED)
34{
35 struct stat statbuf;
36
37 /* In general we should use lstat() here, not stat(). But on platforms
38 without symbolic links, lstat() - if it exists - would be equivalent to
39 stat(), therefore we can use stat(). This saves us a configure check. */
40 if (stat (name, &statbuf) >= 0)
41 errno = EINVAL;
42 return -1;
43}
44
45#else /* HAVE_READLINK */
46
47# undef readlink
48
49/* readlink() wrapper that uses correct types, for systems like cygwin
50 1.5.x where readlink returns int, and which rejects trailing slash,
51 for Solaris 9. */
52
53ssize_t
54rpl_readlink (const char *name, char *buf, size_t bufsize)
55{
56# if READLINK_TRAILING_SLASH_BUG
57 size_t len = strlen (name);
58 if (len && name[len - 1] == '/')
59 {
60 /* Even if name without the slash is a symlink to a directory,
61 both lstat() and stat() must resolve the trailing slash to
62 the directory rather than the symlink. We can therefore
63 safely use stat() to distinguish between EINVAL and
64 ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
65 struct stat st;
66 if (stat (name, &st) == 0)
67 errno = EINVAL;
68 return -1;
69 }
70# endif /* READLINK_TRAILING_SLASH_BUG */
71 return readlink (name, buf, bufsize);
72}
73
74#endif /* HAVE_READLINK */
diff --git a/lib/stat.c b/lib/stat.c
new file mode 100644
index 00000000000..cbc9100fd4d
--- /dev/null
+++ b/lib/stat.c
@@ -0,0 +1,105 @@
1/* Work around platform bugs in stat.
2 Copyright (C) 2009-2011 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* written by Eric Blake */
18
19#include <config.h>
20
21/* Get the original definition of stat. It might be defined as a macro. */
22#define __need_system_sys_stat_h
23#include <sys/types.h>
24#include <sys/stat.h>
25#undef __need_system_sys_stat_h
26
27static inline int
28orig_stat (const char *filename, struct stat *buf)
29{
30 return stat (filename, buf);
31}
32
33/* Specification. */
34#include <sys/stat.h>
35
36#include <errno.h>
37#include <limits.h>
38#include <stdbool.h>
39#include <string.h>
40#include "dosname.h"
41
42/* Store information about NAME into ST. Work around bugs with
43 trailing slashes. Mingw has other bugs (such as st_ino always
44 being 0 on success) which this wrapper does not work around. But
45 at least this implementation provides the ability to emulate fchdir
46 correctly. */
47
48int
49rpl_stat (char const *name, struct stat *st)
50{
51 int result = orig_stat (name, st);
52#if REPLACE_FUNC_STAT_FILE
53 /* Solaris 9 mistakenly succeeds when given a non-directory with a
54 trailing slash. */
55 if (result == 0 && !S_ISDIR (st->st_mode))
56 {
57 size_t len = strlen (name);
58 if (ISSLASH (name[len - 1]))
59 {
60 errno = ENOTDIR;
61 return -1;
62 }
63 }
64#endif /* REPLACE_FUNC_STAT_FILE */
65#if REPLACE_FUNC_STAT_DIR
66 if (result == -1 && errno == ENOENT)
67 {
68 /* Due to mingw's oddities, there are some directories (like
69 c:\) where stat() only succeeds with a trailing slash, and
70 other directories (like c:\windows) where stat() only
71 succeeds without a trailing slash. But we want the two to be
72 synonymous, since chdir() manages either style. Likewise, Mingw also
73 reports ENOENT for names longer than PATH_MAX, when we want
74 ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
75 Fortunately, mingw PATH_MAX is small enough for stack
76 allocation. */
77 char fixed_name[PATH_MAX + 1] = {0};
78 size_t len = strlen (name);
79 bool check_dir = false;
80 if (PATH_MAX <= len)
81 errno = ENAMETOOLONG;
82 else if (len)
83 {
84 strcpy (fixed_name, name);
85 if (ISSLASH (fixed_name[len - 1]))
86 {
87 check_dir = true;
88 while (len && ISSLASH (fixed_name[len - 1]))
89 fixed_name[--len] = '\0';
90 if (!len)
91 fixed_name[0] = '/';
92 }
93 else
94 fixed_name[len++] = '/';
95 result = orig_stat (fixed_name, st);
96 if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
97 {
98 result = -1;
99 errno = ENOTDIR;
100 }
101 }
102 }
103#endif /* REPLACE_FUNC_STAT_DIR */
104 return result;
105}
diff --git a/lib/symlink.c b/lib/symlink.c
new file mode 100644
index 00000000000..2896cc9655b
--- /dev/null
+++ b/lib/symlink.c
@@ -0,0 +1,57 @@
1/* Stub for symlink().
2 Copyright (C) 2009-2011 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <unistd.h>
21
22#include <errno.h>
23#include <string.h>
24#include <sys/stat.h>
25
26
27#if HAVE_SYMLINK
28
29# undef symlink
30
31/* Create a symlink, but reject trailing slash. */
32int
33rpl_symlink (char const *contents, char const *name)
34{
35 size_t len = strlen (name);
36 if (len && name[len - 1] == '/')
37 {
38 struct stat st;
39 if (lstat (name, &st) == 0)
40 errno = EEXIST;
41 return -1;
42 }
43 return symlink (contents, name);
44}
45
46#else /* !HAVE_SYMLINK */
47
48/* The system does not support symlinks. */
49int
50symlink (char const *contents _GL_UNUSED,
51 char const *name _GL_UNUSED)
52{
53 errno = ENOSYS;
54 return -1;
55}
56
57#endif /* !HAVE_SYMLINK */
diff --git a/m4/gl-comp.m4 b/m4/gl-comp.m4
index 10ec34da386..8bf5a64a5f9 100644
--- a/m4/gl-comp.m4
+++ b/m4/gl-comp.m4
@@ -29,6 +29,7 @@ AC_DEFUN([gl_EARLY],
29 # Code from module arg-nonnull: 29 # Code from module arg-nonnull:
30 # Code from module c++defs: 30 # Code from module c++defs:
31 # Code from module crypto/md5: 31 # Code from module crypto/md5:
32 # Code from module dosname:
32 # Code from module dtoastr: 33 # Code from module dtoastr:
33 # Code from module extensions: 34 # Code from module extensions:
34 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 35 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
@@ -40,13 +41,17 @@ AC_DEFUN([gl_EARLY],
40 # Code from module ignore-value: 41 # Code from module ignore-value:
41 # Code from module include_next: 42 # Code from module include_next:
42 # Code from module intprops: 43 # Code from module intprops:
44 # Code from module lstat:
43 # Code from module mktime: 45 # Code from module mktime:
44 # Code from module multiarch: 46 # Code from module multiarch:
47 # Code from module readlink:
48 # Code from module stat:
45 # Code from module stdbool: 49 # Code from module stdbool:
46 # Code from module stddef: 50 # Code from module stddef:
47 # Code from module stdint: 51 # Code from module stdint:
48 # Code from module stdlib: 52 # Code from module stdlib:
49 # Code from module strftime: 53 # Code from module strftime:
54 # Code from module symlink:
50 # Code from module sys_stat: 55 # Code from module sys_stat:
51 # Code from module time: 56 # Code from module time:
52 # Code from module time_r: 57 # Code from module time_r:
@@ -74,6 +79,7 @@ AC_DEFUN([gl_INIT],
74 # Code from module c++defs: 79 # Code from module c++defs:
75 # Code from module crypto/md5: 80 # Code from module crypto/md5:
76 gl_MD5 81 gl_MD5
82 # Code from module dosname:
77 # Code from module dtoastr: 83 # Code from module dtoastr:
78 AC_REQUIRE([gl_C99_STRTOLD]) 84 AC_REQUIRE([gl_C99_STRTOLD])
79 # Code from module extensions: 85 # Code from module extensions:
@@ -94,11 +100,20 @@ AC_DEFUN([gl_INIT],
94 AC_REQUIRE([AC_C_INLINE]) 100 AC_REQUIRE([AC_C_INLINE])
95 # Code from module include_next: 101 # Code from module include_next:
96 # Code from module intprops: 102 # Code from module intprops:
103 # Code from module lstat:
104 gl_FUNC_LSTAT
105 gl_SYS_STAT_MODULE_INDICATOR([lstat])
97 # Code from module mktime: 106 # Code from module mktime:
98 gl_FUNC_MKTIME 107 gl_FUNC_MKTIME
99 gl_TIME_MODULE_INDICATOR([mktime]) 108 gl_TIME_MODULE_INDICATOR([mktime])
100 # Code from module multiarch: 109 # Code from module multiarch:
101 gl_MULTIARCH 110 gl_MULTIARCH
111 # Code from module readlink:
112 gl_FUNC_READLINK
113 gl_UNISTD_MODULE_INDICATOR([readlink])
114 # Code from module stat:
115 gl_FUNC_STAT
116 gl_SYS_STAT_MODULE_INDICATOR([stat])
102 # Code from module stdbool: 117 # Code from module stdbool:
103 AM_STDBOOL_H 118 AM_STDBOOL_H
104 # Code from module stddef: 119 # Code from module stddef:
@@ -109,6 +124,9 @@ AC_DEFUN([gl_INIT],
109 gl_STDLIB_H 124 gl_STDLIB_H
110 # Code from module strftime: 125 # Code from module strftime:
111 gl_FUNC_GNU_STRFTIME 126 gl_FUNC_GNU_STRFTIME
127 # Code from module symlink:
128 gl_FUNC_SYMLINK
129 gl_UNISTD_MODULE_INDICATOR([symlink])
112 # Code from module sys_stat: 130 # Code from module sys_stat:
113 gl_HEADER_SYS_STAT_H 131 gl_HEADER_SYS_STAT_H
114 AC_PROG_MKDIR_P 132 AC_PROG_MKDIR_P
@@ -263,6 +281,7 @@ AC_DEFUN([gl_FILE_LIST], [
263 build-aux/arg-nonnull.h 281 build-aux/arg-nonnull.h
264 build-aux/c++defs.h 282 build-aux/c++defs.h
265 build-aux/warn-on-use.h 283 build-aux/warn-on-use.h
284 lib/dosname.h
266 lib/dtoastr.c 285 lib/dtoastr.c
267 lib/filemode.c 286 lib/filemode.c
268 lib/filemode.h 287 lib/filemode.h
@@ -276,16 +295,20 @@ AC_DEFUN([gl_FILE_LIST], [
276 lib/gettext.h 295 lib/gettext.h
277 lib/ignore-value.h 296 lib/ignore-value.h
278 lib/intprops.h 297 lib/intprops.h
298 lib/lstat.c
279 lib/md5.c 299 lib/md5.c
280 lib/md5.h 300 lib/md5.h
281 lib/mktime-internal.h 301 lib/mktime-internal.h
282 lib/mktime.c 302 lib/mktime.c
303 lib/readlink.c
304 lib/stat.c
283 lib/stdbool.in.h 305 lib/stdbool.in.h
284 lib/stddef.in.h 306 lib/stddef.in.h
285 lib/stdint.in.h 307 lib/stdint.in.h
286 lib/stdlib.in.h 308 lib/stdlib.in.h
287 lib/strftime.c 309 lib/strftime.c
288 lib/strftime.h 310 lib/strftime.h
311 lib/symlink.c
289 lib/sys_stat.in.h 312 lib/sys_stat.in.h
290 lib/time.in.h 313 lib/time.in.h
291 lib/time_r.c 314 lib/time_r.c
@@ -299,15 +322,19 @@ AC_DEFUN([gl_FILE_LIST], [
299 m4/gnulib-common.m4 322 m4/gnulib-common.m4
300 m4/include_next.m4 323 m4/include_next.m4
301 m4/longlong.m4 324 m4/longlong.m4
325 m4/lstat.m4
302 m4/md5.m4 326 m4/md5.m4
303 m4/mktime.m4 327 m4/mktime.m4
304 m4/multiarch.m4 328 m4/multiarch.m4
329 m4/readlink.m4
305 m4/st_dm_mode.m4 330 m4/st_dm_mode.m4
331 m4/stat.m4
306 m4/stdbool.m4 332 m4/stdbool.m4
307 m4/stddef_h.m4 333 m4/stddef_h.m4
308 m4/stdint.m4 334 m4/stdint.m4
309 m4/stdlib_h.m4 335 m4/stdlib_h.m4
310 m4/strftime.m4 336 m4/strftime.m4
337 m4/symlink.m4
311 m4/sys_stat_h.m4 338 m4/sys_stat_h.m4
312 m4/time_h.m4 339 m4/time_h.m4
313 m4/time_r.m4 340 m4/time_r.m4
diff --git a/m4/lstat.m4 b/m4/lstat.m4
new file mode 100644
index 00000000000..b9b22a6b20e
--- /dev/null
+++ b/m4/lstat.m4
@@ -0,0 +1,69 @@
1# serial 21
2
3# Copyright (C) 1997-2001, 2003-2011 Free Software Foundation, Inc.
4#
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9dnl From Jim Meyering.
10
11AC_DEFUN([gl_FUNC_LSTAT],
12[
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 dnl If lstat does not exist, the replacement <sys/stat.h> does
15 dnl "#define lstat stat", and lstat.c is a no-op.
16 AC_CHECK_FUNCS_ONCE([lstat])
17 if test $ac_cv_func_lstat = yes; then
18 AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
19 if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
20 dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ([lstat]).
21 REPLACE_LSTAT=1
22 fi
23 # Prerequisites of lib/lstat.c.
24 AC_REQUIRE([AC_C_INLINE])
25 else
26 HAVE_LSTAT=0
27 fi
28])
29
30# Redefine AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, because it is no longer
31# maintained in Autoconf.
32AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
33[
34 AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
35 [ac_cv_func_lstat_dereferences_slashed_symlink],
36 [rm -f conftest.sym conftest.file
37 echo >conftest.file
38 if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
39 AC_RUN_IFELSE(
40 [AC_LANG_PROGRAM(
41 [AC_INCLUDES_DEFAULT],
42 [[struct stat sbuf;
43 /* Linux will dereference the symlink and fail, as required by
44 POSIX. That is better in the sense that it means we will not
45 have to compile and use the lstat wrapper. */
46 return lstat ("conftest.sym/", &sbuf) == 0;
47 ]])],
48 [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
49 [ac_cv_func_lstat_dereferences_slashed_symlink=no],
50 [# When cross-compiling, be pessimistic so we will end up using the
51 # replacement version of lstat that checks for trailing slashes and
52 # calls lstat a second time when necessary.
53 ac_cv_func_lstat_dereferences_slashed_symlink=no
54 ])
55 else
56 # If the 'ln -s' command failed, then we probably don't even
57 # have an lstat function.
58 ac_cv_func_lstat_dereferences_slashed_symlink=no
59 fi
60 rm -f conftest.sym conftest.file
61 ])
62 test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
63 AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
64 [Define to 1 if `lstat' dereferences a symlink specified
65 with a trailing slash.])
66 if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then
67 AC_LIBOBJ([lstat])
68 fi
69])
diff --git a/m4/readlink.m4 b/m4/readlink.m4
new file mode 100644
index 00000000000..a502ca560fe
--- /dev/null
+++ b/m4/readlink.m4
@@ -0,0 +1,62 @@
1# readlink.m4 serial 9
2dnl Copyright (C) 2003, 2007, 2009-2011 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_READLINK],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_CHECK_FUNCS_ONCE([readlink])
11 if test $ac_cv_func_readlink = no; then
12 HAVE_READLINK=0
13 AC_LIBOBJ([readlink])
14 gl_PREREQ_READLINK
15 else
16 AC_CACHE_CHECK([whether readlink signature is correct],
17 [gl_cv_decl_readlink_works],
18 [AC_COMPILE_IFELSE(
19 [AC_LANG_PROGRAM(
20 [[#include <unistd.h>
21 /* Cause compilation failure if original declaration has wrong type. */
22 ssize_t readlink (const char *, char *, size_t);]])],
23 [gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])])
24 dnl Solaris 9 ignores trailing slash.
25 dnl FreeBSD 7.2 dereferences only one level of links with trailing slash.
26 AC_CACHE_CHECK([whether readlink handles trailing slash correctly],
27 [gl_cv_func_readlink_works],
28 [# We have readlink, so assume ln -s works.
29 ln -s conftest.no-such conftest.link
30 ln -s conftest.link conftest.lnk2
31 AC_RUN_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <unistd.h>
34]], [[char buf[20];
35 return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])],
36 [gl_cv_func_readlink_works=yes], [gl_cv_func_readlink_works=no],
37 [gl_cv_func_readlink_works="guessing no"])
38 rm -f conftest.link conftest.lnk2])
39 if test "$gl_cv_func_readlink_works" != yes; then
40 AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink
41 fails to recognize a trailing slash.])
42 REPLACE_READLINK=1
43 AC_LIBOBJ([readlink])
44 elif test "$gl_cv_decl_readlink_works" != yes; then
45 REPLACE_READLINK=1
46 AC_LIBOBJ([readlink])
47 fi
48 fi
49])
50
51# Like gl_FUNC_READLINK, except prepare for separate compilation (no AC_LIBOBJ).
52AC_DEFUN([gl_FUNC_READLINK_SEPARATE],
53[
54 AC_CHECK_FUNCS_ONCE([readlink])
55 gl_PREREQ_READLINK
56])
57
58# Prerequisites of lib/readlink.c.
59AC_DEFUN([gl_PREREQ_READLINK],
60[
61 :
62])
diff --git a/m4/stat.m4 b/m4/stat.m4
new file mode 100644
index 00000000000..27f82d5a91a
--- /dev/null
+++ b/m4/stat.m4
@@ -0,0 +1,66 @@
1# serial 7
2
3# Copyright (C) 2009-2011 Free Software Foundation, Inc.
4#
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9AC_DEFUN([gl_FUNC_STAT],
10[
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
13 AC_CHECK_FUNCS_ONCE([lstat])
14 dnl mingw is the only known platform where stat(".") and stat("./") differ
15 AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
16 [gl_cv_func_stat_dir_slash],
17 [AC_RUN_IFELSE(
18 [AC_LANG_PROGRAM(
19 [[#include <sys/stat.h>
20]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
21 [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
22 [case $host_os in
23 mingw*) gl_cv_func_stat_dir_slash="guessing no";;
24 *) gl_cv_func_stat_dir_slash="guessing yes";;
25 esac])])
26 dnl AIX 7.1, Solaris 9 mistakenly succeed on stat("file/")
27 dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/")
28 AC_CACHE_CHECK([whether stat handles trailing slashes on files],
29 [gl_cv_func_stat_file_slash],
30 [touch conftest.tmp
31 # Assume that if we have lstat, we can also check symlinks.
32 if test $ac_cv_func_lstat = yes; then
33 ln -s conftest.tmp conftest.lnk
34 fi
35 AC_RUN_IFELSE(
36 [AC_LANG_PROGRAM(
37 [[#include <sys/stat.h>
38]], [[int result = 0;
39 struct stat st;
40 if (!stat ("conftest.tmp/", &st))
41 result |= 1;
42#if HAVE_LSTAT
43 if (!stat ("conftest.lnk/", &st))
44 result |= 2;
45#endif
46 return result;
47 ]])],
48 [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
49 [gl_cv_func_stat_file_slash="guessing no"])
50 rm -f conftest.tmp conftest.lnk])
51 case $gl_cv_func_stat_dir_slash in
52 *no) REPLACE_STAT=1
53 AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
54 help when passed a directory name with a trailing slash]);;
55 esac
56 case $gl_cv_func_stat_file_slash in
57 *no) REPLACE_STAT=1
58 AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
59 help when passed a file name with a trailing slash]);;
60 esac
61 if test $REPLACE_STAT = 1; then
62 AC_LIBOBJ([stat])
63 dnl Prerequisites of lib/stat.c.
64 AC_REQUIRE([AC_C_INLINE])
65 fi
66])
diff --git a/m4/symlink.m4 b/m4/symlink.m4
new file mode 100644
index 00000000000..917d5f0ec2c
--- /dev/null
+++ b/m4/symlink.m4
@@ -0,0 +1,45 @@
1# serial 4
2# See if we need to provide symlink replacement.
3
4dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved.
8
9# Written by Eric Blake.
10
11AC_DEFUN([gl_FUNC_SYMLINK],
12[
13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
14 AC_CHECK_FUNCS_ONCE([symlink])
15 dnl The best we can do on mingw is provide a dummy that always fails, so
16 dnl that compilation can proceed with fewer ifdefs. On FreeBSD 7.2, AIX 7.1,
17 dnl and Solaris 9, we want to fix a bug with trailing slash handling.
18 if test $ac_cv_func_symlink = no; then
19 HAVE_SYMLINK=0
20 AC_LIBOBJ([symlink])
21 else
22 AC_CACHE_CHECK([whether symlink handles trailing slash correctly],
23 [gl_cv_func_symlink_works],
24 [AC_RUN_IFELSE(
25 [AC_LANG_PROGRAM(
26 [[#include <unistd.h>
27 ]],
28 [[int result = 0;
29 if (!symlink ("a", "conftest.link/"))
30 result |= 1;
31 if (symlink ("conftest.f", "conftest.lnk2"))
32 result |= 2;
33 else if (!symlink ("a", "conftest.lnk2/"))
34 result |= 4;
35 return result;
36 ]])],
37 [gl_cv_func_symlink_works=yes], [gl_cv_func_symlink_works=no],
38 [gl_cv_func_symlink_works="guessing no"])
39 rm -f conftest.f conftest.link conftest.lnk2])
40 if test "$gl_cv_func_symlink_works" != yes; then
41 REPLACE_SYMLINK=1
42 AC_LIBOBJ([symlink])
43 fi
44 fi
45])
diff --git a/src/ChangeLog b/src/ChangeLog
index 0e5e295a622..34e28866144 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12011-03-02 Paul Eggert <eggert@cs.ucla.edu>
2
3 Work around some portability problems with symlinks.
4
5 * fileio.c (Fmake_symbolic_link): Treat ENOSYS specially, and
6 generate a special message for it. Suggested by Eli Zaretskii in
7 <http://lists.gnu.org/archive/html/emacs-devel/2011-02/msg00995.html>.
8 (Frename_file, Fmake_symbolic_link, Ffile_symlink_p):
9 Simplify the code by assuming that the readlink and symlink calls
10 exist, even if they always fail on this host.
11 (Ffile_readable_p): Likewise, for fifos.
12 * config.in: Regenerate.
13
12011-02-27 Chong Yidong <cyd@stupidchicken.com> 142011-02-27 Chong Yidong <cyd@stupidchicken.com>
2 15
3 * frame.c (store_frame_param): Don't store value directly in 16 * frame.c (store_frame_param): Don't store value directly in
diff --git a/src/config.in b/src/config.in
index ded8c6b292a..4e49b4df170 100644
--- a/src/config.in
+++ b/src/config.in
@@ -576,6 +576,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
576/* Define to 1 if you have the `random' function. */ 576/* Define to 1 if you have the `random' function. */
577#undef HAVE_RANDOM 577#undef HAVE_RANDOM
578 578
579/* Define to 1 if you have the `readlink' function. */
580#undef HAVE_READLINK
581
579/* Define to 1 if you have the `recvfrom' function. */ 582/* Define to 1 if you have the `recvfrom' function. */
580#undef HAVE_RECVFROM 583#undef HAVE_RECVFROM
581 584
@@ -696,6 +699,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
696/* Define if struct stat has an st_dm_mode member. */ 699/* Define if struct stat has an st_dm_mode member. */
697#undef HAVE_ST_DM_MODE 700#undef HAVE_ST_DM_MODE
698 701
702/* Define to 1 if you have the `symlink' function. */
703#undef HAVE_SYMLINK
704
699/* Define to 1 if you have the `sync' function. */ 705/* Define to 1 if you have the `sync' function. */
700#undef HAVE_SYNC 706#undef HAVE_SYNC
701 707
@@ -897,6 +903,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
897/* Define to 1 if localtime caches TZ. */ 903/* Define to 1 if localtime caches TZ. */
898#undef LOCALTIME_CACHE 904#undef LOCALTIME_CACHE
899 905
906/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
907 slash. */
908#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
909
900/* String giving fallback POP mail host. */ 910/* String giving fallback POP mail host. */
901#undef MAILHOST 911#undef MAILHOST
902 912
@@ -968,10 +978,21 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
968 'ptrdiff_t'. */ 978 'ptrdiff_t'. */
969#undef PTRDIFF_T_SUFFIX 979#undef PTRDIFF_T_SUFFIX
970 980
981/* Define to 1 if readlink fails to recognize a trailing slash. */
982#undef READLINK_TRAILING_SLASH_BUG
983
971/* Define REL_ALLOC if you want to use the relocating allocator for buffer 984/* Define REL_ALLOC if you want to use the relocating allocator for buffer
972 space. */ 985 space. */
973#undef REL_ALLOC 986#undef REL_ALLOC
974 987
988/* Define to 1 if stat needs help when passed a directory name with a trailing
989 slash */
990#undef REPLACE_FUNC_STAT_DIR
991
992/* Define to 1 if stat needs help when passed a file name with a trailing
993 slash */
994#undef REPLACE_FUNC_STAT_FILE
995
975/* Define as the return type of signal handlers (`int' or `void'). */ 996/* Define as the return type of signal handlers (`int' or `void'). */
976#undef RETSIGTYPE 997#undef RETSIGTYPE
977 998
diff --git a/src/fileio.c b/src/fileio.c
index 0225e0bf3a9..18e9dbe9680 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2178,14 +2178,11 @@ This is what happens in interactive use with M-x. */)
2178 if (errno == EXDEV) 2178 if (errno == EXDEV)
2179 { 2179 {
2180 int count; 2180 int count;
2181#ifdef S_IFLNK
2182 symlink_target = Ffile_symlink_p (file); 2181 symlink_target = Ffile_symlink_p (file);
2183 if (! NILP (symlink_target)) 2182 if (! NILP (symlink_target))
2184 Fmake_symbolic_link (symlink_target, newname, 2183 Fmake_symbolic_link (symlink_target, newname,
2185 NILP (ok_if_already_exists) ? Qnil : Qt); 2184 NILP (ok_if_already_exists) ? Qnil : Qt);
2186 else 2185 else if (!NILP (Ffile_directory_p (file)))
2187#endif
2188 if (!NILP (Ffile_directory_p (file)))
2189 call4 (Qcopy_directory, file, newname, Qt, Qnil); 2186 call4 (Qcopy_directory, file, newname, Qt, Qnil);
2190 else 2187 else
2191 /* We have already prompted if it was an integer, so don't 2188 /* We have already prompted if it was an integer, so don't
@@ -2197,11 +2194,7 @@ This is what happens in interactive use with M-x. */)
2197 count = SPECPDL_INDEX (); 2194 count = SPECPDL_INDEX ();
2198 specbind (Qdelete_by_moving_to_trash, Qnil); 2195 specbind (Qdelete_by_moving_to_trash, Qnil);
2199 2196
2200 if (!NILP (Ffile_directory_p (file)) 2197 if (!NILP (Ffile_directory_p (file)) && NILP (symlink_target))
2201#ifdef S_IFLNK
2202 && NILP (symlink_target)
2203#endif
2204 )
2205 call2 (Qdelete_directory, file, Qt); 2198 call2 (Qdelete_directory, file, Qt);
2206 else 2199 else
2207 Fdelete_file (file, Qnil); 2200 Fdelete_file (file, Qnil);
@@ -2311,7 +2304,6 @@ This happens for interactive use with M-x. */)
2311 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, 2304 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename,
2312 linkname, ok_if_already_exists)); 2305 linkname, ok_if_already_exists));
2313 2306
2314#ifdef S_IFLNK
2315 encoded_filename = ENCODE_FILE (filename); 2307 encoded_filename = ENCODE_FILE (filename);
2316 encoded_linkname = ENCODE_FILE (linkname); 2308 encoded_linkname = ENCODE_FILE (linkname);
2317 2309
@@ -2333,17 +2325,17 @@ This happens for interactive use with M-x. */)
2333 return Qnil; 2325 return Qnil;
2334 } 2326 }
2335 } 2327 }
2328 if (errno == ENOSYS)
2329 {
2330 UNGCPRO;
2331 xsignal1 (Qfile_error,
2332 build_string ("Symbolic links are not supported"));
2333 }
2336 2334
2337 report_file_error ("Making symbolic link", list2 (filename, linkname)); 2335 report_file_error ("Making symbolic link", list2 (filename, linkname));
2338 } 2336 }
2339 UNGCPRO; 2337 UNGCPRO;
2340 return Qnil; 2338 return Qnil;
2341
2342#else
2343 UNGCPRO;
2344 xsignal1 (Qfile_error, build_string ("Symbolic links are not supported"));
2345
2346#endif /* S_IFLNK */
2347} 2339}
2348 2340
2349 2341
@@ -2482,7 +2474,7 @@ See also `file-exists-p' and `file-attributes'. */)
2482 return Qnil; 2474 return Qnil;
2483#else /* not DOS_NT and not macintosh */ 2475#else /* not DOS_NT and not macintosh */
2484 flags = O_RDONLY; 2476 flags = O_RDONLY;
2485#if defined (S_IFIFO) && defined (O_NONBLOCK) 2477#ifdef O_NONBLOCK
2486 /* Opening a fifo without O_NONBLOCK can wait. 2478 /* Opening a fifo without O_NONBLOCK can wait.
2487 We don't want to wait. But we don't want to mess wth O_NONBLOCK 2479 We don't want to wait. But we don't want to mess wth O_NONBLOCK
2488 except in the case of a fifo, on a system which handles it. */ 2480 except in the case of a fifo, on a system which handles it. */
@@ -2584,6 +2576,10 @@ points to a nonexistent file. */)
2584 (Lisp_Object filename) 2576 (Lisp_Object filename)
2585{ 2577{
2586 Lisp_Object handler; 2578 Lisp_Object handler;
2579 char *buf;
2580 int bufsize;
2581 int valsize;
2582 Lisp_Object val;
2587 2583
2588 CHECK_STRING (filename); 2584 CHECK_STRING (filename);
2589 filename = Fexpand_file_name (filename, Qnil); 2585 filename = Fexpand_file_name (filename, Qnil);
@@ -2594,13 +2590,6 @@ points to a nonexistent file. */)
2594 if (!NILP (handler)) 2590 if (!NILP (handler))
2595 return call2 (handler, Qfile_symlink_p, filename); 2591 return call2 (handler, Qfile_symlink_p, filename);
2596 2592
2597#ifdef S_IFLNK
2598 {
2599 char *buf;
2600 int bufsize;
2601 int valsize;
2602 Lisp_Object val;
2603
2604 filename = ENCODE_FILE (filename); 2593 filename = ENCODE_FILE (filename);
2605 2594
2606 bufsize = 50; 2595 bufsize = 50;
@@ -2635,10 +2624,6 @@ points to a nonexistent file. */)
2635 xfree (buf); 2624 xfree (buf);
2636 val = DECODE_FILE (val); 2625 val = DECODE_FILE (val);
2637 return val; 2626 return val;
2638 }
2639#else /* not S_IFLNK */
2640 return Qnil;
2641#endif /* not S_IFLNK */
2642} 2627}
2643 2628
2644DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0, 2629DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0,