aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2011-02-22 11:30:07 -0800
committerPaul Eggert2011-02-22 11:30:07 -0800
commitae0d725005539d9259efac6a81ff8fdd45eb69a6 (patch)
treec721b530409b355281537abc7b058bdb2697ee01 /lib
parent8d40723d1e9661840a67ca7be9c5b073526ab421 (diff)
downloademacs-ae0d725005539d9259efac6a81ff8fdd45eb69a6.tar.gz
emacs-ae0d725005539d9259efac6a81ff8fdd45eb69a6.zip
[ChangeLog]
Work around some portability problems with symlinks. * Makefile.in (GNULIB_MODULES): Add lstat, readlink, symlink. * configure.in (lstat, HAVE_LSTAT): Remove special hack. * lib/lstat.c, lib/readlink.c, lib/stat.c, lib/symlink.c: * m4/dos.m4, m4/lstat.m4, m4/readlink.m4, m4/stat.m4, m4/symlink.m4: New files, automatically generated from gnulib. * aclocal.m4, configure, lib/Makefile.in, lib/gnulib.mk: * lib/stdlib.in.h, m4/gl-comp.m4, m4/stdlib_h.m4: Regenerate. 2011-02-22 Paul Eggert <eggert@cs.ucla.edu> [src/ChangeLog] Work around some portability problems with symlinks. * fileio.c (Frename_file, Fmake_symbolic_link, Ffile_symlink_p): Simplify the code by assuming that the readlink and symlink calls exist, even if they always fail on this host. (Ffile_readable_p): Likewise, for fifos. * config.in: Regenerate.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.in44
-rw-r--r--lib/gnulib.mk42
-rw-r--r--lib/lstat.c91
-rw-r--r--lib/readlink.c74
-rw-r--r--lib/stat.c104
-rw-r--r--lib/stdlib.in.h30
-rw-r--r--lib/symlink.c57
7 files changed, 427 insertions, 15 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 48e7b1d6507..e9b9f2eb86e 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@
@@ -50,16 +50,18 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
50subdir = lib 50subdir = lib
51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ 52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \
53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \ 53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/dos.m4 \
54 $(top_srcdir)/m4/filemode.m4 $(top_srcdir)/m4/getloadavg.m4 \ 54 $(top_srcdir)/m4/extensions.m4 $(top_srcdir)/m4/filemode.m4 \
55 $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/gl-comp.m4 \ 55 $(top_srcdir)/m4/getloadavg.m4 $(top_srcdir)/m4/getopt.m4 \
56 $(top_srcdir)/m4/gnulib-common.m4 \ 56 $(top_srcdir)/m4/gl-comp.m4 $(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
@@ -179,6 +181,7 @@ GNULIB_LINKAT = @GNULIB_LINKAT@
179GNULIB_LSEEK = @GNULIB_LSEEK@ 181GNULIB_LSEEK = @GNULIB_LSEEK@
180GNULIB_LSTAT = @GNULIB_LSTAT@ 182GNULIB_LSTAT = @GNULIB_LSTAT@
181GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@ 183GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@
184GNULIB_MBTOWC = @GNULIB_MBTOWC@
182GNULIB_MKDIRAT = @GNULIB_MKDIRAT@ 185GNULIB_MKDIRAT = @GNULIB_MKDIRAT@
183GNULIB_MKDTEMP = @GNULIB_MKDTEMP@ 186GNULIB_MKDTEMP = @GNULIB_MKDTEMP@
184GNULIB_MKFIFO = @GNULIB_MKFIFO@ 187GNULIB_MKFIFO = @GNULIB_MKFIFO@
@@ -225,6 +228,7 @@ GNULIB_UNLOCKPT = @GNULIB_UNLOCKPT@
225GNULIB_UNSETENV = @GNULIB_UNSETENV@ 228GNULIB_UNSETENV = @GNULIB_UNSETENV@
226GNULIB_USLEEP = @GNULIB_USLEEP@ 229GNULIB_USLEEP = @GNULIB_USLEEP@
227GNULIB_UTIMENSAT = @GNULIB_UTIMENSAT@ 230GNULIB_UTIMENSAT = @GNULIB_UTIMENSAT@
231GNULIB_WCTOMB = @GNULIB_WCTOMB@
228GNULIB_WRITE = @GNULIB_WRITE@ 232GNULIB_WRITE = @GNULIB_WRITE@
229GNULIB__EXIT = @GNULIB__EXIT@ 233GNULIB__EXIT = @GNULIB__EXIT@
230GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ 234GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@
@@ -452,6 +456,7 @@ REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@
452REPLACE_LSEEK = @REPLACE_LSEEK@ 456REPLACE_LSEEK = @REPLACE_LSEEK@
453REPLACE_LSTAT = @REPLACE_LSTAT@ 457REPLACE_LSTAT = @REPLACE_LSTAT@
454REPLACE_MALLOC = @REPLACE_MALLOC@ 458REPLACE_MALLOC = @REPLACE_MALLOC@
459REPLACE_MBTOWC = @REPLACE_MBTOWC@
455REPLACE_MKDIR = @REPLACE_MKDIR@ 460REPLACE_MKDIR = @REPLACE_MKDIR@
456REPLACE_MKFIFO = @REPLACE_MKFIFO@ 461REPLACE_MKFIFO = @REPLACE_MKFIFO@
457REPLACE_MKNOD = @REPLACE_MKNOD@ 462REPLACE_MKNOD = @REPLACE_MKNOD@
@@ -478,6 +483,7 @@ REPLACE_UNLINKAT = @REPLACE_UNLINKAT@
478REPLACE_UNSETENV = @REPLACE_UNSETENV@ 483REPLACE_UNSETENV = @REPLACE_UNSETENV@
479REPLACE_USLEEP = @REPLACE_USLEEP@ 484REPLACE_USLEEP = @REPLACE_USLEEP@
480REPLACE_UTIMENSAT = @REPLACE_UTIMENSAT@ 485REPLACE_UTIMENSAT = @REPLACE_UTIMENSAT@
486REPLACE_WCTOMB = @REPLACE_WCTOMB@
481REPLACE_WRITE = @REPLACE_WRITE@ 487REPLACE_WRITE = @REPLACE_WRITE@
482RSVG_CFLAGS = @RSVG_CFLAGS@ 488RSVG_CFLAGS = @RSVG_CFLAGS@
483RSVG_LIBS = @RSVG_LIBS@ 489RSVG_LIBS = @RSVG_LIBS@
@@ -600,9 +606,10 @@ BUILT_SOURCES = arg-nonnull.h c++defs.h $(GETOPT_H) $(STDBOOL_H) \
600EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \ 606EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \
601 md5.c md5.h ftoastr.c ftoastr.h filemode.c filemode.h \ 607 md5.c md5.h ftoastr.c ftoastr.h filemode.c filemode.h \
602 getloadavg.c getopt.c getopt.in.h getopt1.c getopt_int.h \ 608 getloadavg.c getopt.c getopt.in.h getopt1.c getopt_int.h \
603 intprops.h mktime-internal.h mktime.c stdbool.in.h stddef.in.h \ 609 intprops.h lstat.c mktime-internal.h mktime.c readlink.c \
604 stdint.in.h stdlib.in.h strftime.c strftime.h sys_stat.in.h \ 610 stat.c stdbool.in.h stddef.in.h stdint.in.h stdlib.in.h \
605 time.in.h time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h 611 strftime.c strftime.h symlink.c sys_stat.in.h time.in.h \
612 time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h
606MOSTLYCLEANDIRS = sys 613MOSTLYCLEANDIRS = sys
607MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \ 614MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \
608 c++defs.h c++defs.h-t getopt.h getopt.h-t stdbool.h \ 615 c++defs.h c++defs.h-t getopt.h getopt.h-t stdbool.h \
@@ -615,7 +622,8 @@ libgnu_a_SOURCES = dtoastr.c gettext.h ignore-value.h
615libgnu_a_LIBADD = $(gl_LIBOBJS) 622libgnu_a_LIBADD = $(gl_LIBOBJS)
616libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 623libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
617EXTRA_libgnu_a_SOURCES = md5.c ftoastr.c filemode.c getloadavg.c \ 624EXTRA_libgnu_a_SOURCES = md5.c ftoastr.c filemode.c getloadavg.c \
618 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
619ARG_NONNULL_H = arg-nonnull.h 627ARG_NONNULL_H = arg-nonnull.h
620CXXDEFS_H = c++defs.h 628CXXDEFS_H = c++defs.h
621WARN_ON_USE_H = warn-on-use.h 629WARN_ON_USE_H = warn-on-use.h
@@ -674,9 +682,13 @@ distclean-compile:
674@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getloadavg.Po@am__quote@ 682@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getloadavg.Po@am__quote@
675@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ 683@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
676@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@
677@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@ 686@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@
678@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@
679@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@
680@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@
681 693
682.c.o: 694.c.o:
@@ -1001,6 +1013,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1001 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ 1013 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
1002 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ 1014 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
1003 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ 1015 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
1016 -e 's|@''GNULIB_MBTOWC''@|$(GNULIB_MBTOWC)|g' \
1004 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ 1017 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
1005 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ 1018 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
1006 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \ 1019 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
@@ -1019,6 +1032,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1019 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \ 1032 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
1020 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ 1033 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
1021 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ 1034 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
1035 -e 's|@''GNULIB_WCTOMB''@|$(GNULIB_WCTOMB)|g' \
1022 < $(srcdir)/stdlib.in.h | \ 1036 < $(srcdir)/stdlib.in.h | \
1023 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ 1037 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
1024 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 1038 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
@@ -1047,6 +1061,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1047 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ 1061 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
1048 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 1062 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
1049 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 1063 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
1064 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
1050 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 1065 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
1051 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 1066 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
1052 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ 1067 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
@@ -1054,6 +1069,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1054 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ 1069 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
1055 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 1070 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
1056 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ 1071 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
1072 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
1057 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1073 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1058 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 1074 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1059 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 1075 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 32bf5714d17..1d918ff5fae 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
@@ -151,6 +151,15 @@ EXTRA_DIST += intprops.h
151 151
152## end gnulib module intprops 152## end gnulib module intprops
153 153
154## begin gnulib module lstat
155
156
157EXTRA_DIST += lstat.c
158
159EXTRA_libgnu_a_SOURCES += lstat.c
160
161## end gnulib module lstat
162
154## begin gnulib module mktime 163## begin gnulib module mktime
155 164
156 165
@@ -160,6 +169,24 @@ EXTRA_libgnu_a_SOURCES += mktime.c
160 169
161## end gnulib module mktime 170## end gnulib module mktime
162 171
172## begin gnulib module readlink
173
174
175EXTRA_DIST += readlink.c
176
177EXTRA_libgnu_a_SOURCES += readlink.c
178
179## end gnulib module readlink
180
181## begin gnulib module stat
182
183
184EXTRA_DIST += stat.c
185
186EXTRA_libgnu_a_SOURCES += stat.c
187
188## end gnulib module stat
189
163## begin gnulib module stdbool 190## begin gnulib module stdbool
164 191
165BUILT_SOURCES += $(STDBOOL_H) 192BUILT_SOURCES += $(STDBOOL_H)
@@ -267,6 +294,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
267 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ 294 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
268 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ 295 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
269 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ 296 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
297 -e 's|@''GNULIB_MBTOWC''@|$(GNULIB_MBTOWC)|g' \
270 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ 298 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
271 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ 299 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
272 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \ 300 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
@@ -285,6 +313,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
285 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \ 313 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
286 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ 314 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
287 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ 315 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
316 -e 's|@''GNULIB_WCTOMB''@|$(GNULIB_WCTOMB)|g' \
288 < $(srcdir)/stdlib.in.h | \ 317 < $(srcdir)/stdlib.in.h | \
289 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ 318 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
290 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 319 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
@@ -313,6 +342,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
313 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ 342 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
314 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 343 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
315 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 344 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
345 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
316 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 346 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
317 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 347 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
318 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ 348 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
@@ -320,6 +350,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
320 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ 350 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
321 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 351 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
322 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ 352 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
353 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
323 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 354 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
324 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 355 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
325 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 356 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
@@ -340,6 +371,15 @@ EXTRA_libgnu_a_SOURCES += strftime.c
340 371
341## end gnulib module strftime 372## end gnulib module strftime
342 373
374## begin gnulib module symlink
375
376
377EXTRA_DIST += symlink.c
378
379EXTRA_libgnu_a_SOURCES += symlink.c
380
381## end gnulib module symlink
382
343## begin gnulib module sys_stat 383## begin gnulib module sys_stat
344 384
345BUILT_SOURCES += sys/stat.h 385BUILT_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..f16d9144afc
--- /dev/null
+++ b/lib/stat.c
@@ -0,0 +1,104 @@
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
41/* Store information about NAME into ST. Work around bugs with
42 trailing slashes. Mingw has other bugs (such as st_ino always
43 being 0 on success) which this wrapper does not work around. But
44 at least this implementation provides the ability to emulate fchdir
45 correctly. */
46
47int
48rpl_stat (char const *name, struct stat *st)
49{
50 int result = orig_stat (name, st);
51#if REPLACE_FUNC_STAT_FILE
52 /* Solaris 9 mistakenly succeeds when given a non-directory with a
53 trailing slash. */
54 if (result == 0 && !S_ISDIR (st->st_mode))
55 {
56 size_t len = strlen (name);
57 if (ISSLASH (name[len - 1]))
58 {
59 errno = ENOTDIR;
60 return -1;
61 }
62 }
63#endif /* REPLACE_FUNC_STAT_FILE */
64#if REPLACE_FUNC_STAT_DIR
65 if (result == -1 && errno == ENOENT)
66 {
67 /* Due to mingw's oddities, there are some directories (like
68 c:\) where stat() only succeeds with a trailing slash, and
69 other directories (like c:\windows) where stat() only
70 succeeds without a trailing slash. But we want the two to be
71 synonymous, since chdir() manages either style. Likewise, Mingw also
72 reports ENOENT for names longer than PATH_MAX, when we want
73 ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
74 Fortunately, mingw PATH_MAX is small enough for stack
75 allocation. */
76 char fixed_name[PATH_MAX + 1] = {0};
77 size_t len = strlen (name);
78 bool check_dir = false;
79 if (PATH_MAX <= len)
80 errno = ENAMETOOLONG;
81 else if (len)
82 {
83 strcpy (fixed_name, name);
84 if (ISSLASH (fixed_name[len - 1]))
85 {
86 check_dir = true;
87 while (len && ISSLASH (fixed_name[len - 1]))
88 fixed_name[--len] = '\0';
89 if (!len)
90 fixed_name[0] = '/';
91 }
92 else
93 fixed_name[len++] = '/';
94 result = orig_stat (fixed_name, st);
95 if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
96 {
97 result = -1;
98 errno = ENOTDIR;
99 }
100 }
101 }
102#endif /* REPLACE_FUNC_STAT_DIR */
103 return result;
104}
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 62d18c62811..2697a4bd1db 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -274,6 +274,21 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
274 "use gnulib module malloc-posix for portability"); 274 "use gnulib module malloc-posix for portability");
275#endif 275#endif
276 276
277/* Convert a multibyte character to a wide character. */
278#if @GNULIB_MBTOWC@
279# if @REPLACE_MBTOWC@
280# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
281# undef mbtowc
282# define mbtowc rpl_mbtowc
283# endif
284_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
285_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
286# else
287_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
288# endif
289_GL_CXXALIASWARN (mbtowc);
290#endif
291
277#if @GNULIB_MKDTEMP@ 292#if @GNULIB_MKDTEMP@
278/* Create a unique temporary directory from TEMPLATE. 293/* Create a unique temporary directory from TEMPLATE.
279 The last six characters of TEMPLATE must be "XXXXXX"; 294 The last six characters of TEMPLATE must be "XXXXXX";
@@ -723,6 +738,21 @@ _GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
723# endif 738# endif
724#endif 739#endif
725 740
741/* Convert a wide character to a multibyte character. */
742#if @GNULIB_WCTOMB@
743# if @REPLACE_WCTOMB@
744# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
745# undef wctomb
746# define wctomb rpl_wctomb
747# endif
748_GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc));
749_GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
750# else
751_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
752# endif
753_GL_CXXALIASWARN (wctomb);
754#endif
755
726 756
727#endif /* _GL_STDLIB_H */ 757#endif /* _GL_STDLIB_H */
728#endif /* _GL_STDLIB_H */ 758#endif /* _GL_STDLIB_H */
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 */