gnulib: upgrade to today's version
* tools/snippet/_Noreturn.h, tools/snippet/c++defs.h, tools/snippet/arg-nonnull.h, tools/snippet/warn-on-use.h: Rename to... * lib/_Noreturn.h, lib/c++defs.h, lib/arg-nonnull.h, lib/warn-on-use.h: ... these. * lib/filename.h, lib/getopt-cdefs.in.h, lib/getopt-core.h, lib/getopt-ext.h, lib/getopt-pfx-core.h, lib/getopt-pfx-ext.h, lib/localtime-buffer.c, lib/localtime-buffer.h, lib/malloca.c, lib/malloca.h, lib/malloca.valgrind, lib/stat-w32.c, lib/stat-w32.h, m4/eealloc.m4, m4/localtime-buffer.m4, m4/malloca.m4: New files. * lib/argp-help.c, lib/argp-parse.c, lib/error.c, lib/float.in.h, lib/getopt1.c, lib/getopt.c, lib/getopt.in.h, lib/getopt_int.h, lib/gettext.h, lib/gettimeofday.c, lib/intprops.h, lib/isatty.c, lib/limits.in.h, lib/localcharset.c, lib/Makefile.am, lib/mbrtowc.c, lib/mbsinit.c, lib/msvc-nothrow.c, lib/quotearg.c, lib/stat.c, lib/stdalign.in.h, lib/stdint.in.h, lib/string.in.h, lib/sys_stat.in.h, lib/sys_types.in.h, lib/tempname.c, lib/time.in.h, lib/unistd.in.h, lib/vasnprintf.c, lib/wchar.in.h, lib/wctype.in.h, lib/xalloc.h, lib/xalloc-oversized.h, m4/fcntl-o.m4, m4/float_h.m4, m4/getopt.m4, m4/gettimeofday.m4, m4/gnulib-common.m4, m4/gnulib-comp.m4, m4/include_next.m4, m4/largefile.m4, m4/lstat.m4, m4/mbrtowc.m4, m4/memchr.m4, m4/mkstemp.m4, m4/printf.m4, m4/sleep.m4, m4/stat.m4, m4/stdalign.m4, m4/stdint.m4, m4/strerror.m4, m4/string_h.m4, m4/sys_stat_h.m4, m4/sys_time_h.m4, m4/sys_types_h.m4, m4/time_h.m4, m4/unistd_h.m4, m4/wchar_h.m4, m4/wctype_h.m4, m4/wint_t.m4: Update.
This commit is contained in:
parent
aa8cf6ac92
commit
80d50c5665
81 changed files with 3458 additions and 1954 deletions
6
lib/.gitignore
vendored
6
lib/.gitignore
vendored
|
|
@ -1,13 +1,14 @@
|
|||
alloca.h
|
||||
arg-nonnull.h
|
||||
c++defs.h
|
||||
configmake.h
|
||||
dummy.c
|
||||
errno.h
|
||||
fcntl.h
|
||||
getopt-cdefs.h
|
||||
getopt.h
|
||||
libgnu.a
|
||||
limits.h
|
||||
stdalign.h
|
||||
stdint.h
|
||||
stdio.h
|
||||
stdlib.h
|
||||
string.h
|
||||
|
|
@ -16,7 +17,6 @@ sys/
|
|||
sysexits.h
|
||||
time.h
|
||||
unistd.h
|
||||
warn-on-use.h
|
||||
wchar.h
|
||||
wctype.h
|
||||
*.sed
|
||||
|
|
|
|||
139
lib/Makefile.am
139
lib/Makefile.am
|
|
@ -37,6 +37,7 @@ MOSTLYCLEANDIRS =
|
|||
CLEANFILES =
|
||||
DISTCLEANFILES =
|
||||
MAINTAINERCLEANFILES =
|
||||
# No GNU Make output.
|
||||
|
||||
AM_CPPFLAGS =
|
||||
AM_CFLAGS =
|
||||
|
|
@ -273,6 +274,13 @@ EXTRA_DIST += fcntl.in.h
|
|||
|
||||
## end gnulib module fcntl-h
|
||||
|
||||
## begin gnulib module filename
|
||||
|
||||
|
||||
EXTRA_DIST += filename.h
|
||||
|
||||
## end gnulib module filename
|
||||
|
||||
## begin gnulib module float
|
||||
|
||||
BUILT_SOURCES += $(FLOAT_H)
|
||||
|
|
@ -306,11 +314,11 @@ EXTRA_libgnu_la_SOURCES += float.c itold.c
|
|||
|
||||
## begin gnulib module getopt-posix
|
||||
|
||||
BUILT_SOURCES += $(GETOPT_H)
|
||||
BUILT_SOURCES += $(GETOPT_H) $(GETOPT_CDEFS_H)
|
||||
|
||||
# We need the following in order to create <getopt.h> when the system
|
||||
# doesn't have one that works with the given compiler.
|
||||
getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H)
|
||||
getopt.h: getopt.in.h $(top_builddir)/config.status
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
|
||||
|
|
@ -323,9 +331,18 @@ getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H)
|
|||
< $(srcdir)/getopt.in.h; \
|
||||
} > $@-t && \
|
||||
mv -f $@-t $@
|
||||
MOSTLYCLEANFILES += getopt.h getopt.h-t
|
||||
|
||||
EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h
|
||||
getopt-cdefs.h: getopt-cdefs.in.h $(top_builddir)/config.status
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \
|
||||
< $(srcdir)/getopt-cdefs.in.h; \
|
||||
} > $@-t && \
|
||||
mv -f $@-t $@
|
||||
|
||||
MOSTLYCLEANFILES += getopt.h getopt.h-t getopt-cdefs.h getopt-cdefs.h-t
|
||||
|
||||
EXTRA_DIST += getopt-cdefs.in.h getopt-core.h getopt-ext.h getopt-pfx-core.h getopt-pfx-ext.h getopt.c getopt.in.h getopt1.c getopt_int.h
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += getopt.c getopt1.c
|
||||
|
||||
|
|
@ -478,6 +495,15 @@ EXTRA_DIST += config.charset ref-add.sin ref-del.sin
|
|||
|
||||
## end gnulib module localcharset
|
||||
|
||||
## begin gnulib module localtime-buffer
|
||||
|
||||
|
||||
EXTRA_DIST += localtime-buffer.c localtime-buffer.h
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += localtime-buffer.c
|
||||
|
||||
## end gnulib module localtime-buffer
|
||||
|
||||
## begin gnulib module lstat
|
||||
|
||||
|
||||
|
|
@ -505,6 +531,14 @@ EXTRA_libgnu_la_SOURCES += malloc.c
|
|||
|
||||
## end gnulib module malloc-posix
|
||||
|
||||
## begin gnulib module malloca
|
||||
|
||||
libgnu_la_SOURCES += malloca.c
|
||||
|
||||
EXTRA_DIST += malloca.h malloca.valgrind
|
||||
|
||||
## end gnulib module malloca
|
||||
|
||||
## begin gnulib module mbrtowc
|
||||
|
||||
|
||||
|
|
@ -647,90 +681,57 @@ EXTRA_libgnu_la_SOURCES += sleep.c
|
|||
## begin gnulib module snippet/_Noreturn
|
||||
|
||||
# Because this Makefile snippet defines a variable used by other
|
||||
# gnulib Makefile snippets, it must be present in all Makefile.am that
|
||||
# gnulib Makefile snippets, it must be present in all makefiles that
|
||||
# need it. This is ensured by the applicability 'all' defined above.
|
||||
|
||||
_NORETURN_H=$(top_srcdir)/tools/snippet/_Noreturn.h
|
||||
_NORETURN_H=$(srcdir)/_Noreturn.h
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/tools/snippet/_Noreturn.h
|
||||
EXTRA_DIST += _Noreturn.h
|
||||
|
||||
## end gnulib module snippet/_Noreturn
|
||||
|
||||
## begin gnulib module snippet/arg-nonnull
|
||||
|
||||
# The BUILT_SOURCES created by this Makefile snippet are not used via #include
|
||||
# statements but through direct file reference. Therefore this snippet must be
|
||||
# present in all Makefile.am that need it. This is ensured by the applicability
|
||||
# 'all' defined above.
|
||||
# Because this Makefile snippet defines a variable used by other
|
||||
# gnulib Makefile snippets, it must be present in all makefiles that
|
||||
# need it. This is ensured by the applicability 'all' defined above.
|
||||
|
||||
BUILT_SOURCES += arg-nonnull.h
|
||||
# The arg-nonnull.h that gets inserted into generated .h files is the same as
|
||||
# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut
|
||||
# off.
|
||||
arg-nonnull.h: $(top_srcdir)/tools/snippet/arg-nonnull.h
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
sed -n -e '/GL_ARG_NONNULL/,$$p' \
|
||||
< $(top_srcdir)/tools/snippet/arg-nonnull.h \
|
||||
> $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
|
||||
ARG_NONNULL_H=$(srcdir)/arg-nonnull.h
|
||||
|
||||
ARG_NONNULL_H=arg-nonnull.h
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/tools/snippet/arg-nonnull.h
|
||||
EXTRA_DIST += arg-nonnull.h
|
||||
|
||||
## end gnulib module snippet/arg-nonnull
|
||||
|
||||
## begin gnulib module snippet/c++defs
|
||||
|
||||
# The BUILT_SOURCES created by this Makefile snippet are not used via #include
|
||||
# statements but through direct file reference. Therefore this snippet must be
|
||||
# present in all Makefile.am that need it. This is ensured by the applicability
|
||||
# 'all' defined above.
|
||||
# Because this Makefile snippet defines a variable used by other
|
||||
# gnulib Makefile snippets, it must be present in all makefiles that
|
||||
# need it. This is ensured by the applicability 'all' defined above.
|
||||
|
||||
BUILT_SOURCES += c++defs.h
|
||||
# The c++defs.h that gets inserted into generated .h files is the same as
|
||||
# build-aux/snippet/c++defs.h, except that it has the copyright header cut off.
|
||||
c++defs.h: $(top_srcdir)/tools/snippet/c++defs.h
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
sed -n -e '/_GL_CXXDEFS/,$$p' \
|
||||
< $(top_srcdir)/tools/snippet/c++defs.h \
|
||||
> $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += c++defs.h c++defs.h-t
|
||||
CXXDEFS_H=$(srcdir)/c++defs.h
|
||||
|
||||
CXXDEFS_H=c++defs.h
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/tools/snippet/c++defs.h
|
||||
EXTRA_DIST += c++defs.h
|
||||
|
||||
## end gnulib module snippet/c++defs
|
||||
|
||||
## begin gnulib module snippet/warn-on-use
|
||||
|
||||
BUILT_SOURCES += warn-on-use.h
|
||||
# The warn-on-use.h that gets inserted into generated .h files is the same as
|
||||
# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut
|
||||
# off.
|
||||
warn-on-use.h: $(top_srcdir)/tools/snippet/warn-on-use.h
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
sed -n -e '/^.ifndef/,$$p' \
|
||||
< $(top_srcdir)/tools/snippet/warn-on-use.h \
|
||||
> $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
|
||||
# Because this Makefile snippet defines a variable used by other
|
||||
# gnulib Makefile snippets, it must be present in all makefiles that
|
||||
# need it. This is ensured by the applicability 'all' defined above.
|
||||
|
||||
WARN_ON_USE_H=warn-on-use.h
|
||||
WARN_ON_USE_H=$(srcdir)/warn-on-use.h
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/tools/snippet/warn-on-use.h
|
||||
EXTRA_DIST += warn-on-use.h
|
||||
|
||||
## end gnulib module snippet/warn-on-use
|
||||
|
||||
## begin gnulib module stat
|
||||
|
||||
|
||||
EXTRA_DIST += stat.c
|
||||
EXTRA_DIST += stat-w32.c stat-w32.h stat.c
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += stat.c
|
||||
EXTRA_libgnu_la_SOURCES += stat-w32.c stat.c
|
||||
|
||||
## end gnulib module stat
|
||||
|
||||
|
|
@ -1163,6 +1164,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
|
|||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \
|
||||
-e 's/@''GNULIB_EXPLICIT_BZERO''@/$(GNULIB_EXPLICIT_BZERO)/g' \
|
||||
-e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \
|
||||
-e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \
|
||||
-e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \
|
||||
|
|
@ -1201,7 +1203,8 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
|
|||
-e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \
|
||||
-e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \
|
||||
< $(srcdir)/string.in.h | \
|
||||
sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
|
||||
sed -e 's|@''HAVE_EXPLICIT_BZERO''@|$(HAVE_EXPLICIT_BZERO)|g' \
|
||||
-e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
|
||||
-e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \
|
||||
-e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
|
||||
-e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \
|
||||
|
|
@ -1323,6 +1326,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
|
|||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
|
||||
-e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \
|
||||
-e 's|@''WINDOWS_STAT_TIMESPEC''@|$(WINDOWS_STAT_TIMESPEC)|g' \
|
||||
-e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \
|
||||
-e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \
|
||||
-e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
|
||||
|
|
@ -1336,6 +1340,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
|
|||
-e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \
|
||||
-e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \
|
||||
-e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \
|
||||
-e 's/@''GNULIB_OVERRIDES_STRUCT_STAT''@/$(GNULIB_OVERRIDES_STRUCT_STAT)/g' \
|
||||
-e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
|
||||
-e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
|
||||
-e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
|
||||
|
|
@ -1419,6 +1424,7 @@ sys/types.h: sys_types.in.h $(top_builddir)/config.status
|
|||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \
|
||||
-e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
|
||||
-e 's|@''WINDOWS_STAT_INODES''@|$(WINDOWS_STAT_INODES)|g' \
|
||||
< $(srcdir)/sys_types.in.h; \
|
||||
} > $@-t && \
|
||||
mv $@-t $@
|
||||
|
|
@ -1507,24 +1513,31 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
|
|||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
|
||||
-e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
|
||||
-e 's/@''GNULIB_CTIME''@/$(GNULIB_CTIME)/g' \
|
||||
-e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \
|
||||
-e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
|
||||
-e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
|
||||
-e 's/@''GNULIB_STRFTIME''@/$(GNULIB_STRFTIME)/g' \
|
||||
-e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
|
||||
-e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
|
||||
-e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
|
||||
-e 's/@''GNULIB_TIME_RZ''@/$(GNULIB_TIME_RZ)/g' \
|
||||
-e 's/@''GNULIB_TZSET''@/$(GNULIB_TZSET)/g' \
|
||||
-e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
|
||||
-e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
|
||||
-e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
|
||||
-e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
|
||||
-e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
|
||||
-e 's|@''HAVE_TZSET''@|$(HAVE_TZSET)|g' \
|
||||
-e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
|
||||
-e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
|
||||
-e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
|
||||
-e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
|
||||
-e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
|
||||
-e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
|
||||
-e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
|
||||
-e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
|
||||
-e 's|@''REPLACE_TZSET''@|$(REPLACE_TZSET)|g' \
|
||||
-e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
|
||||
-e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
|
||||
-e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
|
||||
|
|
@ -1599,6 +1612,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
|
|||
-e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \
|
||||
-e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \
|
||||
-e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/g' \
|
||||
-e 's/@''GNULIB_TRUNCATE''@/$(GNULIB_TRUNCATE)/g' \
|
||||
-e 's/@''GNULIB_TTYNAME_R''@/$(GNULIB_TTYNAME_R)/g' \
|
||||
-e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GNULIB_GL_UNISTD_H_GETOPT)/g' \
|
||||
-e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GNULIB_UNISTD_H_NONBLOCKING)/g' \
|
||||
|
|
@ -1636,6 +1650,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
|
|||
-e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
|
||||
-e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
|
||||
-e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
|
||||
-e 's|@''HAVE_TRUNCATE''@|$(HAVE_TRUNCATE)|g' \
|
||||
-e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
|
||||
-e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
|
||||
-e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
|
||||
|
|
@ -1677,6 +1692,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
|
|||
-e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
|
||||
-e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
|
||||
-e 's|@''REPLACE_SYMLINKAT''@|$(REPLACE_SYMLINKAT)|g' \
|
||||
-e 's|@''REPLACE_TRUNCATE''@|$(REPLACE_TRUNCATE)|g' \
|
||||
-e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
|
||||
-e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
|
||||
-e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
|
||||
|
|
@ -1736,6 +1752,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
|
|||
-e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
|
||||
-e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
|
||||
-e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
|
||||
-e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
|
||||
-e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' \
|
||||
-e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \
|
||||
-e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \
|
||||
|
|
@ -1776,6 +1793,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
|
|||
-e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \
|
||||
-e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \
|
||||
-e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \
|
||||
-e 's/@''GNULIB_WCSFTIME''@/$(GNULIB_WCSFTIME)/g' \
|
||||
< $(srcdir)/wchar.in.h | \
|
||||
sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
|
||||
-e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
|
||||
|
|
@ -1815,6 +1833,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
|
|||
-e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \
|
||||
-e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \
|
||||
-e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \
|
||||
-e 's|@''HAVE_WCSFTIME''@|$(HAVE_WCSFTIME)|g' \
|
||||
-e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
|
||||
-e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
|
||||
| \
|
||||
|
|
@ -1831,6 +1850,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
|
|||
-e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
|
||||
-e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
|
||||
-e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
|
||||
-e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
|
||||
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
|
||||
-e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
|
||||
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
|
||||
|
|
@ -1858,6 +1878,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H
|
|||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
|
||||
-e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
|
||||
-e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' \
|
||||
-e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \
|
||||
-e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \
|
||||
|
|
|
|||
10
lib/_Noreturn.h
Normal file
10
lib/_Noreturn.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#if !defined _Noreturn && __STDC_VERSION__ < 201112
|
||||
# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
|
||||
|| 0x5110 <= __SUNPRO_C)
|
||||
# define _Noreturn __attribute__ ((__noreturn__))
|
||||
# elif 1200 <= _MSC_VER
|
||||
# define _Noreturn __declspec (noreturn)
|
||||
# else
|
||||
# define _Noreturn
|
||||
# endif
|
||||
#endif
|
||||
26
lib/arg-nonnull.h
Normal file
26
lib/arg-nonnull.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
||||
|
|
@ -880,7 +880,8 @@ hol_append (struct hol *hol, struct hol *more)
|
|||
|
||||
/* Fix up the short options pointers from HOL. */
|
||||
for (e = entries, left = hol->num_entries; left > 0; e++, left--)
|
||||
e->short_options += (short_options - hol->short_options);
|
||||
e->short_options
|
||||
= short_options + (e->short_options - hol->short_options);
|
||||
|
||||
/* Now add the short options from MORE, fixing up its entries
|
||||
too. */
|
||||
|
|
@ -1460,7 +1461,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
|
|||
}
|
||||
|
||||
/* Print the documentation for ARGP to STREAM; if POST is false, then
|
||||
everything preceeding a '\v' character in the documentation strings (or
|
||||
everything preceding a '\v' character in the documentation strings (or
|
||||
the whole string, for those with none) is printed, otherwise, everything
|
||||
following the '\v' character (nothing for strings without). Each separate
|
||||
bit of documentation is separated a blank line, and if PRE_BLANK is true,
|
||||
|
|
@ -1873,8 +1874,8 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
|
|||
char const *s = NULL;
|
||||
putc_unlocked (':', stream);
|
||||
putc_unlocked (' ', stream);
|
||||
# if HAVE_DECL_STRERROR_R
|
||||
# if STRERROR_R_CHAR_P
|
||||
# if GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R
|
||||
# if !GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P
|
||||
s = __strerror_r (errnum, buf, sizeof buf);
|
||||
# else
|
||||
if (__strerror_r (errnum, buf, sizeof buf) == 0)
|
||||
|
|
|
|||
|
|
@ -740,12 +740,15 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
|
|||
}
|
||||
}
|
||||
else
|
||||
/* A long option. We use shifts instead of masking for extracting
|
||||
the user value in order to preserve the sign. */
|
||||
err =
|
||||
group_parse (&parser->groups[group_key - 1], &parser->state,
|
||||
(opt << GROUP_BITS) >> GROUP_BITS,
|
||||
parser->opt_data.optarg);
|
||||
/* A long option. Preserve the sign in the user key, without
|
||||
invoking undefined behavior. Assume two's complement. */
|
||||
{
|
||||
int user_key =
|
||||
((opt & (1 << (USER_BITS - 1))) ? ~USER_MASK : 0) | (opt & USER_MASK);
|
||||
err =
|
||||
group_parse (&parser->groups[group_key - 1], &parser->state,
|
||||
user_key, parser->opt_data.optarg);
|
||||
}
|
||||
|
||||
if (err == EBADKEY)
|
||||
/* At least currently, an option not recognized is an error in the
|
||||
|
|
|
|||
316
lib/c++defs.h
Normal file
316
lib/c++defs.h
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* Begin/end the GNULIB_NAMESPACE namespace. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
|
||||
# define _GL_END_NAMESPACE }
|
||||
#else
|
||||
# define _GL_BEGIN_NAMESPACE
|
||||
# define _GL_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping rpl_func in an object with an inline conversion operator
|
||||
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::rpl_func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::rpl_func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping func in an object with an inline conversion operator
|
||||
avoids a reference to func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !__OPTIMIZE__
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !__OPTIMIZE__
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
||||
23
lib/error.c
23
lib/error.c
|
|
@ -98,28 +98,32 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
|
|||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
/* Get _get_osfhandle. */
|
||||
# include "msvc-nothrow.h"
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* The gnulib override of fcntl is not needed in this file. */
|
||||
# undef fcntl
|
||||
|
||||
# if !HAVE_DECL_STRERROR_R
|
||||
# if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R)
|
||||
# ifndef HAVE_DECL_STRERROR_R
|
||||
"this configure-time declaration test was not run"
|
||||
# endif
|
||||
# if STRERROR_R_CHAR_P
|
||||
char *strerror_r ();
|
||||
char *strerror_r (int errnum, char *buf, size_t buflen);
|
||||
# else
|
||||
int strerror_r ();
|
||||
int strerror_r (int errnum, char *buf, size_t buflen);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#define program_name getprogname ()
|
||||
|
||||
# if HAVE_STRERROR_R || defined strerror_r
|
||||
# if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r
|
||||
# define __strerror_r strerror_r
|
||||
# endif /* HAVE_STRERROR_R || defined strerror_r */
|
||||
# endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */
|
||||
#endif /* not _LIBC */
|
||||
|
||||
#if !_LIBC
|
||||
|
|
@ -172,9 +176,9 @@ print_errno_message (int errnum)
|
|||
{
|
||||
char const *s;
|
||||
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
#if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R
|
||||
char errbuf[1024];
|
||||
# if _LIBC || STRERROR_R_CHAR_P
|
||||
# if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P)
|
||||
s = __strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
# else
|
||||
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
|
||||
|
|
@ -268,7 +272,6 @@ error_tail (int status, int errnum, const char *message, va_list args)
|
|||
else
|
||||
#endif
|
||||
vfprintf (stderr, message, args);
|
||||
va_end (args);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
|
|
@ -318,6 +321,7 @@ error (int status, int errnum, const char *message, ...)
|
|||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
va_end (args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
|
|
@ -388,6 +392,7 @@ error_at_line (int status, int errnum, const char *file_name,
|
|||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
va_end (args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
|
|
|
|||
54
lib/filename.h
Normal file
54
lib/filename.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* Basic filename support macros.
|
||||
Copyright (C) 2001-2004, 2007-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _FILENAME_H
|
||||
#define _FILENAME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Pathname support.
|
||||
ISSLASH(C) tests whether C is a directory separator character.
|
||||
IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
|
||||
it may be concatenated to a directory pathname.
|
||||
IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
|
||||
*/
|
||||
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
|
||||
/* Native Windows, Cygwin, OS/2, DOS */
|
||||
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
|
||||
# define HAS_DEVICE(P) \
|
||||
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
|
||||
&& (P)[1] == ':')
|
||||
# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
|
||||
# define IS_PATH_WITH_DIR(P) \
|
||||
(strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
|
||||
#else
|
||||
/* Unix */
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
|
||||
# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) 0
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FILENAME_H */
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
|
||||
precision in the compiler but 64 bits of precision at runtime. See
|
||||
<http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. */
|
||||
#if defined __i386__ && defined __FreeBSD__
|
||||
#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
|
||||
/* Number of mantissa units, in base FLT_RADIX. */
|
||||
# undef LDBL_MANT_DIG
|
||||
# define LDBL_MANT_DIG 64
|
||||
|
|
|
|||
67
lib/getopt-cdefs.in.h
Normal file
67
lib/getopt-cdefs.in.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* getopt-on-non-glibc compatibility macros.
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of gnulib.
|
||||
Unlike most of the getopt implementation, it is NOT shared
|
||||
with the GNU C Library.
|
||||
|
||||
gnulib is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
gnulib is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with gnulib; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_CDEFS_H
|
||||
#define _GETOPT_CDEFS_H 1
|
||||
|
||||
/* This header should not be used directly; include getopt.h or
|
||||
unistd.h instead. It does not have a protective #error, because
|
||||
the guard macro for getopt.h in gnulib is not fixed. */
|
||||
|
||||
/* getopt-core.h and getopt-ext.h are shared with GNU libc, and expect
|
||||
a number of the internal macros supplied to GNU libc's headers by
|
||||
sys/cdefs.h. Provide fallback definitions for all of them. */
|
||||
#if @HAVE_SYS_CDEFS_H@
|
||||
# include <sys/cdefs.h>
|
||||
#endif
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# ifdef __cplusplus
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# else
|
||||
# define __BEGIN_DECLS /* nothing */
|
||||
# endif
|
||||
#endif
|
||||
#ifndef __END_DECLS
|
||||
# ifdef __cplusplus
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __END_DECLS /* nothing */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC_PREREQ
|
||||
# if defined __GNUC__ && defined __GNUC_VERSION__
|
||||
# define __GNUC_PREREQ(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
# else
|
||||
# define __GNUC_PREREQ(maj, min) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __THROW
|
||||
# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
||||
# define __THROW throw ()
|
||||
# else
|
||||
# define __THROW
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _GETOPT_CDEFS_H */
|
||||
96
lib/getopt-core.h
Normal file
96
lib/getopt-core.h
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/* Declarations for getopt (basic, portable features only).
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library and is also part of gnulib.
|
||||
Patches to this file should be submitted to both projects.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_CORE_H
|
||||
#define _GETOPT_CORE_H 1
|
||||
|
||||
/* This header should not be used directly; include getopt.h or
|
||||
unistd.h instead. Unlike most bits headers, it does not have
|
||||
a protective #error, because the guard macro for getopt.h in
|
||||
gnulib is not fixed. */
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* For communication from 'getopt' to the caller.
|
||||
When 'getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when 'ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to 'getopt'.
|
||||
|
||||
On entry to 'getopt', zero means this is the first call; initialize.
|
||||
|
||||
When 'getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, 'optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message 'getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, 'optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in 'optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU 'getopt'.
|
||||
|
||||
The argument '--' causes premature termination of argument
|
||||
scanning, explicitly telling 'getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with '-', then non-option arguments are treated as
|
||||
arguments to the option '\1'. This behavior is specific to the GNU
|
||||
'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
|
||||
the environment, then do not permute arguments.
|
||||
|
||||
For standards compliance, the 'argv' argument has the type
|
||||
char *const *, but this is inaccurate; if argument permutation is
|
||||
enabled, the argv array (not the strings it points to) must be
|
||||
writable. */
|
||||
|
||||
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _GETOPT_CORE_H */
|
||||
77
lib/getopt-ext.h
Normal file
77
lib/getopt-ext.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* Declarations for getopt (GNU extensions).
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library and is also part of gnulib.
|
||||
Patches to this file should be submitted to both projects.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_EXT_H
|
||||
#define _GETOPT_EXT_H 1
|
||||
|
||||
/* This header should not be used directly; include getopt.h instead.
|
||||
Unlike most bits headers, it does not have a protective #error,
|
||||
because the guard macro for getopt.h in gnulib is not fixed. */
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of 'struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field 'has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field 'flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field 'val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an 'int' to
|
||||
a compiled-in constant, such as set a value from 'optarg', set the
|
||||
option's 'flag' field to zero and its 'val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero 'flag' field, 'getopt'
|
||||
returns the contents of the 'val' field. */
|
||||
|
||||
struct option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the 'has_arg' field of 'struct option'. */
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _GETOPT_EXT_H */
|
||||
59
lib/getopt-pfx-core.h
Normal file
59
lib/getopt-pfx-core.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* getopt (basic, portable features) gnulib wrapper header.
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of gnulib.
|
||||
Unlike most of the getopt implementation, it is NOT shared
|
||||
with the GNU C Library.
|
||||
|
||||
gnulib is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
gnulib is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with gnulib; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_PFX_CORE_H
|
||||
#define _GETOPT_PFX_CORE_H 1
|
||||
|
||||
/* This header should not be used directly; include getopt.h or
|
||||
unistd.h instead. It does not have a protective #error, because
|
||||
the guard macro for getopt.h in gnulib is not fixed. */
|
||||
|
||||
/* Standalone applications should #define __GETOPT_PREFIX to an
|
||||
identifier that prefixes the external functions and variables
|
||||
defined in getopt-core.h and getopt-ext.h. Systematically
|
||||
rename identifiers so that they do not collide with the system
|
||||
functions and variables. Renaming avoids problems with some
|
||||
compilers and linkers. */
|
||||
#ifdef __GETOPT_PREFIX
|
||||
# ifndef __GETOPT_ID
|
||||
# define __GETOPT_CONCAT(x, y) x ## y
|
||||
# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
|
||||
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
|
||||
# endif
|
||||
# undef getopt
|
||||
# undef optarg
|
||||
# undef opterr
|
||||
# undef optind
|
||||
# undef optopt
|
||||
# define getopt __GETOPT_ID (getopt)
|
||||
# define optarg __GETOPT_ID (optarg)
|
||||
# define opterr __GETOPT_ID (opterr)
|
||||
# define optind __GETOPT_ID (optind)
|
||||
# define optopt __GETOPT_ID (optopt)
|
||||
|
||||
/* The system's getopt.h may have already included getopt-core.h to
|
||||
declare the unprefixed identifiers. Undef _GETOPT_CORE_H so that
|
||||
getopt-core.h declares them with prefixes. */
|
||||
# undef _GETOPT_CORE_H
|
||||
#endif
|
||||
|
||||
#include <getopt-core.h>
|
||||
|
||||
#endif /* _GETOPT_PFX_CORE_H */
|
||||
71
lib/getopt-pfx-ext.h
Normal file
71
lib/getopt-pfx-ext.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* getopt (GNU extensions) gnulib wrapper header.
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of gnulib.
|
||||
Unlike most of the getopt implementation, it is NOT shared
|
||||
with the GNU C Library.
|
||||
|
||||
gnulib is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
gnulib is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with gnulib; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_PFX_EXT_H
|
||||
#define _GETOPT_PFX_EXT_H 1
|
||||
|
||||
/* This header should not be used directly; include getopt.h instead.
|
||||
It does not have a protective #error, because the guard macro for
|
||||
getopt.h in gnulib is not fixed. */
|
||||
|
||||
/* Standalone applications should #define __GETOPT_PREFIX to an
|
||||
identifier that prefixes the external functions and variables
|
||||
defined in getopt-core.h and getopt-ext.h. Systematically
|
||||
rename identifiers so that they do not collide with the system
|
||||
functions and variables. Renaming avoids problems with some
|
||||
compilers and linkers. */
|
||||
#ifdef __GETOPT_PREFIX
|
||||
# ifndef __GETOPT_ID
|
||||
# define __GETOPT_CONCAT(x, y) x ## y
|
||||
# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
|
||||
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
|
||||
# endif
|
||||
# undef getopt_long
|
||||
# undef getopt_long_only
|
||||
# undef option
|
||||
# undef _getopt_internal
|
||||
# define getopt_long __GETOPT_ID (getopt_long)
|
||||
# define getopt_long_only __GETOPT_ID (getopt_long_only)
|
||||
# define option __GETOPT_ID (option)
|
||||
# define _getopt_internal __GETOPT_ID (getopt_internal)
|
||||
|
||||
/* The system's getopt.h may have already included getopt-ext.h to
|
||||
declare the unprefixed identifiers. Undef _GETOPT_EXT_H so that
|
||||
getopt-ext.h declares them with prefixes. */
|
||||
# undef _GETOPT_EXT_H
|
||||
#endif
|
||||
|
||||
/* Standalone applications get correct prototypes for getopt_long and
|
||||
getopt_long_only; they declare "char **argv". For backward
|
||||
compatibility with old applications, if __GETOPT_PREFIX is not
|
||||
defined, we supply GNU-libc-compatible, but incorrect, prototypes
|
||||
using "char *const *argv". (GNU libc is stuck with the incorrect
|
||||
prototypes, as they are baked into older versions of LSB.) */
|
||||
#ifndef __getopt_argv_const
|
||||
# if defined __GETOPT_PREFIX
|
||||
# define __getopt_argv_const /* empty */
|
||||
# else
|
||||
# define __getopt_argv_const const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <getopt-ext.h>
|
||||
|
||||
#endif /* _GETOPT_PFX_EXT_H */
|
||||
1436
lib/getopt.c
1436
lib/getopt.c
File diff suppressed because it is too large
Load diff
258
lib/getopt.in.h
258
lib/getopt.in.h
|
|
@ -1,20 +1,22 @@
|
|||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2017 Free Software
|
||||
Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of gnulib.
|
||||
Unlike most of the getopt implementation, it is NOT shared
|
||||
with the GNU C Library, which supplies a different version of
|
||||
this file.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
gnulib is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
gnulib is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with gnulib; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_GETOPT_H
|
||||
|
||||
|
|
@ -32,230 +34,28 @@
|
|||
# undef _GL_SYSTEM_GETOPT
|
||||
#endif
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _@GUARD_PREFIX@_GETOPT_H 1
|
||||
#endif
|
||||
#define _@GUARD_PREFIX@_GETOPT_H 1
|
||||
|
||||
/* Standalone applications should #define __GETOPT_PREFIX to an
|
||||
identifier that prefixes the external functions and variables
|
||||
defined in this header. When this happens, include the
|
||||
headers that might declare getopt so that they will not cause
|
||||
confusion if included after this file (if the system had <getopt.h>,
|
||||
we have already included it). Then systematically rename
|
||||
identifiers so that they do not collide with the system functions
|
||||
and variables. Renaming avoids problems with some compilers and
|
||||
linkers. */
|
||||
defined in getopt-core.h and getopt-ext.h. When this happens,
|
||||
include the headers that might declare getopt so that they will not
|
||||
cause confusion if included after this file (if the system had
|
||||
<getopt.h>, we have already included it). */
|
||||
#if defined __GETOPT_PREFIX
|
||||
# if !defined __need_getopt
|
||||
# if !@HAVE_GETOPT_H@
|
||||
# define __need_system_stdlib_h
|
||||
# include <stdlib.h>
|
||||
# undef __need_system_stdlib_h
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# undef __need_getopt
|
||||
# endif
|
||||
# undef __GETOPT_CONCAT
|
||||
# undef __GETOPT_XCONCAT
|
||||
# undef __GETOPT_ID
|
||||
# undef getopt
|
||||
# undef getopt_long
|
||||
# undef getopt_long_only
|
||||
# undef optarg
|
||||
# undef opterr
|
||||
# undef optind
|
||||
# undef optopt
|
||||
# undef option
|
||||
# undef _getopt_internal
|
||||
# define __GETOPT_CONCAT(x, y) x ## y
|
||||
# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
|
||||
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
|
||||
# define getopt __GETOPT_ID (getopt)
|
||||
# define getopt_long __GETOPT_ID (getopt_long)
|
||||
# define getopt_long_only __GETOPT_ID (getopt_long_only)
|
||||
# define optarg __GETOPT_ID (optarg)
|
||||
# define opterr __GETOPT_ID (opterr)
|
||||
# define optind __GETOPT_ID (optind)
|
||||
# define optopt __GETOPT_ID (optopt)
|
||||
# define option __GETOPT_ID (option)
|
||||
# define _getopt_internal __GETOPT_ID (getopt_internal)
|
||||
#endif
|
||||
|
||||
/* Standalone applications get correct prototypes for getopt_long and
|
||||
getopt_long_only; they declare "char **argv". libc uses prototypes
|
||||
with "char *const *argv" that are incorrect because getopt_long and
|
||||
getopt_long_only can permute argv; this is required for backward
|
||||
compatibility (e.g., for LSB 2.0.1).
|
||||
|
||||
This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
|
||||
but it caused redefinition warnings if both unistd.h and getopt.h were
|
||||
included, since unistd.h includes getopt.h having previously defined
|
||||
__need_getopt.
|
||||
|
||||
The only place where __getopt_argv_const is used is in definitions
|
||||
of getopt_long and getopt_long_only below, but these are visible
|
||||
only if __need_getopt is not defined, so it is quite safe to rewrite
|
||||
the conditional as follows:
|
||||
*/
|
||||
#if !defined __need_getopt
|
||||
# if defined __GETOPT_PREFIX
|
||||
# define __getopt_argv_const /* empty */
|
||||
# else
|
||||
# define __getopt_argv_const const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If __GNU_LIBRARY__ is not already defined, either we are being used
|
||||
standalone, or this is the first header included in the source file.
|
||||
If we are being used with glibc, we need to include <features.h>, but
|
||||
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
|
||||
not defined, include <ctype.h>, which will pull in <features.h> for us
|
||||
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
|
||||
doesn't flood the namespace with stuff the way some other headers do.) */
|
||||
#if !defined __GNU_LIBRARY__
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifndef __THROW
|
||||
# ifndef __GNUC_PREREQ
|
||||
# define __GNUC_PREREQ(maj, min) (0)
|
||||
# endif
|
||||
# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
||||
# define __THROW throw ()
|
||||
# else
|
||||
# define __THROW
|
||||
# if !@HAVE_GETOPT_H@
|
||||
# define __need_system_stdlib_h
|
||||
# include <stdlib.h>
|
||||
# undef __need_system_stdlib_h
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from 'getopt' to the caller.
|
||||
When 'getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when 'ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to 'getopt'.
|
||||
|
||||
On entry to 'getopt', zero means this is the first call; initialize.
|
||||
|
||||
When 'getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, 'optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message 'getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of 'struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field 'has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field 'flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field 'val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an 'int' to
|
||||
a compiled-in constant, such as set a value from 'optarg', set the
|
||||
option's 'flag' field to zero and its 'val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero 'flag' field, 'getopt'
|
||||
returns the contents of the 'val' field. */
|
||||
|
||||
# if !GNULIB_defined_struct_option
|
||||
struct option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
# define GNULIB_defined_struct_option 1
|
||||
# endif
|
||||
|
||||
/* Names for the values of the 'has_arg' field of 'struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, 'optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in 'optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU 'getopt'.
|
||||
|
||||
The argument '--' causes premature termination of argument
|
||||
scanning, explicitly telling 'getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with '-', then non-option arguments are treated as
|
||||
arguments to the option '\1'. This behavior is specific to the GNU
|
||||
'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
|
||||
the environment, then do not permute arguments. */
|
||||
|
||||
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
#ifndef __need_getopt
|
||||
extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
#include <getopt-cdefs.h>
|
||||
#include <getopt-pfx-core.h>
|
||||
#include <getopt-pfx-ext.h>
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_GETOPT_H */
|
||||
#endif /* _@GUARD_PREFIX@_GETOPT_H */
|
||||
|
|
|
|||
165
lib/getopt1.c
165
lib/getopt1.c
|
|
@ -1,56 +1,44 @@
|
|||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||
Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2017 Free Software
|
||||
Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Copyright (C) 1987-2017 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library and is also part of gnulib.
|
||||
Patches to this file should be submitted to both projects.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <getopt.h>
|
||||
#else
|
||||
#ifndef _LIBC
|
||||
# include <config.h>
|
||||
# include "getopt.h"
|
||||
#endif
|
||||
|
||||
#include "getopt.h"
|
||||
#include "getopt_int.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* This needs to come after some library #include
|
||||
to get __GNU_LIBRARY__ defined. */
|
||||
#ifdef __GNU_LIBRARY__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
int
|
||||
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, (char **) argv, options, long_options,
|
||||
opt_index, 0, 0);
|
||||
opt_index, 0, 0);
|
||||
}
|
||||
|
||||
int
|
||||
_getopt_long_r (int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
{
|
||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||
0, d, 0);
|
||||
0, d, 0);
|
||||
}
|
||||
|
||||
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||
|
|
@ -60,26 +48,27 @@ _getopt_long_r (int argc, char **argv, const char *options,
|
|||
|
||||
int
|
||||
getopt_long_only (int argc, char *__getopt_argv_const *argv,
|
||||
const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, (char **) argv, options, long_options,
|
||||
opt_index, 1, 0);
|
||||
opt_index, 1, 0);
|
||||
}
|
||||
|
||||
int
|
||||
_getopt_long_only_r (int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
{
|
||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||
1, d, 0);
|
||||
1, d, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
|
|
@ -93,74 +82,74 @@ main (int argc, char **argv)
|
|||
int option_index = 0;
|
||||
static const struct option long_options[] =
|
||||
{
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||
long_options, &option_index);
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
printf ("option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (" with arg %s", optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
{
|
||||
case 0:
|
||||
printf ("option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (" with arg %s", optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value '%s'\n", optarg);
|
||||
break;
|
||||
case 'c':
|
||||
printf ("option c with value '%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printf ("option d with value '%s'\n", optarg);
|
||||
break;
|
||||
case 'd':
|
||||
printf ("option d with value '%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,31 @@
|
|||
/* Internal declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2017 Free Software
|
||||
Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library and is also part of gnulib.
|
||||
Patches to this file should be submitted to both projects.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_INT_H
|
||||
#define _GETOPT_INT_H 1
|
||||
#define _GETOPT_INT_H 1
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
extern int _getopt_internal (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, int __posixly_correct);
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, int __posixly_correct);
|
||||
|
||||
|
||||
/* Reentrant versions which can handle parsing multiple argument
|
||||
|
|
@ -32,28 +33,20 @@ extern int _getopt_internal (int ___argc, char **___argv,
|
|||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
If the caller did not specify anything,
|
||||
the default is REQUIRE_ORDER if the environment variable
|
||||
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||
REQUIRE_ORDER means don't recognize them as options; stop option
|
||||
processing when the first non-option is seen. This is what POSIX
|
||||
specifies should happen.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options;
|
||||
stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
This mode of operation is selected by either setting the environment
|
||||
variable POSIXLY_CORRECT, or using '+' as the first character
|
||||
of the list of option characters, or by calling getopt.
|
||||
|
||||
PERMUTE is the default. We permute the contents of ARGV as we
|
||||
scan, so that eventually all the non-options are at the end.
|
||||
This allows options to be given in any order, even with programs
|
||||
that were not written to expect this.
|
||||
PERMUTE means permute the contents of ARGV as we scan, so that
|
||||
eventually all the non-options are at the end. This allows options
|
||||
to be given in any order, even with programs that were not written
|
||||
to expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were
|
||||
written to expect options and other ARGV-elements in any order
|
||||
and that care about the ordering of the two. We describe each
|
||||
non-option ARGV-element as if it were the argument of an option
|
||||
with character code 1. Using '-' as the first character of the
|
||||
list of option characters selects this mode of operation.
|
||||
with character code 1.
|
||||
|
||||
The special argument '--' forces an end of option-scanning regardless
|
||||
of the value of 'ordering'. In the case of RETURN_IN_ORDER, only
|
||||
|
|
@ -91,11 +84,6 @@ struct _getopt_data
|
|||
/* See __ord above. */
|
||||
enum __ord __ordering;
|
||||
|
||||
/* If the POSIXLY_CORRECT environment variable is set
|
||||
or getopt was called. */
|
||||
int __posixly_correct;
|
||||
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
|
|
@ -104,32 +92,27 @@ struct _getopt_data
|
|||
|
||||
int __first_nonopt;
|
||||
int __last_nonopt;
|
||||
|
||||
#if defined _LIBC && defined USE_NONOPTION_FLAGS
|
||||
int __nonoption_flags_max_len;
|
||||
int __nonoption_flags_len;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* The initializer is necessary to set OPTIND and OPTERR to their
|
||||
default values and to clear the initialization flag. */
|
||||
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
|
||||
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
|
||||
|
||||
extern int _getopt_internal_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, struct _getopt_data *__data,
|
||||
int __posixly_correct);
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, struct _getopt_data *__data,
|
||||
int __posixly_correct);
|
||||
|
||||
extern int _getopt_long_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
extern int _getopt_long_only_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts,
|
||||
int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts,
|
||||
int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
#endif /* getopt_int.h */
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if ENABLE_NLS
|
||||
/* NLS can be disabled through the configure --disable-nls option
|
||||
or through "#define ENABLE NLS 0" before including this file. */
|
||||
#if defined ENABLE_NLS && ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
|
|
@ -184,7 +185,8 @@ npgettext_aux (const char *domain,
|
|||
#include <string.h>
|
||||
|
||||
#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
|
||||
/* || __STDC_VERSION__ >= 199901L */ )
|
||||
/* || __STDC_VERSION__ == 199901L
|
||||
|| (__STDC_VERSION__ >= 201112L && !defined __STDC_NO_VLA__) */ )
|
||||
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
|
||||
#else
|
||||
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
|
||||
|
|
|
|||
|
|
@ -24,93 +24,95 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
#if HAVE_SYS_TIMEB_H
|
||||
# include <sys/timeb.h>
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
|
||||
#include "localtime-buffer.h"
|
||||
|
||||
/* Work around the bug in some systems whereby gettimeofday clobbers
|
||||
the static buffer that localtime uses for its return value. The
|
||||
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
|
||||
this problem. The tzset replacement is necessary for at least
|
||||
Solaris 2.5, 2.5.1, and 2.6. */
|
||||
#ifdef WINDOWS_NATIVE
|
||||
|
||||
static struct tm tm_zero_buffer;
|
||||
static struct tm *localtime_buffer_addr = &tm_zero_buffer;
|
||||
/* GetSystemTimePreciseAsFileTime was introduced only in Windows 8. */
|
||||
typedef void (WINAPI * GetSystemTimePreciseAsFileTimeFuncType) (FILETIME *lpTime);
|
||||
static GetSystemTimePreciseAsFileTimeFuncType GetSystemTimePreciseAsFileTimeFunc = NULL;
|
||||
static BOOL initialized = FALSE;
|
||||
|
||||
# undef localtime
|
||||
extern struct tm *localtime (time_t const *);
|
||||
|
||||
# undef gmtime
|
||||
extern struct tm *gmtime (time_t const *);
|
||||
|
||||
/* This is a wrapper for localtime. It is used only on systems for which
|
||||
gettimeofday clobbers the static buffer used for localtime's result.
|
||||
|
||||
On the first call, record the address of the static buffer that
|
||||
localtime uses for its result. */
|
||||
|
||||
struct tm *
|
||||
rpl_localtime (time_t const *timep)
|
||||
static void
|
||||
initialize (void)
|
||||
{
|
||||
struct tm *tm = localtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
HMODULE kernel32 = LoadLibrary ("kernel32.dll");
|
||||
if (kernel32 != NULL)
|
||||
{
|
||||
GetSystemTimePreciseAsFileTimeFunc =
|
||||
(GetSystemTimePreciseAsFileTimeFuncType) GetProcAddress (kernel32, "GetSystemTimePreciseAsFileTime");
|
||||
}
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
/* Same as above, since gmtime and localtime use the same buffer. */
|
||||
struct tm *
|
||||
rpl_gmtime (time_t const *timep)
|
||||
{
|
||||
struct tm *tm = gmtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
|
||||
|
||||
#if TZSET_CLOBBERS_LOCALTIME
|
||||
|
||||
# undef tzset
|
||||
extern void tzset (void);
|
||||
|
||||
/* This is a wrapper for tzset, for systems on which tzset may clobber
|
||||
the static buffer used for localtime's result. */
|
||||
void
|
||||
rpl_tzset (void)
|
||||
{
|
||||
/* Save and restore the contents of the buffer used for localtime's
|
||||
result around the call to tzset. */
|
||||
struct tm save = *localtime_buffer_addr;
|
||||
tzset ();
|
||||
*localtime_buffer_addr = save;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This is a wrapper for gettimeofday. It is used only on systems
|
||||
that lack this function, or whose implementation of this function
|
||||
causes problems. */
|
||||
causes problems.
|
||||
Work around the bug in some systems whereby gettimeofday clobbers
|
||||
the static buffer that localtime uses for its return value. The
|
||||
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
|
||||
this problem. */
|
||||
|
||||
int
|
||||
gettimeofday (struct timeval *restrict tv, void *restrict tz)
|
||||
{
|
||||
#undef gettimeofday
|
||||
#if HAVE_GETTIMEOFDAY
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
#ifdef WINDOWS_NATIVE
|
||||
|
||||
/* On native Windows, there are two ways to get the current time:
|
||||
GetSystemTimeAsFileTime
|
||||
<https://msdn.microsoft.com/en-us/library/ms724397.aspx>
|
||||
or
|
||||
GetSystemTimePreciseAsFileTime
|
||||
<https://msdn.microsoft.com/en-us/library/hh706895.aspx>.
|
||||
GetSystemTimeAsFileTime produces values that jump by increments of
|
||||
15.627 milliseconds (!) on average.
|
||||
Whereas GetSystemTimePreciseAsFileTime values usually jump by 1 or 2
|
||||
microseconds.
|
||||
More discussion on this topic:
|
||||
<http://www.windowstimestamp.com/description>. */
|
||||
FILETIME current_time;
|
||||
|
||||
if (!initialized)
|
||||
initialize ();
|
||||
if (GetSystemTimePreciseAsFileTimeFunc != NULL)
|
||||
GetSystemTimePreciseAsFileTimeFunc (¤t_time);
|
||||
else
|
||||
GetSystemTimeAsFileTime (¤t_time);
|
||||
|
||||
/* Convert from FILETIME to 'struct timeval'. */
|
||||
/* FILETIME: <https://msdn.microsoft.com/en-us/library/ms724284.aspx> */
|
||||
ULONGLONG since_1601 =
|
||||
((ULONGLONG) current_time.dwHighDateTime << 32)
|
||||
| (ULONGLONG) current_time.dwLowDateTime;
|
||||
/* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89 leap
|
||||
years, in total 134774 days. */
|
||||
ULONGLONG since_1970 =
|
||||
since_1601 - (ULONGLONG) 134774 * (ULONGLONG) 86400 * (ULONGLONG) 10000000;
|
||||
ULONGLONG microseconds_since_1970 = since_1970 / (ULONGLONG) 10;
|
||||
tv->tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000;
|
||||
tv->tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000;
|
||||
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
# if HAVE_GETTIMEOFDAY
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
/* Save and restore the contents of the buffer used for localtime's
|
||||
result around the call to gettimeofday. */
|
||||
struct tm save = *localtime_buffer_addr;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined timeval /* 'struct timeval' overridden by gnulib? */
|
||||
# undef timeval
|
||||
# if defined timeval /* 'struct timeval' overridden by gnulib? */
|
||||
# undef timeval
|
||||
struct timeval otv;
|
||||
int result = gettimeofday (&otv, (struct timezone *) tz);
|
||||
if (result == 0)
|
||||
|
|
@ -118,25 +120,16 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
|
|||
tv->tv_sec = otv.tv_sec;
|
||||
tv->tv_usec = otv.tv_usec;
|
||||
}
|
||||
# else
|
||||
# else
|
||||
int result = gettimeofday (tv, (struct timezone *) tz);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
*localtime_buffer_addr = save;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
return result;
|
||||
|
||||
#else
|
||||
|
||||
# if HAVE__FTIME
|
||||
|
||||
struct _timeb timebuf;
|
||||
_ftime (&timebuf);
|
||||
tv->tv_sec = timebuf.time;
|
||||
tv->tv_usec = timebuf.millitm * 1000;
|
||||
|
||||
# else
|
||||
|
||||
# if !defined OK_TO_USE_1S_CLOCK
|
||||
|
|
@ -146,9 +139,8 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
|
|||
tv->tv_sec = time (NULL);
|
||||
tv->tv_usec = 0;
|
||||
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#define _GL_INTPROPS_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <verify.h>
|
||||
|
||||
/* Return a value with the common real type of E and V and the value of V. */
|
||||
#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
|
||||
|
|
@ -80,24 +79,7 @@
|
|||
/* This include file assumes that signed types are two's complement without
|
||||
padding bits; the above macros have undefined behavior otherwise.
|
||||
If this is a problem for you, please let us know how to fix it for your host.
|
||||
As a sanity check, test the assumption for some signed types that
|
||||
<limits.h> bounds. */
|
||||
verify (TYPE_MINIMUM (signed char) == SCHAR_MIN);
|
||||
verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX);
|
||||
verify (TYPE_MINIMUM (short int) == SHRT_MIN);
|
||||
verify (TYPE_MAXIMUM (short int) == SHRT_MAX);
|
||||
verify (TYPE_MINIMUM (int) == INT_MIN);
|
||||
verify (TYPE_MAXIMUM (int) == INT_MAX);
|
||||
verify (TYPE_MINIMUM (long int) == LONG_MIN);
|
||||
verify (TYPE_MAXIMUM (long int) == LONG_MAX);
|
||||
#ifdef LLONG_MAX
|
||||
verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
|
||||
verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
|
||||
#endif
|
||||
/* Similarly, sanity-check one ISO/IEC TS 18661-1:2014 macro if defined. */
|
||||
#ifdef UINT_WIDTH
|
||||
verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
||||
#endif
|
||||
This assumption is tested by the intprops-tests module. */
|
||||
|
||||
/* Does the __typeof__ keyword work? This could be done by
|
||||
'configure', but for now it's easier to do it by hand. */
|
||||
|
|
@ -237,7 +219,11 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
|||
: (max) >> (b) < (a))
|
||||
|
||||
/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */
|
||||
#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__)
|
||||
#if 5 <= __GNUC__ && !defined __ICC
|
||||
# define _GL_HAS_BUILTIN_OVERFLOW 1
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_OVERFLOW 0
|
||||
#endif
|
||||
|
||||
/* True if __builtin_add_overflow_p (A, B, C) works. */
|
||||
#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
|
||||
|
|
@ -389,10 +375,10 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
|||
(_Generic \
|
||||
(*(r), \
|
||||
signed char: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
signed char, SCHAR_MIN, SCHAR_MAX), \
|
||||
short int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
short int, SHRT_MIN, SHRT_MAX), \
|
||||
int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
|
|
@ -406,10 +392,10 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
|||
#else
|
||||
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
|
||||
(sizeof *(r) == sizeof (signed char) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
signed char, SCHAR_MIN, SCHAR_MAX) \
|
||||
: sizeof *(r) == sizeof (short int) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
short int, SHRT_MIN, SHRT_MAX) \
|
||||
: sizeof *(r) == sizeof (int) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
|
|
@ -431,9 +417,8 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
|||
|
||||
/* Store the low-order bits of A <op> B into *R, where the operation
|
||||
is given by OP. Use the unsigned type UT for calculation to avoid
|
||||
overflow problems. *R's type is T, with extremal values TMIN and
|
||||
TMAX. T must be a signed integer type. Return 1 if the result
|
||||
overflows. */
|
||||
overflow problems. *R's type is T, with extrema TMIN and TMAX.
|
||||
T must be a signed integer type. Return 1 if the result overflows. */
|
||||
#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
|
||||
(sizeof ((a) op (b)) < sizeof (t) \
|
||||
? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \
|
||||
|
|
@ -442,17 +427,27 @@ verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
|
|||
((overflow (a, b) \
|
||||
|| (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \
|
||||
|| (tmax) < ((a) op (b))) \
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 1) \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 0))
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0))
|
||||
|
||||
/* Return A <op> B, where the operation is given by OP. Use the
|
||||
unsigned type UT for calculation to avoid overflow problems.
|
||||
Convert the result to type T without overflow by subtracting TMIN
|
||||
from large values before converting, and adding it afterwards.
|
||||
Compilers can optimize all the operations except OP. */
|
||||
#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t, tmin, tmax) \
|
||||
(((ut) (a) op (ut) (b)) <= (tmax) \
|
||||
? (t) ((ut) (a) op (ut) (b)) \
|
||||
: ((t) (((ut) (a) op (ut) (b)) - (tmin)) + (tmin)))
|
||||
/* Return the low-order bits of A <op> B, where the operation is given
|
||||
by OP. Use the unsigned type UT for calculation to avoid undefined
|
||||
behavior on signed integer overflow, and convert the result to type T.
|
||||
UT is at least as wide as T and is no narrower than unsigned int,
|
||||
T is two's complement, and there is no padding or trap representations.
|
||||
Assume that converting UT to T yields the low-order bits, as is
|
||||
done in all known two's-complement C compilers. E.g., see:
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
|
||||
|
||||
According to the C standard, converting UT to T yields an
|
||||
implementation-defined result or signal for values outside T's
|
||||
range. However, code that works around this theoretical problem
|
||||
runs afoul of a compiler bug in Oracle Studio 12.3 x86. See:
|
||||
http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html
|
||||
As the compiler bug is real, don't try to work around the
|
||||
theoretical problem. */
|
||||
|
||||
#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \
|
||||
((t) ((ut) (a) op (ut) (b)))
|
||||
|
||||
#endif /* _GL_INTPROPS_H */
|
||||
|
|
|
|||
10
lib/isatty.c
10
lib/isatty.c
|
|
@ -27,10 +27,16 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "msvc-inval.h"
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
#endif
|
||||
|
||||
/* Get _get_osfhandle(). */
|
||||
#include "msvc-nothrow.h"
|
||||
#if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
#else
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
static BOOL IsConsoleHandle (HANDLE h)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,17 @@
|
|||
#ifndef _@GUARD_PREFIX@_LIMITS_H
|
||||
#define _@GUARD_PREFIX@_LIMITS_H
|
||||
|
||||
/* For HP-UX 11.31. */
|
||||
#if defined LONG_LONG_MIN && !defined LLONG_MIN
|
||||
# define LLONG_MIN LONG_LONG_MIN
|
||||
#endif
|
||||
#if defined LONG_LONG_MAX && !defined LLONG_MAX
|
||||
# define LLONG_MAX LONG_LONG_MAX
|
||||
#endif
|
||||
#if defined ULONG_LONG_MAX && !defined ULLONG_MAX
|
||||
# define ULLONG_MAX ULONG_LONG_MAX
|
||||
#endif
|
||||
|
||||
/* The number of usable bits in an unsigned or signed integer type
|
||||
with minimum value MIN and maximum value MAX, as an int expression
|
||||
suitable in #if. Cover all known practical hosts. This
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 || defined __WIN32__
|
||||
#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
|
@ -75,6 +75,7 @@
|
|||
# include "relocatable.h"
|
||||
#else
|
||||
# define relocate(pathname) (pathname)
|
||||
# define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
|
||||
#endif
|
||||
|
||||
/* Get LIBDIR. */
|
||||
|
|
@ -129,6 +130,7 @@ get_charset_aliases (void)
|
|||
if (cp == NULL)
|
||||
{
|
||||
#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__ || defined OS2)
|
||||
char *malloc_dir = NULL;
|
||||
const char *dir;
|
||||
const char *base = "charset.alias";
|
||||
char *file_name;
|
||||
|
|
@ -137,7 +139,7 @@ get_charset_aliases (void)
|
|||
necessary for running the testsuite before "make install". */
|
||||
dir = getenv ("CHARSETALIASDIR");
|
||||
if (dir == NULL || dir[0] == '\0')
|
||||
dir = relocate (LIBDIR);
|
||||
dir = relocate2 (LIBDIR, &malloc_dir);
|
||||
|
||||
/* Concatenate dir and base into freshly allocated file_name. */
|
||||
{
|
||||
|
|
@ -154,6 +156,8 @@ get_charset_aliases (void)
|
|||
}
|
||||
}
|
||||
|
||||
free (malloc_dir);
|
||||
|
||||
if (file_name == NULL)
|
||||
/* Out of memory. Treat the file as empty. */
|
||||
cp = "";
|
||||
|
|
|
|||
58
lib/localtime-buffer.c
Normal file
58
lib/localtime-buffer.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* Provide access to the last buffer returned by localtime() or gmtime().
|
||||
|
||||
Copyright (C) 2001-2003, 2005-2007, 2009-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "localtime-buffer.h"
|
||||
|
||||
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
|
||||
|
||||
static struct tm tm_zero_buffer;
|
||||
struct tm *localtime_buffer_addr = &tm_zero_buffer;
|
||||
|
||||
/* This is a wrapper for localtime.
|
||||
|
||||
On the first call, record the address of the static buffer that
|
||||
localtime uses for its result. */
|
||||
|
||||
struct tm *
|
||||
rpl_localtime (time_t const *timep)
|
||||
{
|
||||
struct tm *tm = localtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* Same as above, since gmtime and localtime use the same buffer. */
|
||||
struct tm *
|
||||
rpl_gmtime (time_t const *timep)
|
||||
{
|
||||
struct tm *tm = gmtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
#endif
|
||||
27
lib/localtime-buffer.h
Normal file
27
lib/localtime-buffer.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* Provide access to the last buffer returned by localtime() or gmtime().
|
||||
|
||||
Copyright (C) 2001-2003, 2005-2007, 2009-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
|
||||
|
||||
/* The address of the last buffer returned by localtime() or gmtime(). */
|
||||
extern struct tm *localtime_buffer_addr;
|
||||
|
||||
#endif
|
||||
159
lib/malloca.c
Normal file
159
lib/malloca.c
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
/* Safe automatic memory allocation.
|
||||
Copyright (C) 2003, 2006-2007, 2009-2017 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "malloca.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "verify.h"
|
||||
|
||||
/* Silence a warning from clang's MemorySanitizer. */
|
||||
#if defined __has_feature
|
||||
# if __has_feature(memory_sanitizer)
|
||||
# define NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
|
||||
# endif
|
||||
#endif
|
||||
#ifndef NO_SANITIZE_MEMORY
|
||||
# define NO_SANITIZE_MEMORY
|
||||
#endif
|
||||
|
||||
/* The speed critical point in this file is freea() applied to an alloca()
|
||||
result: it must be fast, to match the speed of alloca(). The speed of
|
||||
mmalloca() and freea() in the other case are not critical, because they
|
||||
are only invoked for big memory sizes. */
|
||||
|
||||
#if HAVE_ALLOCA
|
||||
|
||||
/* Store the mmalloca() results in a hash table. This is needed to reliably
|
||||
distinguish a mmalloca() result and an alloca() result.
|
||||
|
||||
Although it is possible that the same pointer is returned by alloca() and
|
||||
by mmalloca() at different times in the same application, it does not lead
|
||||
to a bug in freea(), because:
|
||||
- Before a pointer returned by alloca() can point into malloc()ed memory,
|
||||
the function must return, and once this has happened the programmer must
|
||||
not call freea() on it anyway.
|
||||
- Before a pointer returned by mmalloca() can point into the stack, it
|
||||
must be freed. The only function that can free it is freea(), and
|
||||
when freea() frees it, it also removes it from the hash table. */
|
||||
|
||||
#define MAGIC_NUMBER 0x1415fb4a
|
||||
#define MAGIC_SIZE sizeof (int)
|
||||
/* This is how the header info would look like without any alignment
|
||||
considerations. */
|
||||
struct preliminary_header { void *next; int magic; };
|
||||
/* But the header's size must be a multiple of sa_alignment_max. */
|
||||
#define HEADER_SIZE \
|
||||
(((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
|
||||
union header {
|
||||
void *next;
|
||||
struct {
|
||||
char room[HEADER_SIZE - MAGIC_SIZE];
|
||||
int word;
|
||||
} magic;
|
||||
};
|
||||
verify (HEADER_SIZE == sizeof (union header));
|
||||
/* We make the hash table quite big, so that during lookups the probability
|
||||
of empty hash buckets is quite high. There is no need to make the hash
|
||||
table resizable, because when the hash table gets filled so much that the
|
||||
lookup becomes slow, it means that the application has memory leaks. */
|
||||
#define HASH_TABLE_SIZE 257
|
||||
static void * mmalloca_results[HASH_TABLE_SIZE];
|
||||
|
||||
#endif
|
||||
|
||||
void *
|
||||
mmalloca (size_t n)
|
||||
{
|
||||
#if HAVE_ALLOCA
|
||||
/* Allocate one more word, that serves as an indicator for malloc()ed
|
||||
memory, so that freea() of an alloca() result is fast. */
|
||||
size_t nplus = n + HEADER_SIZE;
|
||||
|
||||
if (nplus >= n)
|
||||
{
|
||||
void *p = malloc (nplus);
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
size_t slot;
|
||||
union header *h = p;
|
||||
|
||||
p = h + 1;
|
||||
|
||||
/* Put a magic number into the indicator word. */
|
||||
h->magic.word = MAGIC_NUMBER;
|
||||
|
||||
/* Enter p into the hash table. */
|
||||
slot = (uintptr_t) p % HASH_TABLE_SIZE;
|
||||
h->next = mmalloca_results[slot];
|
||||
mmalloca_results[slot] = p;
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
/* Out of memory. */
|
||||
return NULL;
|
||||
#else
|
||||
# if !MALLOC_0_IS_NONNULL
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
# endif
|
||||
return malloc (n);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HAVE_ALLOCA
|
||||
void NO_SANITIZE_MEMORY
|
||||
freea (void *p)
|
||||
{
|
||||
/* mmalloca() may have returned NULL. */
|
||||
if (p != NULL)
|
||||
{
|
||||
/* Attempt to quickly distinguish the mmalloca() result - which has
|
||||
a magic indicator word - and the alloca() result - which has an
|
||||
uninitialized indicator word. It is for this test that sa_increment
|
||||
additional bytes are allocated in the alloca() case. */
|
||||
if (((int *) p)[-1] == MAGIC_NUMBER)
|
||||
{
|
||||
/* Looks like a mmalloca() result. To see whether it really is one,
|
||||
perform a lookup in the hash table. */
|
||||
size_t slot = (uintptr_t) p % HASH_TABLE_SIZE;
|
||||
void **chain = &mmalloca_results[slot];
|
||||
for (; *chain != NULL;)
|
||||
{
|
||||
union header *h = p;
|
||||
if (*chain == p)
|
||||
{
|
||||
/* Found it. Remove it from the hash table and free it. */
|
||||
union header *p_begin = h - 1;
|
||||
*chain = p_begin->next;
|
||||
free (p_begin);
|
||||
return;
|
||||
}
|
||||
h = *chain;
|
||||
chain = &h[-1].next;
|
||||
}
|
||||
}
|
||||
/* At this point, we know it was not a mmalloca() result. */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
128
lib/malloca.h
Normal file
128
lib/malloca.h
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/* Safe automatic memory allocation.
|
||||
Copyright (C) 2003-2007, 2009-2017 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MALLOCA_H
|
||||
#define _MALLOCA_H
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xalloc-oversized.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
|
||||
alloca(N); otherwise it returns NULL. It either returns N bytes of
|
||||
memory allocated on the stack, that lasts until the function returns,
|
||||
or NULL.
|
||||
Use of safe_alloca should be avoided:
|
||||
- inside arguments of function calls - undefined behaviour,
|
||||
- in inline functions - the allocation may actually last until the
|
||||
calling function returns.
|
||||
*/
|
||||
#if HAVE_ALLOCA
|
||||
/* The OS usually guarantees only one guard page at the bottom of the stack,
|
||||
and a page size can be as small as 4096 bytes. So we cannot safely
|
||||
allocate anything larger than 4096 bytes. Also care for the possibility
|
||||
of a few compiler-allocated temporary stack slots.
|
||||
This must be a macro, not a function. */
|
||||
# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
|
||||
#else
|
||||
# define safe_alloca(N) ((void) (N), NULL)
|
||||
#endif
|
||||
|
||||
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
|
||||
memory allocated on the stack, that must be freed using freea() before
|
||||
the function returns. Upon failure, it returns NULL. */
|
||||
#if HAVE_ALLOCA
|
||||
# define malloca(N) \
|
||||
((N) < 4032 - sa_increment \
|
||||
? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
|
||||
: mmalloca (N))
|
||||
#else
|
||||
# define malloca(N) \
|
||||
mmalloca (N)
|
||||
#endif
|
||||
extern void * mmalloca (size_t n);
|
||||
|
||||
/* Free a block of memory allocated through malloca(). */
|
||||
#if HAVE_ALLOCA
|
||||
extern void freea (void *p);
|
||||
#else
|
||||
# define freea free
|
||||
#endif
|
||||
|
||||
/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
|
||||
It allocates an array of N objects, each with S bytes of memory,
|
||||
on the stack. S must be positive and N must be nonnegative.
|
||||
The array must be freed using freea() before the function returns. */
|
||||
#define nmalloca(n, s) (xalloc_oversized (n, s) ? NULL : malloca ((n) * (s)))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ------------------- Auxiliary, non-public definitions ------------------- */
|
||||
|
||||
/* Determine the alignment of a type at compile time. */
|
||||
#if defined __GNUC__ || defined __IBM__ALIGNOF__
|
||||
# define sa_alignof __alignof__
|
||||
#elif defined __cplusplus
|
||||
template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
|
||||
# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
|
||||
#elif defined __hpux
|
||||
/* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
|
||||
values. */
|
||||
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
|
||||
#elif defined _AIX
|
||||
/* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
|
||||
values. */
|
||||
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
|
||||
#else
|
||||
# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
/* The desired alignment of memory allocations is the maximum alignment
|
||||
among all elementary types. */
|
||||
sa_alignment_long = sa_alignof (long),
|
||||
sa_alignment_double = sa_alignof (double),
|
||||
#if HAVE_LONG_LONG_INT
|
||||
sa_alignment_longlong = sa_alignof (long long),
|
||||
#endif
|
||||
sa_alignment_longdouble = sa_alignof (long double),
|
||||
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
|
||||
#if HAVE_LONG_LONG_INT
|
||||
| (sa_alignment_longlong - 1)
|
||||
#endif
|
||||
| (sa_alignment_longdouble - 1)
|
||||
) + 1,
|
||||
/* The increment that guarantees room for a magic word must be >= sizeof (int)
|
||||
and a multiple of sa_alignment_max. */
|
||||
sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
|
||||
};
|
||||
|
||||
#endif /* _MALLOCA_H */
|
||||
7
lib/malloca.valgrind
Normal file
7
lib/malloca.valgrind
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Suppress a valgrind message about use of uninitialized memory in freea().
|
||||
# This use is OK because it provides only a speedup.
|
||||
{
|
||||
freea
|
||||
Memcheck:Cond
|
||||
fun:freea
|
||||
}
|
||||
|
|
@ -35,6 +35,13 @@
|
|||
# include "streq.h"
|
||||
# include "verify.h"
|
||||
|
||||
#ifndef FALLTHROUGH
|
||||
# if __GNUC__ < 7
|
||||
# define FALLTHROUGH ((void) 0)
|
||||
# else
|
||||
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
verify (sizeof (mbstate_t) >= 4);
|
||||
|
||||
|
|
@ -74,10 +81,10 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
|
|||
break;
|
||||
case 3:
|
||||
buf[2] = pstate[3];
|
||||
/*FALLTHROUGH*/
|
||||
FALLTHROUGH;
|
||||
case 2:
|
||||
buf[1] = pstate[2];
|
||||
/*FALLTHROUGH*/
|
||||
FALLTHROUGH;
|
||||
case 1:
|
||||
buf[0] = pstate[1];
|
||||
p = buf;
|
||||
|
|
|
|||
|
|
@ -22,17 +22,7 @@
|
|||
|
||||
#include "verify.h"
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
|
||||
|
||||
/* On native Windows, 'mbstate_t' is defined as 'int'. */
|
||||
|
||||
int
|
||||
mbsinit (const mbstate_t *ps)
|
||||
{
|
||||
return ps == NULL || *ps == 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#if GNULIB_defined_mbstate_t
|
||||
|
||||
/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
|
||||
and wcrtomb(), wcsrtombs().
|
||||
|
|
@ -45,6 +35,7 @@ mbsinit (const mbstate_t *ps)
|
|||
We define the meaning of mbstate_t as follows:
|
||||
- In mb -> wc direction, mbstate_t's first byte contains the number of
|
||||
buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
|
||||
See mbrtowc.c.
|
||||
- In wc -> mb direction, mbstate_t contains no information. In other
|
||||
words, it is always in the initial state. */
|
||||
|
||||
|
|
@ -58,4 +49,25 @@ mbsinit (const mbstate_t *ps)
|
|||
return pstate == NULL || pstate[0] == 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
mbsinit (const mbstate_t *ps)
|
||||
{
|
||||
# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
|
||||
/* Native Windows. */
|
||||
# ifdef __MINGW32__
|
||||
/* On mingw, 'mbstate_t' is defined as 'int'. */
|
||||
return ps == NULL || *ps == 0;
|
||||
# else
|
||||
/* MSVC defines 'mbstate_t' as an 8-byte struct; the first 4-bytes matter. */
|
||||
return ps == NULL || *(const unsigned int *)ps == 0;
|
||||
# endif
|
||||
# else
|
||||
/* Minix, HP-UX 11.00, Solaris 2.6, Interix, ... */
|
||||
/* Maybe this definition works, maybe not... */
|
||||
return ps == NULL || *(const char *)ps == 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "msvc-inval.h"
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
#endif
|
||||
|
||||
#undef _get_osfhandle
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@
|
|||
|
||||
#define INT_BITS (sizeof (int) * CHAR_BIT)
|
||||
|
||||
#ifndef FALLTHROUGH
|
||||
# if __GNUC__ < 7
|
||||
# define FALLTHROUGH ((void) 0)
|
||||
# else
|
||||
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct quoting_options
|
||||
{
|
||||
/* Basic quoting style. */
|
||||
|
|
@ -310,7 +318,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
|||
case c_maybe_quoting_style:
|
||||
quoting_style = c_quoting_style;
|
||||
elide_outer_quotes = true;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case c_quoting_style:
|
||||
if (!elide_outer_quotes)
|
||||
STORE ('"');
|
||||
|
|
@ -365,14 +373,14 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
|||
|
||||
case shell_escape_quoting_style:
|
||||
backslash_escapes = true;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case shell_quoting_style:
|
||||
elide_outer_quotes = true;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case shell_escape_always_quoting_style:
|
||||
if (!elide_outer_quotes)
|
||||
backslash_escapes = true;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case shell_always_quoting_style:
|
||||
quoting_style = shell_always_quoting_style;
|
||||
if (!elide_outer_quotes)
|
||||
|
|
@ -505,7 +513,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
|||
if (quoting_style == shell_always_quoting_style
|
||||
&& elide_outer_quotes)
|
||||
goto force_outer_quoting_style;
|
||||
/* Fall through. */
|
||||
/* fall through */
|
||||
c_escape:
|
||||
if (backslash_escapes)
|
||||
{
|
||||
|
|
@ -517,14 +525,14 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
|||
case '{': case '}': /* sometimes special if isolated */
|
||||
if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
|
||||
break;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case '#': case '~':
|
||||
if (i != 0)
|
||||
break;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case ' ':
|
||||
c_and_shell_quote_compat = true;
|
||||
/* Fall through. */
|
||||
FALLTHROUGH;
|
||||
case '!': /* special in bash */
|
||||
case '"': case '$': case '&':
|
||||
case '(': case ')': case '*': case ';':
|
||||
|
|
|
|||
421
lib/stat-w32.c
Normal file
421
lib/stat-w32.c
Normal file
|
|
@ -0,0 +1,421 @@
|
|||
/* Core of implementation of fstat and stat for native Windows.
|
||||
Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
/* Ensure that <windows.h> defines FILE_ID_INFO. */
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT _WIN32_WINNT_WIN8
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <windows.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "stat-w32.h"
|
||||
|
||||
#include "pathmax.h"
|
||||
#include "verify.h"
|
||||
|
||||
#if _GL_WINDOWS_STAT_INODES == 2
|
||||
/* GetFileInformationByHandleEx was introduced only in Windows Vista. */
|
||||
typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile,
|
||||
FILE_INFO_BY_HANDLE_CLASS fiClass,
|
||||
LPVOID lpBuffer,
|
||||
DWORD dwBufferSize);
|
||||
static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL;
|
||||
#endif
|
||||
/* GetFinalPathNameByHandle was introduced only in Windows Vista. */
|
||||
typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
|
||||
LPTSTR lpFilePath,
|
||||
DWORD lenFilePath,
|
||||
DWORD dwFlags);
|
||||
static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
|
||||
static BOOL initialized = FALSE;
|
||||
|
||||
static void
|
||||
initialize (void)
|
||||
{
|
||||
HMODULE kernel32 = LoadLibrary ("kernel32.dll");
|
||||
if (kernel32 != NULL)
|
||||
{
|
||||
#if _GL_WINDOWS_STAT_INODES == 2
|
||||
GetFileInformationByHandleExFunc =
|
||||
(GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx");
|
||||
#endif
|
||||
GetFinalPathNameByHandleFunc =
|
||||
(GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
|
||||
}
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
struct timespec
|
||||
_gl_convert_FILETIME_to_timespec (const FILETIME *ft)
|
||||
{
|
||||
struct timespec result;
|
||||
/* FILETIME: <https://msdn.microsoft.com/en-us/library/ms724284.aspx> */
|
||||
unsigned long long since_1601 =
|
||||
((unsigned long long) ft->dwHighDateTime << 32)
|
||||
| (unsigned long long) ft->dwLowDateTime;
|
||||
if (since_1601 == 0)
|
||||
{
|
||||
result.tv_sec = 0;
|
||||
result.tv_nsec = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
|
||||
leap years, in total 134774 days. */
|
||||
unsigned long long since_1970 =
|
||||
since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
|
||||
result.tv_sec = since_1970 / (unsigned long long) 10000000;
|
||||
result.tv_nsec = (unsigned long) (since_1970 % (unsigned long long) 10000000) * 100;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
time_t
|
||||
_gl_convert_FILETIME_to_POSIX (const FILETIME *ft)
|
||||
{
|
||||
/* FILETIME: <https://msdn.microsoft.com/en-us/library/ms724284.aspx> */
|
||||
unsigned long long since_1601 =
|
||||
((unsigned long long) ft->dwHighDateTime << 32)
|
||||
| (unsigned long long) ft->dwLowDateTime;
|
||||
if (since_1601 == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
/* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
|
||||
leap years, in total 134774 days. */
|
||||
unsigned long long since_1970 =
|
||||
since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
|
||||
return since_1970 / (unsigned long long) 10000000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fill *BUF with information about the file designated by H.
|
||||
PATH is the file name, if known, otherwise NULL.
|
||||
Return 0 if successful, or -1 with errno set upon failure. */
|
||||
int
|
||||
_gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
|
||||
{
|
||||
/* GetFileType
|
||||
<https://msdn.microsoft.com/en-us/library/aa364960.aspx> */
|
||||
DWORD type = GetFileType (h);
|
||||
if (type == FILE_TYPE_DISK)
|
||||
{
|
||||
if (!initialized)
|
||||
initialize ();
|
||||
|
||||
/* st_mode can be determined through
|
||||
GetFileAttributesEx
|
||||
<https://msdn.microsoft.com/en-us/library/aa364946.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa365739.aspx>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364952.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363788.aspx>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileBasicInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364217.aspx>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
if (! GetFileInformationByHandle (h, &info))
|
||||
goto failed;
|
||||
|
||||
/* Test for error conditions before starting to fill *buf. */
|
||||
if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if _GL_WINDOWS_STAT_INODES
|
||||
/* st_ino can be determined through
|
||||
GetFileInformationByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364952.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363788.aspx>
|
||||
as 64 bits, or through
|
||||
GetFileInformationByHandleEx with argument FileIdInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/hh802691.aspx>
|
||||
as 128 bits.
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_WIN8 or higher. */
|
||||
/* Experiments show that GetFileInformationByHandleEx does not provide
|
||||
much more information than GetFileInformationByHandle:
|
||||
* The dwVolumeSerialNumber from GetFileInformationByHandle is equal
|
||||
to the low 32 bits of the 64-bit VolumeSerialNumber from
|
||||
GetFileInformationByHandleEx, and is apparently sufficient for
|
||||
identifying the device.
|
||||
* The nFileIndex from GetFileInformationByHandle is equal to the low
|
||||
64 bits of the 128-bit FileId from GetFileInformationByHandleEx,
|
||||
and the high 64 bits of this 128-bit FileId are zero.
|
||||
* On a FAT file system, GetFileInformationByHandleEx fails with error
|
||||
ERROR_INVALID_PARAMETER, whereas GetFileInformationByHandle
|
||||
succeeds.
|
||||
* On a CIFS/SMB file system, GetFileInformationByHandleEx fails with
|
||||
error ERROR_INVALID_LEVEL, whereas GetFileInformationByHandle
|
||||
succeeds. */
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
if (GetFileInformationByHandleExFunc != NULL)
|
||||
{
|
||||
FILE_ID_INFO id;
|
||||
if (GetFileInformationByHandleExFunc (h, FileIdInfo, &id, sizeof (id)))
|
||||
{
|
||||
buf->st_dev = id.VolumeSerialNumber;
|
||||
verify (sizeof (ino_t) == sizeof (id.FileId));
|
||||
memcpy (&buf->st_ino, &id.FileId, sizeof (ino_t));
|
||||
goto ino_done;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (GetLastError ())
|
||||
{
|
||||
case ERROR_INVALID_PARAMETER: /* older Windows version, or FAT */
|
||||
case ERROR_INVALID_LEVEL: /* CIFS/SMB file system */
|
||||
goto fallback;
|
||||
default:
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
fallback: ;
|
||||
/* Fallback for older Windows versions. */
|
||||
buf->st_dev = info.dwVolumeSerialNumber;
|
||||
buf->st_ino._gl_ino[0] = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
|
||||
buf->st_ino._gl_ino[1] = 0;
|
||||
ino_done: ;
|
||||
# else /* _GL_WINDOWS_STAT_INODES == 1 */
|
||||
buf->st_dev = info.dwVolumeSerialNumber;
|
||||
buf->st_ino = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
|
||||
# endif
|
||||
#else
|
||||
/* st_ino is not wide enough for identifying a file on a device.
|
||||
Without st_ino, st_dev is pointless. */
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = 0;
|
||||
#endif
|
||||
|
||||
/* st_mode. */
|
||||
unsigned int mode =
|
||||
/* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
|
||||
((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
|
||||
| S_IREAD_UGO
|
||||
| ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
|
||||
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
/* Determine whether the file is executable by looking at the file
|
||||
name suffix.
|
||||
If the file name is already known, use it. Otherwise, for
|
||||
non-empty files, it can be determined through
|
||||
GetFinalPathNameByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364962.aspx>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileNameInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364388.aspx>
|
||||
Both require -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
|
||||
{
|
||||
char fpath[PATH_MAX];
|
||||
if (path != NULL
|
||||
|| (GetFinalPathNameByHandleFunc != NULL
|
||||
&& GetFinalPathNameByHandleFunc (h, fpath, sizeof (fpath), VOLUME_NAME_NONE)
|
||||
< sizeof (fpath)
|
||||
&& (path = fpath, 1)))
|
||||
{
|
||||
const char *last_dot = NULL;
|
||||
const char *p;
|
||||
for (p = path; *p != '\0'; p++)
|
||||
if (*p == '.')
|
||||
last_dot = p;
|
||||
if (last_dot != NULL)
|
||||
{
|
||||
const char *suffix = last_dot + 1;
|
||||
if (_stricmp (suffix, "exe") == 0
|
||||
|| _stricmp (suffix, "bat") == 0
|
||||
|| _stricmp (suffix, "cmd") == 0
|
||||
|| _stricmp (suffix, "com") == 0)
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Cannot determine file name. Pretend that it is executable. */
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
buf->st_mode = mode;
|
||||
|
||||
/* st_nlink can be determined through
|
||||
GetFileInformationByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364952.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363788.aspx>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileStandardInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364401.aspx>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
buf->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks);
|
||||
|
||||
/* There's no easy way to map the Windows SID concept to an integer. */
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
|
||||
/* st_rdev is irrelevant for normal files and directories. */
|
||||
buf->st_rdev = 0;
|
||||
|
||||
/* st_size can be determined through
|
||||
GetFileSizeEx
|
||||
<https://msdn.microsoft.com/en-us/library/aa364957.aspx>
|
||||
or through
|
||||
GetFileAttributesEx
|
||||
<https://msdn.microsoft.com/en-us/library/aa364946.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa365739.aspx>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364952.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363788.aspx>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileStandardInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364401.aspx>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
if (sizeof (buf->st_size) <= 4)
|
||||
/* Range check already done above. */
|
||||
buf->st_size = info.nFileSizeLow;
|
||||
else
|
||||
buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
|
||||
|
||||
/* st_atime, st_mtime, st_ctime can be determined through
|
||||
GetFileTime
|
||||
<https://msdn.microsoft.com/en-us/library/ms724320.aspx>
|
||||
or through
|
||||
GetFileAttributesEx
|
||||
<https://msdn.microsoft.com/en-us/library/aa364946.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa365739.aspx>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://msdn.microsoft.com/en-us/library/aa364952.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363788.aspx>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileBasicInfo
|
||||
<https://msdn.microsoft.com/en-us/library/aa364953.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364217.aspx>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
|
||||
buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
|
||||
buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
|
||||
#else
|
||||
buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
|
||||
buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
|
||||
buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (type == FILE_TYPE_CHAR || type == FILE_TYPE_PIPE)
|
||||
{
|
||||
buf->st_dev = 0;
|
||||
#if _GL_WINDOWS_STAT_INODES == 2
|
||||
buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
|
||||
#else
|
||||
buf->st_ino = 0;
|
||||
#endif
|
||||
buf->st_mode = (type == FILE_TYPE_PIPE ? _S_IFIFO : _S_IFCHR);
|
||||
buf->st_nlink = 1;
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
buf->st_rdev = 0;
|
||||
if (type == FILE_TYPE_PIPE)
|
||||
{
|
||||
/* PeekNamedPipe
|
||||
<https://msdn.microsoft.com/en-us/library/aa365779.aspx> */
|
||||
DWORD bytes_available;
|
||||
if (PeekNamedPipe (h, NULL, 0, NULL, &bytes_available, NULL))
|
||||
buf->st_size = bytes_available;
|
||||
else
|
||||
buf->st_size = 0;
|
||||
}
|
||||
else
|
||||
buf->st_size = 0;
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim.tv_sec = 0; buf->st_atim.tv_nsec = 0;
|
||||
buf->st_mtim.tv_sec = 0; buf->st_mtim.tv_nsec = 0;
|
||||
buf->st_ctim.tv_sec = 0; buf->st_ctim.tv_nsec = 0;
|
||||
#else
|
||||
buf->st_atime = 0;
|
||||
buf->st_mtime = 0;
|
||||
buf->st_ctime = 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
failed:
|
||||
{
|
||||
DWORD error = GetLastError ();
|
||||
#if 0
|
||||
fprintf (stderr, "_gl_fstat_by_handle error 0x%x\n", (unsigned int) error);
|
||||
#endif
|
||||
switch (error)
|
||||
{
|
||||
case ERROR_ACCESS_DENIED:
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
errno = EACCES;
|
||||
break;
|
||||
|
||||
case ERROR_OUTOFMEMORY:
|
||||
errno = ENOMEM;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_FAULT:
|
||||
case ERROR_READ_FAULT:
|
||||
case ERROR_GEN_FAILURE:
|
||||
errno = EIO;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* This declaration is solely to ensure that after preprocessing
|
||||
this file is never empty. */
|
||||
typedef int dummy;
|
||||
|
||||
#endif
|
||||
37
lib/stat-w32.h
Normal file
37
lib/stat-w32.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* Core of implementation of fstat and stat for native Windows.
|
||||
Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _STAT_W32_H
|
||||
#define _STAT_W32_H 1
|
||||
|
||||
/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
extern struct timespec _gl_convert_FILETIME_to_timespec (const FILETIME *ft);
|
||||
#else
|
||||
extern time_t _gl_convert_FILETIME_to_POSIX (const FILETIME *ft);
|
||||
#endif
|
||||
|
||||
/* Fill *BUF with information about the file designated by H.
|
||||
PATH is the file name, if known, otherwise NULL.
|
||||
Return 0 if successful, or -1 with errno set upon failure. */
|
||||
extern int _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf);
|
||||
|
||||
/* Bitmasks for st_mode. */
|
||||
#define S_IREAD_UGO (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
|
||||
#define S_IWRITE_UGO (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
|
||||
#define S_IEXEC_UGO (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
|
||||
|
||||
#endif /* _STAT_W32_H */
|
||||
419
lib/stat.c
419
lib/stat.c
|
|
@ -14,7 +14,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Eric Blake */
|
||||
/* Written by Eric Blake and Bruno Haible. */
|
||||
|
||||
/* If the user's config.h happens to include <sys/stat.h>, let it include only
|
||||
the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
|
||||
|
|
@ -28,26 +28,19 @@
|
|||
#undef __need_system_sys_stat_h
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
# if _GL_WINDOWS_64_BIT_ST_SIZE
|
||||
# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
|
||||
# define stat _stati64
|
||||
# define REPLACE_FUNC_STAT_DIR 1
|
||||
# undef REPLACE_FUNC_STAT_FILE
|
||||
# elif REPLACE_FUNC_STAT_FILE
|
||||
/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a.
|
||||
Bypass it. */
|
||||
# define stat _stat
|
||||
# define REPLACE_FUNC_STAT_DIR 1
|
||||
# undef REPLACE_FUNC_STAT_FILE
|
||||
# endif
|
||||
# define WINDOWS_NATIVE
|
||||
#endif
|
||||
|
||||
#if !defined WINDOWS_NATIVE
|
||||
|
||||
static int
|
||||
orig_stat (const char *filename, struct stat *buf)
|
||||
{
|
||||
return stat (filename, buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
|
||||
eliminates this include because of the preliminary #include <sys/stat.h>
|
||||
|
|
@ -58,16 +51,42 @@ orig_stat (const char *filename, struct stat *buf)
|
|||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "dosname.h"
|
||||
#include "filename.h"
|
||||
#include "malloca.h"
|
||||
#include "verify.h"
|
||||
|
||||
#if REPLACE_FUNC_STAT_DIR
|
||||
# include "pathmax.h"
|
||||
/* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
|
||||
have a constant PATH_MAX. */
|
||||
# ifndef PATH_MAX
|
||||
# error "Please port this replacement to your platform"
|
||||
# endif
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include "stat-w32.h"
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
/* Return TRUE if the given file name denotes an UNC root. */
|
||||
static BOOL
|
||||
is_unc_root (const char *rname)
|
||||
{
|
||||
/* Test whether it has the syntax '\\server\share'. */
|
||||
if (ISSLASH (rname[0]) && ISSLASH (rname[1]))
|
||||
{
|
||||
/* It starts with two slashes. Find the next slash. */
|
||||
const char *p = rname + 2;
|
||||
const char *q = p;
|
||||
while (*q != '\0' && !ISSLASH (*q))
|
||||
q++;
|
||||
if (q > p && *q != '\0')
|
||||
{
|
||||
/* Found the next slash at q. */
|
||||
q++;
|
||||
const char *r = q;
|
||||
while (*r != '\0' && !ISSLASH (*r))
|
||||
r++;
|
||||
if (r > q && *r == '\0')
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Store information about NAME into ST. Work around bugs with
|
||||
|
|
@ -77,13 +96,319 @@ orig_stat (const char *filename, struct stat *buf)
|
|||
correctly. */
|
||||
|
||||
int
|
||||
rpl_stat (char const *name, struct stat *st)
|
||||
rpl_stat (char const *name, struct stat *buf)
|
||||
{
|
||||
int result = orig_stat (name, st);
|
||||
#if REPLACE_FUNC_STAT_FILE
|
||||
#ifdef WINDOWS_NATIVE
|
||||
/* Fill the fields ourselves, because the original stat function returns
|
||||
values for st_atime, st_mtime, st_ctime that depend on the current time
|
||||
zone. See
|
||||
<https://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00134.html> */
|
||||
/* XXX Should we convert to wchar_t* and prepend '\\?\', in order to work
|
||||
around length limitations
|
||||
<https://msdn.microsoft.com/en-us/library/aa365247.aspx> ? */
|
||||
|
||||
/* POSIX <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>
|
||||
specifies: "More than two leading <slash> characters shall be treated as
|
||||
a single <slash> character." */
|
||||
if (ISSLASH (name[0]) && ISSLASH (name[1]) && ISSLASH (name[2]))
|
||||
{
|
||||
name += 2;
|
||||
while (ISSLASH (name[1]))
|
||||
name++;
|
||||
}
|
||||
|
||||
size_t len = strlen (name);
|
||||
size_t drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
|
||||
|
||||
/* Remove trailing slashes (except the very first one, at position
|
||||
drive_prefix_len), but remember their presence. */
|
||||
size_t rlen;
|
||||
bool check_dir = false;
|
||||
|
||||
rlen = len;
|
||||
while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
|
||||
{
|
||||
check_dir = true;
|
||||
if (rlen == drive_prefix_len + 1)
|
||||
break;
|
||||
rlen--;
|
||||
}
|
||||
|
||||
/* Handle '' and 'C:'. */
|
||||
if (!check_dir && rlen == drive_prefix_len)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Handle '\\'. */
|
||||
if (rlen == 1 && ISSLASH (name[0]) && len >= 2)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *rname;
|
||||
char *malloca_rname;
|
||||
if (rlen == len)
|
||||
{
|
||||
rname = name;
|
||||
malloca_rname = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
malloca_rname = malloca (rlen + 1);
|
||||
if (malloca_rname == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
memcpy (malloca_rname, name, rlen);
|
||||
malloca_rname[rlen] = '\0';
|
||||
rname = malloca_rname;
|
||||
}
|
||||
|
||||
/* There are two ways to get at the requested information:
|
||||
- by scanning the parent directory and examining the relevant
|
||||
directory entry,
|
||||
- by opening the file directly.
|
||||
The first approach fails for root directories (e.g. 'C:\') and
|
||||
UNC root directories (e.g. '\\server\share').
|
||||
The second approach fails for some system files (e.g. 'C:\pagefile.sys'
|
||||
and 'C:\hiberfil.sys'): ERROR_SHARING_VIOLATION.
|
||||
The second approach gives more information (in particular, correct
|
||||
st_dev, st_ino, st_nlink fields).
|
||||
So we use the second approach and, as a fallback except for root and
|
||||
UNC root directories, also the first approach. */
|
||||
{
|
||||
int ret;
|
||||
|
||||
{
|
||||
/* Approach based on the file. */
|
||||
|
||||
/* Open a handle to the file.
|
||||
CreateFile
|
||||
<https://msdn.microsoft.com/en-us/library/aa363858.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa363874.aspx> */
|
||||
HANDLE h =
|
||||
CreateFile (rname,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
/* FILE_FLAG_POSIX_SEMANTICS (treat file names that differ only
|
||||
in case as different) makes sense only when applied to *all*
|
||||
filesystem operations. */
|
||||
FILE_FLAG_BACKUP_SEMANTICS /* | FILE_FLAG_POSIX_SEMANTICS */,
|
||||
NULL);
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ret = _gl_fstat_by_handle (h, rname, buf);
|
||||
CloseHandle (h);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Test for root and UNC root directories. */
|
||||
if ((rlen == drive_prefix_len + 1 && ISSLASH (rname[drive_prefix_len]))
|
||||
|| is_unc_root (rname))
|
||||
goto failed;
|
||||
|
||||
/* Fallback. */
|
||||
{
|
||||
/* Approach based on the directory entry. */
|
||||
|
||||
if (strchr (rname, '?') != NULL || strchr (rname, '*') != NULL)
|
||||
{
|
||||
/* Other Windows API functions would fail with error
|
||||
ERROR_INVALID_NAME. */
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get the details about the directory entry. This can be done through
|
||||
FindFirstFile
|
||||
<https://msdn.microsoft.com/en-us/library/aa364418.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa365740.aspx>
|
||||
or through
|
||||
FindFirstFileEx with argument FindExInfoBasic
|
||||
<https://msdn.microsoft.com/en-us/library/aa364419.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa364415.aspx>
|
||||
<https://msdn.microsoft.com/en-us/library/aa365740.aspx> */
|
||||
WIN32_FIND_DATA info;
|
||||
HANDLE h = FindFirstFile (rname, &info);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
goto failed;
|
||||
|
||||
/* Test for error conditions before starting to fill *buf. */
|
||||
if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
|
||||
{
|
||||
FindClose (h);
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
# if _GL_WINDOWS_STAT_INODES
|
||||
buf->st_dev = 0;
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
|
||||
# else /* _GL_WINDOWS_STAT_INODES == 1 */
|
||||
buf->st_ino = 0;
|
||||
# endif
|
||||
# else
|
||||
/* st_ino is not wide enough for identifying a file on a device.
|
||||
Without st_ino, st_dev is pointless. */
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = 0;
|
||||
# endif
|
||||
|
||||
/* st_mode. */
|
||||
unsigned int mode =
|
||||
/* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
|
||||
((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
|
||||
| S_IREAD_UGO
|
||||
| ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
|
||||
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
/* Determine whether the file is executable by looking at the file
|
||||
name suffix. */
|
||||
if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
|
||||
{
|
||||
const char *last_dot = NULL;
|
||||
const char *p;
|
||||
for (p = info.cFileName; *p != '\0'; p++)
|
||||
if (*p == '.')
|
||||
last_dot = p;
|
||||
if (last_dot != NULL)
|
||||
{
|
||||
const char *suffix = last_dot + 1;
|
||||
if (_stricmp (suffix, "exe") == 0
|
||||
|| _stricmp (suffix, "bat") == 0
|
||||
|| _stricmp (suffix, "cmd") == 0
|
||||
|| _stricmp (suffix, "com") == 0)
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
}
|
||||
buf->st_mode = mode;
|
||||
|
||||
/* st_nlink. Ignore hard links here. */
|
||||
buf->st_nlink = 1;
|
||||
|
||||
/* There's no easy way to map the Windows SID concept to an integer. */
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
|
||||
/* st_rdev is irrelevant for normal files and directories. */
|
||||
buf->st_rdev = 0;
|
||||
|
||||
/* st_size. */
|
||||
if (sizeof (buf->st_size) <= 4)
|
||||
/* Range check already done above. */
|
||||
buf->st_size = info.nFileSizeLow;
|
||||
else
|
||||
buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
|
||||
|
||||
/* st_atime, st_mtime, st_ctime. */
|
||||
# if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
|
||||
buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
|
||||
buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
|
||||
# else
|
||||
buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
|
||||
buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
|
||||
buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
|
||||
# endif
|
||||
|
||||
FindClose (h);
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
done:
|
||||
if (ret >= 0 && check_dir && !S_ISDIR (buf->st_mode))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
ret = -1;
|
||||
}
|
||||
if (malloca_rname != NULL)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
freea (malloca_rname);
|
||||
errno = saved_errno;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
failed:
|
||||
{
|
||||
DWORD error = GetLastError ();
|
||||
#if 0
|
||||
fprintf (stderr, "rpl_stat error 0x%x\n", (unsigned int) error);
|
||||
#endif
|
||||
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
|
||||
switch (error)
|
||||
{
|
||||
/* Some of these errors probably cannot happen with the specific flags
|
||||
that we pass to CreateFile. But who knows... */
|
||||
case ERROR_FILE_NOT_FOUND: /* The last component of rname does not exist. */
|
||||
case ERROR_PATH_NOT_FOUND: /* Some directory component in rname does not exist. */
|
||||
case ERROR_BAD_PATHNAME: /* rname is such as '\\server'. */
|
||||
case ERROR_BAD_NET_NAME: /* rname is such as '\\server\nonexistentshare'. */
|
||||
case ERROR_INVALID_NAME: /* rname contains wildcards, misplaced colon, etc. */
|
||||
case ERROR_DIRECTORY:
|
||||
errno = ENOENT;
|
||||
break;
|
||||
|
||||
case ERROR_ACCESS_DENIED: /* rname is such as 'C:\System Volume Information\foo'. */
|
||||
case ERROR_SHARING_VIOLATION: /* rname is such as 'C:\pagefile.sys' (second approach only). */
|
||||
/* XXX map to EACCESS or EPERM? */
|
||||
errno = EACCES;
|
||||
break;
|
||||
|
||||
case ERROR_OUTOFMEMORY:
|
||||
errno = ENOMEM;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_PROTECT:
|
||||
errno = EROFS;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_FAULT:
|
||||
case ERROR_READ_FAULT:
|
||||
case ERROR_GEN_FAILURE:
|
||||
errno = EIO;
|
||||
break;
|
||||
|
||||
case ERROR_BUFFER_OVERFLOW:
|
||||
case ERROR_FILENAME_EXCED_RANGE:
|
||||
errno = ENAMETOOLONG;
|
||||
break;
|
||||
|
||||
case ERROR_DELETE_PENDING: /* XXX map to EACCESS or EPERM? */
|
||||
errno = EPERM;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
int result = orig_stat (name, buf);
|
||||
# if REPLACE_FUNC_STAT_FILE
|
||||
/* Solaris 9 mistakenly succeeds when given a non-directory with a
|
||||
trailing slash. */
|
||||
if (result == 0 && !S_ISDIR (st->st_mode))
|
||||
if (result == 0 && !S_ISDIR (buf->st_mode))
|
||||
{
|
||||
size_t len = strlen (name);
|
||||
if (ISSLASH (name[len - 1]))
|
||||
|
|
@ -92,47 +417,7 @@ rpl_stat (char const *name, struct stat *st)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif /* REPLACE_FUNC_STAT_FILE */
|
||||
#if REPLACE_FUNC_STAT_DIR
|
||||
|
||||
if (result == -1 && errno == ENOENT)
|
||||
{
|
||||
/* Due to mingw's oddities, there are some directories (like
|
||||
c:\) where stat() only succeeds with a trailing slash, and
|
||||
other directories (like c:\windows) where stat() only
|
||||
succeeds without a trailing slash. But we want the two to be
|
||||
synonymous, since chdir() manages either style. Likewise, Mingw also
|
||||
reports ENOENT for names longer than PATH_MAX, when we want
|
||||
ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
|
||||
Fortunately, mingw PATH_MAX is small enough for stack
|
||||
allocation. */
|
||||
char fixed_name[PATH_MAX + 1] = {0};
|
||||
size_t len = strlen (name);
|
||||
bool check_dir = false;
|
||||
verify (PATH_MAX <= 4096);
|
||||
if (PATH_MAX <= len)
|
||||
errno = ENAMETOOLONG;
|
||||
else if (len)
|
||||
{
|
||||
strcpy (fixed_name, name);
|
||||
if (ISSLASH (fixed_name[len - 1]))
|
||||
{
|
||||
check_dir = true;
|
||||
while (len && ISSLASH (fixed_name[len - 1]))
|
||||
fixed_name[--len] = '\0';
|
||||
if (!len)
|
||||
fixed_name[0] = '/';
|
||||
}
|
||||
else
|
||||
fixed_name[len++] = '/';
|
||||
result = orig_stat (fixed_name, st);
|
||||
if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
|
||||
{
|
||||
result = -1;
|
||||
errno = ENOTDIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* REPLACE_FUNC_STAT_DIR */
|
||||
# endif /* REPLACE_FUNC_STAT_FILE */
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@
|
|||
# elif ((defined __APPLE__ && defined __MACH__ \
|
||||
? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
|
||||
: __GNUC__) \
|
||||
|| 061200 <= __HP_cc || 061200 <= __HP_aCC \
|
||||
|| (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
|
||||
|| __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__)
|
||||
# define _Alignas(a) __attribute__ ((__aligned__ (a)))
|
||||
# elif 1300 <= _MSC_VER
|
||||
|
|
|
|||
|
|
@ -128,8 +128,13 @@
|
|||
Return an unspecified value if BITS == 0, adding a check to pacify
|
||||
picky compilers. */
|
||||
|
||||
# define _STDINT_MIN(signed, bits, zero) \
|
||||
((signed) ? ~ _STDINT_MAX (signed, bits, zero) : (zero))
|
||||
/* These are separate macros, because if you try to merge these macros into
|
||||
a single one, HP-UX cc rejects the resulting expression in constant
|
||||
expressions. */
|
||||
# define _STDINT_UNSIGNED_MIN(bits, zero) \
|
||||
(zero)
|
||||
# define _STDINT_SIGNED_MIN(bits, zero) \
|
||||
(~ _STDINT_MAX (1, bits, zero))
|
||||
|
||||
# define _STDINT_MAX(signed, bits, zero) \
|
||||
(((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
|
||||
|
|
@ -512,15 +517,15 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
|||
# undef PTRDIFF_MAX
|
||||
# if @APPLE_UNIVERSAL_BUILD@
|
||||
# ifdef _LP64
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l)
|
||||
# define PTRDIFF_MIN _STDINT_SIGNED_MIN (64, 0l)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
|
||||
# else
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0)
|
||||
# define PTRDIFF_MIN _STDINT_SIGNED_MIN (32, 0)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
|
||||
# endif
|
||||
# else
|
||||
# define PTRDIFF_MIN \
|
||||
_STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
|
||||
_STDINT_SIGNED_MIN (@BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
|
||||
# define PTRDIFF_MAX \
|
||||
_STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
|
||||
# endif
|
||||
|
|
@ -528,9 +533,13 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
|||
/* sig_atomic_t limits */
|
||||
# undef SIG_ATOMIC_MIN
|
||||
# undef SIG_ATOMIC_MAX
|
||||
# define SIG_ATOMIC_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
|
||||
0@SIG_ATOMIC_T_SUFFIX@)
|
||||
# if @HAVE_SIGNED_SIG_ATOMIC_T@
|
||||
# define SIG_ATOMIC_MIN \
|
||||
_STDINT_SIGNED_MIN (@BITSIZEOF_SIG_ATOMIC_T@, 0@SIG_ATOMIC_T_SUFFIX@)
|
||||
# else
|
||||
# define SIG_ATOMIC_MIN \
|
||||
_STDINT_UNSIGNED_MIN (@BITSIZEOF_SIG_ATOMIC_T@, 0@SIG_ATOMIC_T_SUFFIX@)
|
||||
# endif
|
||||
# define SIG_ATOMIC_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
|
||||
0@SIG_ATOMIC_T_SUFFIX@)
|
||||
|
|
@ -566,16 +575,26 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
|||
# endif
|
||||
# undef WCHAR_MIN
|
||||
# undef WCHAR_MAX
|
||||
# define WCHAR_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
# if @HAVE_SIGNED_WCHAR_T@
|
||||
# define WCHAR_MIN \
|
||||
_STDINT_SIGNED_MIN (@BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
# else
|
||||
# define WCHAR_MIN \
|
||||
_STDINT_UNSIGNED_MIN (@BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
# endif
|
||||
# define WCHAR_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
|
||||
/* wint_t limits */
|
||||
# undef WINT_MIN
|
||||
# undef WINT_MAX
|
||||
# define WINT_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
# if @HAVE_SIGNED_WINT_T@
|
||||
# define WINT_MIN \
|
||||
_STDINT_SIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
# else
|
||||
# define WINT_MIN \
|
||||
_STDINT_UNSIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
# endif
|
||||
# define WINT_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,23 @@
|
|||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
/* Clear a block of memory. The compiler will not delete a call to
|
||||
this function, even if the block is dead after the call. */
|
||||
#if @GNULIB_EXPLICIT_BZERO@
|
||||
# if ! @HAVE_EXPLICIT_BZERO@
|
||||
_GL_FUNCDECL_SYS (explicit_bzero, void,
|
||||
(void *__dest, size_t __n) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
|
||||
_GL_CXXALIASWARN (explicit_bzero);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef explicit_bzero
|
||||
# if HAVE_RAW_DECL_EXPLICIT_BZERO
|
||||
_GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
|
||||
"use gnulib module explicit_bzero for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Find the index of the least-significant set bit. */
|
||||
#if @GNULIB_FFSL@
|
||||
# if !@HAVE_FFSL@
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Provide a more complete sys/stat header file.
|
||||
/* Provide a more complete sys/stat.h header file.
|
||||
Copyright (C) 2005-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -72,6 +72,75 @@
|
|||
# define stat _stati64
|
||||
#endif
|
||||
|
||||
/* Optionally, override 'struct stat' on native Windows. */
|
||||
#if @GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
|
||||
# undef stat
|
||||
# if @GNULIB_STAT@
|
||||
# define stat rpl_stat
|
||||
# else
|
||||
/* Provoke a clear link error if stat() is used as a function and
|
||||
module 'stat' is not in use. */
|
||||
# define stat stat_used_without_requesting_gnulib_module_stat
|
||||
# endif
|
||||
|
||||
# if !GNULIB_defined_struct_stat
|
||||
struct stat
|
||||
{
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
# if 0
|
||||
uid_t st_uid;
|
||||
# else /* uid_t is not defined by default on native Windows. */
|
||||
short st_uid;
|
||||
# endif
|
||||
# if 0
|
||||
gid_t st_gid;
|
||||
# else /* gid_t is not defined by default on native Windows. */
|
||||
short st_gid;
|
||||
# endif
|
||||
dev_t st_rdev;
|
||||
off_t st_size;
|
||||
# if 0
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
# endif
|
||||
|
||||
# if @WINDOWS_STAT_TIMESPEC@
|
||||
struct timespec st_atim;
|
||||
struct timespec st_mtim;
|
||||
struct timespec st_ctim;
|
||||
# else
|
||||
time_t st_atime;
|
||||
time_t st_mtime;
|
||||
time_t st_ctime;
|
||||
# endif
|
||||
};
|
||||
# if @WINDOWS_STAT_TIMESPEC@
|
||||
# define st_atime st_atim.tv_sec
|
||||
# define st_mtime st_mtim.tv_sec
|
||||
# define st_ctime st_ctim.tv_sec
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_STAT_TIMESPEC 1
|
||||
# endif
|
||||
# define GNULIB_defined_struct_stat 1
|
||||
# endif
|
||||
|
||||
/* Other possible values of st_mode. */
|
||||
# if 0
|
||||
# define _S_IFBLK 0x6000
|
||||
# endif
|
||||
# if 0
|
||||
# define _S_IFLNK 0xA000
|
||||
# endif
|
||||
# if 0
|
||||
# define _S_IFSOCK 0xC000
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef S_IFIFO
|
||||
# ifdef _S_IFIFO
|
||||
# define S_IFIFO _S_IFIFO
|
||||
|
|
@ -345,6 +414,9 @@ _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
|
|||
_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (fstat);
|
||||
#elif @GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
# undef fstat
|
||||
# define fstat fstat_used_without_requesting_gnulib_module_fstat
|
||||
#elif @WINDOWS_64_BIT_ST_SIZE@
|
||||
/* Above, we define stat to _stati64. */
|
||||
# define fstat _fstati64
|
||||
|
|
@ -378,6 +450,9 @@ _GL_CXXALIAS_SYS (fstatat, int,
|
|||
(int fd, char const *name, struct stat *st, int flags));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (fstatat);
|
||||
#elif @GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
# undef fstatat
|
||||
# define fstatat fstatat_used_without_requesting_gnulib_module_fstatat
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fstatat
|
||||
# if HAVE_RAW_DECL_FSTATAT
|
||||
|
|
@ -476,6 +551,9 @@ _GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
|
|||
# if @HAVE_LSTAT@
|
||||
_GL_CXXALIASWARN (lstat);
|
||||
# endif
|
||||
#elif @GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
# undef lstat
|
||||
# define lstat lstat_used_without_requesting_gnulib_module_lstat
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef lstat
|
||||
# if HAVE_RAW_DECL_LSTAT
|
||||
|
|
@ -625,63 +703,69 @@ _GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
|
|||
|
||||
#if @GNULIB_STAT@
|
||||
# if @REPLACE_STAT@
|
||||
/* We can't use the object-like #define stat rpl_stat, because of
|
||||
struct stat. This means that rpl_stat will not be used if the user
|
||||
does (stat)(a,b). Oh well. */
|
||||
# if defined _AIX && defined stat && defined _LARGE_FILES
|
||||
/* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
|
||||
so we have to replace stat64() instead of stat(). */
|
||||
# undef stat64
|
||||
# define stat64(name, st) rpl_stat (name, st)
|
||||
# elif @WINDOWS_64_BIT_ST_SIZE@
|
||||
/* Above, we define stat to _stati64. */
|
||||
# if defined __MINGW32__ && defined _stati64
|
||||
# ifndef _USE_32BIT_TIME_T
|
||||
/* The system headers define _stati64 to _stat64. */
|
||||
# undef _stat64
|
||||
# define _stat64(name, st) rpl_stat (name, st)
|
||||
# if !@GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
/* We can't use the object-like #define stat rpl_stat, because of
|
||||
struct stat. This means that rpl_stat will not be used if the user
|
||||
does (stat)(a,b). Oh well. */
|
||||
# if defined _AIX && defined stat && defined _LARGE_FILES
|
||||
/* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
|
||||
so we have to replace stat64() instead of stat(). */
|
||||
# undef stat64
|
||||
# define stat64(name, st) rpl_stat (name, st)
|
||||
# elif @WINDOWS_64_BIT_ST_SIZE@
|
||||
/* Above, we define stat to _stati64. */
|
||||
# if defined __MINGW32__ && defined _stati64
|
||||
# ifndef _USE_32BIT_TIME_T
|
||||
/* The system headers define _stati64 to _stat64. */
|
||||
# undef _stat64
|
||||
# define _stat64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# elif defined _MSC_VER && defined _stati64
|
||||
# ifdef _USE_32BIT_TIME_T
|
||||
/* The system headers define _stati64 to _stat32i64. */
|
||||
# undef _stat32i64
|
||||
# define _stat32i64(name, st) rpl_stat (name, st)
|
||||
# else
|
||||
/* The system headers define _stati64 to _stat64. */
|
||||
# undef _stat64
|
||||
# define _stat64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# else
|
||||
# undef _stati64
|
||||
# define _stati64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# elif defined _MSC_VER && defined _stati64
|
||||
# elif defined __MINGW32__ && defined stat
|
||||
# ifdef _USE_32BIT_TIME_T
|
||||
/* The system headers define _stati64 to _stat32i64. */
|
||||
/* The system headers define stat to _stat32i64. */
|
||||
# undef _stat32i64
|
||||
# define _stat32i64(name, st) rpl_stat (name, st)
|
||||
# else
|
||||
/* The system headers define _stati64 to _stat64. */
|
||||
/* The system headers define stat to _stat64. */
|
||||
# undef _stat64
|
||||
# define _stat64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# else
|
||||
# undef _stati64
|
||||
# define _stati64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# elif defined __MINGW32__ && defined stat
|
||||
# ifdef _USE_32BIT_TIME_T
|
||||
/* The system headers define stat to _stat32i64. */
|
||||
# undef _stat32i64
|
||||
# define _stat32i64(name, st) rpl_stat (name, st)
|
||||
# else
|
||||
/* The system headers define stat to _stat64. */
|
||||
# undef _stat64
|
||||
# define _stat64(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# elif defined _MSC_VER && defined stat
|
||||
# ifdef _USE_32BIT_TIME_T
|
||||
/* The system headers define stat to _stat32. */
|
||||
# undef _stat32
|
||||
# define _stat32(name, st) rpl_stat (name, st)
|
||||
# else
|
||||
/* The system headers define stat to _stat64i32. */
|
||||
# undef _stat64i32
|
||||
# define _stat64i32(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
|
||||
# undef stat
|
||||
# define stat(name, st) rpl_stat (name, st)
|
||||
# endif /* !_LARGE_FILES */
|
||||
# elif defined _MSC_VER && defined stat
|
||||
# ifdef _USE_32BIT_TIME_T
|
||||
/* The system headers define stat to _stat32. */
|
||||
# undef _stat32
|
||||
# define _stat32(name, st) rpl_stat (name, st)
|
||||
# else
|
||||
/* The system headers define stat to _stat64i32. */
|
||||
# undef _stat64i32
|
||||
# define _stat64i32(name, st) rpl_stat (name, st)
|
||||
# endif
|
||||
# else /* !(_AIX || __MINGW32__ || _MSC_VER) */
|
||||
# undef stat
|
||||
# define stat(name, st) rpl_stat (name, st)
|
||||
# endif /* !_LARGE_FILES */
|
||||
# endif /* !@GNULIB_OVERRIDES_STRUCT_STAT@ */
|
||||
_GL_EXTERN_C int stat (const char *name, struct stat *buf)
|
||||
_GL_ARG_NONNULL ((1, 2));
|
||||
# endif
|
||||
#elif @GNULIB_OVERRIDES_STRUCT_STAT@
|
||||
/* see above:
|
||||
#define stat stat_used_without_requesting_gnulib_module_stat
|
||||
*/
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef stat
|
||||
# if HAVE_RAW_DECL_STAT
|
||||
|
|
|
|||
|
|
@ -42,6 +42,48 @@
|
|||
# define _GL_WINDOWS_64_BIT_OFF_T 1
|
||||
#endif
|
||||
|
||||
/* Override dev_t and ino_t if distinguishable inodes support is requested
|
||||
on native Windows. */
|
||||
#if @WINDOWS_STAT_INODES@
|
||||
|
||||
# if @WINDOWS_STAT_INODES@ == 2
|
||||
/* Experimental, not useful in Windows 10. */
|
||||
|
||||
/* Define dev_t to a 64-bit type. */
|
||||
# if !defined GNULIB_defined_dev_t
|
||||
typedef unsigned long long int rpl_dev_t;
|
||||
# undef dev_t
|
||||
# define dev_t rpl_dev_t
|
||||
# define GNULIB_defined_dev_t 1
|
||||
# endif
|
||||
|
||||
/* Define ino_t to a 128-bit type. */
|
||||
# if !defined GNULIB_defined_ino_t
|
||||
/* MSVC does not have a 128-bit integer type.
|
||||
GCC has a 128-bit integer type __int128, but only on 64-bit targets. */
|
||||
typedef struct { unsigned long long int _gl_ino[2]; } rpl_ino_t;
|
||||
# undef ino_t
|
||||
# define ino_t rpl_ino_t
|
||||
# define GNULIB_defined_ino_t 1
|
||||
# endif
|
||||
|
||||
# else /* @WINDOWS_STAT_INODES@ == 1 */
|
||||
|
||||
/* Define ino_t to a 64-bit type. */
|
||||
# if !defined GNULIB_defined_ino_t
|
||||
typedef unsigned long long int rpl_ino_t;
|
||||
# undef ino_t
|
||||
# define ino_t rpl_ino_t
|
||||
# define GNULIB_defined_ino_t 1
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_STAT_INODES @WINDOWS_STAT_INODES@
|
||||
|
||||
#endif
|
||||
|
||||
/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */
|
||||
/* But avoid namespace pollution on glibc systems. */
|
||||
#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ try_nocreate (char *tmpl, void *flags _GL_UNUSED)
|
|||
{
|
||||
struct_stat64 st;
|
||||
|
||||
if (__lxstat64 (_STAT_VER, tmpl, &st) == 0)
|
||||
if (__lxstat64 (_STAT_VER, tmpl, &st) == 0 || errno == EOVERFLOW)
|
||||
__set_errno (EEXIST);
|
||||
return errno == ENOENT ? 0 : -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,24 @@ _GL_CXXALIAS_SYS (nanosleep, int,
|
|||
_GL_CXXALIASWARN (nanosleep);
|
||||
# endif
|
||||
|
||||
/* Initialize time conversion information. */
|
||||
# if @GNULIB_TZSET@
|
||||
# if @REPLACE_TZSET@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef tzset
|
||||
# define tzset rpl_tzset
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (tzset, void, (void));
|
||||
_GL_CXXALIAS_RPL (tzset, void, (void));
|
||||
# else
|
||||
# if ! @HAVE_TZSET@
|
||||
_GL_FUNCDECL_SYS (tzset, void, (void));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (tzset, void, (void));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (tzset);
|
||||
# endif
|
||||
|
||||
/* Return the 'time_t' representation of TP and normalize TP. */
|
||||
# if @GNULIB_MKTIME@
|
||||
# if @REPLACE_MKTIME@
|
||||
|
|
@ -187,7 +205,7 @@ _GL_CXXALIASWARN (gmtime_r);
|
|||
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
|
||||
<http://www.opengroup.org/susv3xsh/localtime.html> and
|
||||
<http://www.opengroup.org/susv3xsh/gmtime.html>. */
|
||||
# if @GNULIB_GETTIMEOFDAY@
|
||||
# if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
|
||||
# if @REPLACE_LOCALTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef localtime
|
||||
|
|
@ -202,7 +220,7 @@ _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
|
|||
_GL_CXXALIASWARN (localtime);
|
||||
# endif
|
||||
|
||||
# if @GNULIB_GETTIMEOFDAY@
|
||||
# if 0 || @REPLACE_GMTIME@
|
||||
# if @REPLACE_GMTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef gmtime
|
||||
|
|
@ -233,6 +251,41 @@ _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
|
|||
_GL_CXXALIASWARN (strptime);
|
||||
# endif
|
||||
|
||||
/* Convert *TP to a date and time string. See
|
||||
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
|
||||
# if @GNULIB_CTIME@
|
||||
# if @REPLACE_CTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ctime rpl_ctime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (ctime);
|
||||
# endif
|
||||
|
||||
/* Convert *TP to a date and time string. See
|
||||
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
|
||||
# if @GNULIB_STRFTIME@
|
||||
# if @REPLACE_STRFTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define strftime rpl_strftime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
|
||||
const char *__fmt, const struct tm *__tp)
|
||||
_GL_ARG_NONNULL ((1, 3, 4)));
|
||||
_GL_CXXALIAS_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
|
||||
const char *__fmt, const struct tm *__tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (strftime, size_t, (char *__buf, size_t __bufsize,
|
||||
const char *__fmt, const struct tm *__tp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (strftime);
|
||||
# endif
|
||||
|
||||
# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
|
||||
typedef struct tm_zone *timezone_t;
|
||||
_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
|
||||
|
|
|
|||
|
|
@ -127,11 +127,18 @@
|
|||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
/* Get getopt(), optarg, optind, opterr, optopt.
|
||||
But avoid namespace pollution on glibc systems. */
|
||||
#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
|
||||
# define __need_getopt
|
||||
# include <getopt.h>
|
||||
# include <getopt-cdefs.h>
|
||||
# include <getopt-pfx-core.h>
|
||||
#endif
|
||||
|
||||
#ifndef _GL_INLINE_HEADER_BEGIN
|
||||
|
|
@ -142,13 +149,6 @@ _GL_INLINE_HEADER_BEGIN
|
|||
# define _GL_UNISTD_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
/* Hide some function declarations from <winsock2.h>. */
|
||||
|
||||
#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
|
||||
|
|
@ -1457,6 +1457,36 @@ _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
|
|||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_TRUNCATE@
|
||||
/* Change the size of the file designated by FILENAME to become equal to LENGTH.
|
||||
Return 0 if successful, otherwise -1 and errno set.
|
||||
See the POSIX:2008 specification
|
||||
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html>. */
|
||||
# if @REPLACE_TRUNCATE@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef truncate
|
||||
# define truncate rpl_truncate
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (truncate, int, (const char *filename, off_t length)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (truncate, int, (const char *filename, off_t length));
|
||||
# else
|
||||
# if !@HAVE_TRUNCATE@
|
||||
_GL_FUNCDECL_SYS (truncate, int, (const char *filename, off_t length)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (truncate, int, (const char *filename, off_t length));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (truncate);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef truncate
|
||||
# if HAVE_RAW_DECL_TRUNCATE
|
||||
_GL_WARN_ON_USE (truncate, "truncate is unportable - "
|
||||
"use gnulib module truncate for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_TTYNAME_R@
|
||||
/* Store at most BUFLEN characters of the pathname of the terminal FD is
|
||||
open on in BUF. Return 0 on success, otherwise an error number. */
|
||||
|
|
|
|||
|
|
@ -118,6 +118,14 @@
|
|||
# include "fpucw.h"
|
||||
#endif
|
||||
|
||||
#ifndef FALLTHROUGH
|
||||
# if __GNUC__ < 7
|
||||
# define FALLTHROUGH ((void) 0)
|
||||
# else
|
||||
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Default parameters. */
|
||||
#ifndef VASNPRINTF
|
||||
# if WIDE_CHAR_VERSION
|
||||
|
|
@ -156,6 +164,7 @@
|
|||
# define SNPRINTF snwprintf
|
||||
# else
|
||||
# define SNPRINTF _snwprintf
|
||||
# define USE_MSVC__SNPRINTF 1
|
||||
# endif
|
||||
# else
|
||||
/* Unix. */
|
||||
|
|
@ -181,7 +190,9 @@
|
|||
/* Here we need to call the native snprintf, not rpl_snprintf. */
|
||||
# undef snprintf
|
||||
# else
|
||||
/* MSVC versions < 14 did not have snprintf, only _snprintf. */
|
||||
# define SNPRINTF _snprintf
|
||||
# define USE_MSVC__SNPRINTF 1
|
||||
# endif
|
||||
# else
|
||||
/* Unix. */
|
||||
|
|
@ -208,7 +219,7 @@
|
|||
#undef remainder
|
||||
#define remainder rem
|
||||
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && !WIDE_CHAR_VERSION
|
||||
# if (HAVE_STRNLEN && !defined _AIX)
|
||||
# define local_strnlen strnlen
|
||||
# else
|
||||
|
|
@ -224,7 +235,7 @@ local_strnlen (const char *string, size_t maxlen)
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
|
||||
#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
|
||||
# if HAVE_WCSLEN
|
||||
# define local_wcslen wcslen
|
||||
# else
|
||||
|
|
@ -247,7 +258,7 @@ local_wcslen (const wchar_t *s)
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
|
||||
# if HAVE_WCSNLEN
|
||||
# define local_wcsnlen wcsnlen
|
||||
# else
|
||||
|
|
@ -1517,7 +1528,7 @@ is_borderline (const char *digits, size_t precision)
|
|||
|
||||
#endif
|
||||
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
|
||||
|
||||
/* Use a different function name, to make it possible that the 'wchar_t'
|
||||
parametrization and the 'char' parametrization get compiled in the same
|
||||
|
|
@ -2392,7 +2403,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
}
|
||||
}
|
||||
#endif
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
|
||||
#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
|
||||
else if (dp->conversion == 's'
|
||||
# if WIDE_CHAR_VERSION
|
||||
&& a.arg[dp->arg_index].type != TYPE_WIDE_STRING
|
||||
|
|
@ -4591,10 +4602,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
int has_width;
|
||||
#endif
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
size_t width;
|
||||
#endif
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
int has_precision;
|
||||
size_t precision;
|
||||
#endif
|
||||
|
|
@ -4623,7 +4634,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
has_width = 0;
|
||||
#endif
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
width = 0;
|
||||
if (dp->width_start != dp->width_end)
|
||||
{
|
||||
|
|
@ -4657,7 +4668,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
|
||||
has_precision = 0;
|
||||
precision = 6;
|
||||
if (dp->precision_start != dp->precision_end)
|
||||
|
|
@ -4834,7 +4845,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
*fbp++ = 'l';
|
||||
# endif
|
||||
#endif
|
||||
/*FALLTHROUGH*/
|
||||
FALLTHROUGH;
|
||||
case TYPE_LONGINT:
|
||||
case TYPE_ULONGINT:
|
||||
#if HAVE_WINT_T
|
||||
|
|
@ -4858,7 +4869,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
#endif
|
||||
*fbp = dp->conversion;
|
||||
#if USE_SNPRINTF
|
||||
# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
|
||||
# if ! (((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
|
||||
&& !defined __UCLIBC__) \
|
||||
|| (defined __APPLE__ && defined __MACH__) \
|
||||
|| ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
|
||||
fbp[1] = '%';
|
||||
fbp[2] = 'n';
|
||||
fbp[3] = '\0';
|
||||
|
|
@ -4872,6 +4886,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
in format strings in writable memory may crash the program
|
||||
(if compiled with _FORTIFY_SOURCE=2), so we should avoid it
|
||||
in this situation. */
|
||||
/* On Mac OS X 10.3 or newer, we know that snprintf's return
|
||||
value conforms to ISO C 99: the tests gl_SNPRINTF_RETVAL_C99
|
||||
and gl_SNPRINTF_TRUNCATION_C99 pass.
|
||||
Therefore we can avoid using %n in this situation.
|
||||
On Mac OS X 10.13 or newer, the use of %n in format strings
|
||||
in writable memory by default crashes the program, so we
|
||||
should avoid it in this situation. */
|
||||
/* On native Windows systems (such as mingw), we can avoid using
|
||||
%n because:
|
||||
- Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
|
||||
|
|
@ -5127,7 +5148,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
|
|||
/* Look at the snprintf() return value. */
|
||||
if (retcount < 0)
|
||||
{
|
||||
# if !HAVE_SNPRINTF_RETVAL_C99
|
||||
# if !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
|
||||
/* HP-UX 10.20 snprintf() is doubly deficient:
|
||||
It doesn't understand the '%n' directive,
|
||||
*and* it returns -1 (rather than the length
|
||||
|
|
|
|||
109
lib/warn-on-use.h
Normal file
109
lib/warn-on-use.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
This macro is useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead. However, one of the reasons that a function is a
|
||||
portability trap is if it has the wrong signature. Declaring
|
||||
FUNCTION with a different signature in C is a compilation error, so
|
||||
this macro must use the same type as any existing declaration so
|
||||
that programs that avoid the problematic FUNCTION do not fail to
|
||||
compile merely because they included a header that poisoned the
|
||||
function. But this implies that _GL_WARN_ON_USE is only safe to
|
||||
use if FUNCTION is known to already have a declaration. Use of
|
||||
this macro implies that there must not be any other macro hiding
|
||||
the declaration of FUNCTION; but undefining FUNCTION first is part
|
||||
of the poisoning process anyway (although for symbols that are
|
||||
provided only via a macro, the result is a compilation error rather
|
||||
than a warning containing "literal string"). Also note that in
|
||||
C++, it is only safe to use if FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
extern __typeof__ (function) function
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
|
||||
is like _GL_WARN_ON_USE (function, "string"), except that the function is
|
||||
declared with the given prototype, consisting of return type, parameters,
|
||||
and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
extern rettype function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
extern rettype function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
|
@ -113,12 +113,16 @@
|
|||
# define WEOF -1
|
||||
# endif
|
||||
#else
|
||||
/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h>.
|
||||
This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
|
||||
"unchanged by default argument promotions". Override it. */
|
||||
/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
|
||||
<stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
|
||||
wint_t must be "unchanged by default argument promotions". Override it. */
|
||||
# if @GNULIB_OVERRIDES_WINT_T@
|
||||
# if !GNULIB_defined_wint_t
|
||||
# include <crtdefs.h>
|
||||
# if @HAVE_CRTDEFS_H@
|
||||
# include <crtdefs.h>
|
||||
# else
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
typedef unsigned int rpl_wint_t;
|
||||
# undef wint_t
|
||||
# define wint_t rpl_wint_t
|
||||
|
|
@ -1036,6 +1040,38 @@ _GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
|
|||
#endif
|
||||
|
||||
|
||||
/* Convert *TP to a date and time wide string. See
|
||||
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>. */
|
||||
#if @GNULIB_WCSFTIME@
|
||||
# if @REPLACE_WCSFTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcsftime
|
||||
# define wcsftime rpl_wcsftime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
|
||||
const wchar_t *__fmt, const struct tm *__tp)
|
||||
_GL_ARG_NONNULL ((1, 3, 4)));
|
||||
_GL_CXXALIAS_RPL (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
|
||||
const wchar_t *__fmt, const struct tm *__tp));
|
||||
# else
|
||||
# if !@HAVE_WCSFTIME@
|
||||
_GL_FUNCDECL_SYS (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
|
||||
const wchar_t *__fmt, const struct tm *__tp)
|
||||
_GL_ARG_NONNULL ((1, 3, 4)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
|
||||
const wchar_t *__fmt, const struct tm *__tp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcsftime);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsftime
|
||||
# if HAVE_RAW_DECL_WCSFTIME
|
||||
_GL_WARN_ON_USE (wcsftime, "wcsftime is unportable - "
|
||||
"use gnulib module wcsftime for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_WCHAR_H */
|
||||
#endif /* _@GUARD_PREFIX@_WCHAR_H */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -56,11 +56,13 @@
|
|||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
/* mingw has declarations of towupper and towlower in <ctype.h> as
|
||||
well <wctype.h>. Include <ctype.h> in advance to avoid rpl_ prefix
|
||||
being added to the declarations. */
|
||||
#ifdef __MINGW32__
|
||||
/* Native Windows (mingw, MSVC) have declarations of towupper, towlower, and
|
||||
isw* functions in <ctype.h>, <wchar.h> as well as in <wctype.h>. Include
|
||||
<ctype.h>, <wchar.h> in advance to avoid rpl_ prefix being added to the
|
||||
declarations. */
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
# include <ctype.h>
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
/* Include the original <wctype.h> if it exists.
|
||||
|
|
@ -105,12 +107,16 @@ _GL_INLINE_HEADER_BEGIN
|
|||
# define WEOF -1
|
||||
# endif
|
||||
#else
|
||||
/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h>.
|
||||
This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
|
||||
"unchanged by default argument promotions". Override it. */
|
||||
/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
|
||||
<stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
|
||||
wint_t must be "unchanged by default argument promotions". Override it. */
|
||||
# if @GNULIB_OVERRIDES_WINT_T@
|
||||
# if !GNULIB_defined_wint_t
|
||||
# include <crtdefs.h>
|
||||
# if @HAVE_CRTDEFS_H@
|
||||
# include <crtdefs.h>
|
||||
# else
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
typedef unsigned int rpl_wint_t;
|
||||
# undef wint_t
|
||||
# define wint_t rpl_wint_t
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ typedef size_t __xalloc_count_type;
|
|||
#if 7 <= __GNUC__
|
||||
# define xalloc_oversized(n, s) \
|
||||
__builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
|
||||
#elif 5 <= __GNUC__ && !__STRICT_ANSI__
|
||||
#elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__
|
||||
# define xalloc_oversized(n, s) \
|
||||
(__builtin_constant_p (n) && __builtin_constant_p (s) \
|
||||
? __xalloc_oversized (n, s) \
|
||||
|
|
|
|||
|
|
@ -194,6 +194,8 @@ x2nrealloc (void *p, size_t *pn, size_t s)
|
|||
n = DEFAULT_MXFAST / s;
|
||||
n += !n;
|
||||
}
|
||||
if (xalloc_oversized (n, s))
|
||||
xalloc_die ();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue