mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 00:37:00 +08:00
added cloexec module
This commit is contained in:
306
gl/Makefile.am
306
gl/Makefile.am
@@ -21,7 +21,7 @@
|
||||
# the same distribution terms as the rest of that program.
|
||||
#
|
||||
# Generated by gnulib-tool.
|
||||
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl gettime hash-pjw-bare memmem
|
||||
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec gettime hash-pjw-bare memmem
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.5 gnits
|
||||
|
||||
@@ -49,6 +49,93 @@ libgnu_a_LIBADD = $(gl_LIBOBJS)
|
||||
libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
|
||||
EXTRA_libgnu_a_SOURCES =
|
||||
|
||||
## begin gnulib module cloexec
|
||||
|
||||
libgnu_a_SOURCES += cloexec.c
|
||||
|
||||
EXTRA_DIST += cloexec.h
|
||||
|
||||
## end gnulib module cloexec
|
||||
|
||||
## begin gnulib module close
|
||||
|
||||
|
||||
EXTRA_DIST += close.c
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += close.c
|
||||
|
||||
## end gnulib module close
|
||||
|
||||
## begin gnulib module dup2
|
||||
|
||||
|
||||
EXTRA_DIST += dup2.c
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += dup2.c
|
||||
|
||||
## end gnulib module dup2
|
||||
|
||||
## begin gnulib module fcntl
|
||||
|
||||
|
||||
EXTRA_DIST += fcntl.c
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += fcntl.c
|
||||
|
||||
## end gnulib module fcntl
|
||||
|
||||
## begin gnulib module fcntl-h
|
||||
|
||||
BUILT_SOURCES += fcntl.h
|
||||
|
||||
# We need the following in order to create <fcntl.h> when the system
|
||||
# doesn't have one that works with the given compiler.
|
||||
fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
|
||||
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
|
||||
-e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
|
||||
-e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
|
||||
-e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
|
||||
-e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
|
||||
-e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
|
||||
-e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
|
||||
-e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
|
||||
-e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
|
||||
-e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|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)' \
|
||||
< $(srcdir)/fcntl.in.h; \
|
||||
} > $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += fcntl.h fcntl.h-t
|
||||
|
||||
EXTRA_DIST += fcntl.in.h
|
||||
|
||||
## end gnulib module fcntl-h
|
||||
|
||||
## begin gnulib module fd-hook
|
||||
|
||||
libgnu_a_SOURCES += fd-hook.c
|
||||
|
||||
EXTRA_DIST += fd-hook.h
|
||||
|
||||
## end gnulib module fd-hook
|
||||
|
||||
## begin gnulib module getdtablesize
|
||||
|
||||
|
||||
EXTRA_DIST += getdtablesize.c
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += getdtablesize.c
|
||||
|
||||
## end gnulib module getdtablesize
|
||||
|
||||
## begin gnulib module gettime
|
||||
|
||||
libgnu_a_SOURCES += gettime.c
|
||||
@@ -88,6 +175,24 @@ EXTRA_libgnu_a_SOURCES += memmem.c
|
||||
|
||||
## end gnulib module memmem-simple
|
||||
|
||||
## begin gnulib module msvc-inval
|
||||
|
||||
|
||||
EXTRA_DIST += msvc-inval.c msvc-inval.h
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += msvc-inval.c
|
||||
|
||||
## end gnulib module msvc-inval
|
||||
|
||||
## begin gnulib module msvc-nothrow
|
||||
|
||||
|
||||
EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += msvc-nothrow.c
|
||||
|
||||
## end gnulib module msvc-nothrow
|
||||
|
||||
## begin gnulib module snippet/arg-nonnull
|
||||
|
||||
# The BUILT_SOURCES created by this Makefile snippet are not used via #include
|
||||
@@ -157,6 +262,29 @@ EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h
|
||||
|
||||
## end gnulib module snippet/warn-on-use
|
||||
|
||||
## begin gnulib module stdbool
|
||||
|
||||
BUILT_SOURCES += $(STDBOOL_H)
|
||||
|
||||
# We need the following in order to create <stdbool.h> when the system
|
||||
# doesn't have one that works.
|
||||
if GL_GENERATE_STDBOOL_H
|
||||
stdbool.h: stdbool.in.h $(top_builddir)/config.status
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \
|
||||
} > $@-t && \
|
||||
mv $@-t $@
|
||||
else
|
||||
stdbool.h: $(top_builddir)/config.status
|
||||
rm -f $@
|
||||
endif
|
||||
MOSTLYCLEANFILES += stdbool.h stdbool.h-t
|
||||
|
||||
EXTRA_DIST += stdbool.in.h
|
||||
|
||||
## end gnulib module stdbool
|
||||
|
||||
## begin gnulib module stddef
|
||||
|
||||
BUILT_SOURCES += $(STDDEF_H)
|
||||
@@ -371,6 +499,31 @@ EXTRA_DIST += sys_time.in.h
|
||||
|
||||
## end gnulib module sys_time
|
||||
|
||||
## begin gnulib module sys_types
|
||||
|
||||
BUILT_SOURCES += sys/types.h
|
||||
|
||||
# We need the following in order to create <sys/types.h> when the system
|
||||
# doesn't have one that works with the given compiler.
|
||||
sys/types.h: sys_types.in.h $(top_builddir)/config.status
|
||||
$(AM_V_at)$(MKDIR_P) sys
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
|
||||
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-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' \
|
||||
< $(srcdir)/sys_types.in.h; \
|
||||
} > $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += sys/types.h sys/types.h-t
|
||||
|
||||
EXTRA_DIST += sys_types.in.h
|
||||
|
||||
## end gnulib module sys_types
|
||||
|
||||
## begin gnulib module time
|
||||
|
||||
BUILT_SOURCES += time.h
|
||||
@@ -421,6 +574,157 @@ EXTRA_DIST += timespec.h
|
||||
|
||||
## end gnulib module timespec
|
||||
|
||||
## begin gnulib module unistd
|
||||
|
||||
BUILT_SOURCES += unistd.h
|
||||
libgnu_a_SOURCES += unistd.c
|
||||
|
||||
# We need the following in order to create an empty placeholder for
|
||||
# <unistd.h> when the system doesn't have one.
|
||||
unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
|
||||
$(AM_V_GEN)rm -f $@-t $@ && \
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
|
||||
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
|
||||
-e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
|
||||
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
|
||||
-e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
|
||||
-e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
|
||||
-e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \
|
||||
-e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \
|
||||
-e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \
|
||||
-e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \
|
||||
-e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \
|
||||
-e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \
|
||||
-e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \
|
||||
-e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \
|
||||
-e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \
|
||||
-e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \
|
||||
-e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \
|
||||
-e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \
|
||||
-e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \
|
||||
-e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \
|
||||
-e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \
|
||||
-e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \
|
||||
-e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \
|
||||
-e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \
|
||||
-e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \
|
||||
-e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \
|
||||
-e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \
|
||||
-e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \
|
||||
-e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \
|
||||
-e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \
|
||||
-e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \
|
||||
-e 's/@''GNULIB_LCHOWN''@/$(GNULIB_LCHOWN)/g' \
|
||||
-e 's/@''GNULIB_LINK''@/$(GNULIB_LINK)/g' \
|
||||
-e 's/@''GNULIB_LINKAT''@/$(GNULIB_LINKAT)/g' \
|
||||
-e 's/@''GNULIB_LSEEK''@/$(GNULIB_LSEEK)/g' \
|
||||
-e 's/@''GNULIB_PIPE''@/$(GNULIB_PIPE)/g' \
|
||||
-e 's/@''GNULIB_PIPE2''@/$(GNULIB_PIPE2)/g' \
|
||||
-e 's/@''GNULIB_PREAD''@/$(GNULIB_PREAD)/g' \
|
||||
-e 's/@''GNULIB_PWRITE''@/$(GNULIB_PWRITE)/g' \
|
||||
-e 's/@''GNULIB_READ''@/$(GNULIB_READ)/g' \
|
||||
-e 's/@''GNULIB_READLINK''@/$(GNULIB_READLINK)/g' \
|
||||
-e 's/@''GNULIB_READLINKAT''@/$(GNULIB_READLINKAT)/g' \
|
||||
-e 's/@''GNULIB_RMDIR''@/$(GNULIB_RMDIR)/g' \
|
||||
-e 's/@''GNULIB_SETHOSTNAME''@/$(GNULIB_SETHOSTNAME)/g' \
|
||||
-e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \
|
||||
-e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \
|
||||
-e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/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' \
|
||||
-e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GNULIB_UNISTD_H_SIGPIPE)/g' \
|
||||
-e 's/@''GNULIB_UNLINK''@/$(GNULIB_UNLINK)/g' \
|
||||
-e 's/@''GNULIB_UNLINKAT''@/$(GNULIB_UNLINKAT)/g' \
|
||||
-e 's/@''GNULIB_USLEEP''@/$(GNULIB_USLEEP)/g' \
|
||||
-e 's/@''GNULIB_WRITE''@/$(GNULIB_WRITE)/g' \
|
||||
< $(srcdir)/unistd.in.h | \
|
||||
sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
|
||||
-e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
|
||||
-e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
|
||||
-e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
|
||||
-e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
|
||||
-e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
|
||||
-e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
|
||||
-e 's|@''HAVE_FDATASYNC''@|$(HAVE_FDATASYNC)|g' \
|
||||
-e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
|
||||
-e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
|
||||
-e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
|
||||
-e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
|
||||
-e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
|
||||
-e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
|
||||
-e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
|
||||
-e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \
|
||||
-e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
|
||||
-e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
|
||||
-e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
|
||||
-e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \
|
||||
-e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
|
||||
-e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
|
||||
-e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \
|
||||
-e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
|
||||
-e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \
|
||||
-e 's|@''HAVE_SETHOSTNAME''@|$(HAVE_SETHOSTNAME)|g' \
|
||||
-e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
|
||||
-e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
|
||||
-e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
|
||||
-e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
|
||||
-e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
|
||||
-e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
|
||||
-e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
|
||||
-e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
|
||||
-e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
|
||||
-e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
|
||||
-e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
|
||||
-e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
|
||||
-e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \
|
||||
-e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
|
||||
-e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
|
||||
-e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
|
||||
| \
|
||||
sed -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
|
||||
-e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
|
||||
-e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
|
||||
-e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
|
||||
-e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
|
||||
-e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \
|
||||
-e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
|
||||
-e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
|
||||
-e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
|
||||
-e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
|
||||
-e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
|
||||
-e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \
|
||||
-e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
|
||||
-e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
|
||||
-e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \
|
||||
-e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
|
||||
-e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \
|
||||
-e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
|
||||
-e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \
|
||||
-e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
|
||||
-e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
|
||||
-e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
|
||||
-e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
|
||||
-e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
|
||||
-e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
|
||||
-e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
|
||||
-e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
|
||||
-e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
|
||||
-e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
|
||||
-e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|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)'; \
|
||||
} > $@-t && \
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += unistd.h unistd.h-t
|
||||
|
||||
EXTRA_DIST += unistd.in.h
|
||||
|
||||
## end gnulib module unistd
|
||||
|
||||
|
||||
mostlyclean-local: mostlyclean-generic
|
||||
@for dir in '' $(MOSTLYCLEANDIRS); do \
|
||||
|
||||
83
gl/cloexec.c
Normal file
83
gl/cloexec.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* closexec.c - set or clear the close-on-exec descriptor flag
|
||||
|
||||
Copyright (C) 1991, 2004-2006, 2009-2013 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/>.
|
||||
|
||||
The code is taken from glibc/manual/llio.texi */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "cloexec.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
|
||||
or clear the flag if VALUE is false.
|
||||
Return 0 on success, or -1 on error with 'errno' set.
|
||||
|
||||
Note that on MingW, this function does NOT protect DESC from being
|
||||
inherited into spawned children. Instead, either use dup_cloexec
|
||||
followed by closing the original DESC, or use interfaces such as
|
||||
open or pipe2 that accept flags like O_CLOEXEC to create DESC
|
||||
non-inheritable in the first place. */
|
||||
|
||||
int
|
||||
set_cloexec_flag (int desc, bool value)
|
||||
{
|
||||
#ifdef F_SETFD
|
||||
|
||||
int flags = fcntl (desc, F_GETFD, 0);
|
||||
|
||||
if (0 <= flags)
|
||||
{
|
||||
int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
|
||||
|
||||
if (flags == newflags
|
||||
|| fcntl (desc, F_SETFD, newflags) != -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
#else /* !F_SETFD */
|
||||
|
||||
/* Use dup2 to reject invalid file descriptors; the cloexec flag
|
||||
will be unaffected. */
|
||||
if (desc < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
if (dup2 (desc, desc) < 0)
|
||||
/* errno is EBADF here. */
|
||||
return -1;
|
||||
|
||||
/* There is nothing we can do on this kind of platform. Punt. */
|
||||
return 0;
|
||||
#endif /* !F_SETFD */
|
||||
}
|
||||
|
||||
|
||||
/* Duplicates a file handle FD, while marking the copy to be closed
|
||||
prior to exec or spawn. Returns -1 and sets errno if FD could not
|
||||
be duplicated. */
|
||||
|
||||
int
|
||||
dup_cloexec (int fd)
|
||||
{
|
||||
return fcntl (fd, F_DUPFD_CLOEXEC, 0);
|
||||
}
|
||||
38
gl/cloexec.h
Normal file
38
gl/cloexec.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* closexec.c - set or clear the close-on-exec descriptor flag
|
||||
|
||||
Copyright (C) 2004, 2009-2013 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/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
|
||||
or clear the flag if VALUE is false.
|
||||
Return 0 on success, or -1 on error with 'errno' set.
|
||||
|
||||
Note that on MingW, this function does NOT protect DESC from being
|
||||
inherited into spawned children. Instead, either use dup_cloexec
|
||||
followed by closing the original DESC, or use interfaces such as
|
||||
open or pipe2 that accept flags like O_CLOEXEC to create DESC
|
||||
non-inheritable in the first place. */
|
||||
|
||||
int set_cloexec_flag (int desc, bool value);
|
||||
|
||||
/* Duplicates a file handle FD, while marking the copy to be closed
|
||||
prior to exec or spawn. Returns -1 and sets errno if FD could not
|
||||
be duplicated. */
|
||||
|
||||
int dup_cloexec (int fd);
|
||||
69
gl/close.c
Normal file
69
gl/close.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* close replacement.
|
||||
Copyright (C) 2008-2013 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/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "fd-hook.h"
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#undef close
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static int
|
||||
close_nothrow (int fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = close (fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = -1;
|
||||
errno = EBADF;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
# define close_nothrow close
|
||||
#endif
|
||||
|
||||
/* Override close() to call into other gnulib modules. */
|
||||
|
||||
int
|
||||
rpl_close (int fd)
|
||||
{
|
||||
#if WINDOWS_SOCKETS
|
||||
int retval = execute_all_close_hooks (close_nothrow, fd);
|
||||
#else
|
||||
int retval = close_nothrow (fd);
|
||||
#endif
|
||||
|
||||
#if REPLACE_FCHDIR
|
||||
if (retval >= 0)
|
||||
_gl_unregister_fd (fd);
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
160
gl/dup2.c
Normal file
160
gl/dup2.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/* Duplicate an open file descriptor to a specified file descriptor.
|
||||
|
||||
Copyright (C) 1999, 2004-2007, 2009-2013 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 Paul Eggert */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if HAVE_DUP2
|
||||
|
||||
# undef dup2
|
||||
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
# include "msvc-inval.h"
|
||||
|
||||
/* Get _get_osfhandle. */
|
||||
# include "msvc-nothrow.h"
|
||||
|
||||
static int
|
||||
ms_windows_dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
|
||||
dup2 (fd, fd) returns 0, but all further attempts to use fd in
|
||||
future dup2 calls will hang. */
|
||||
if (fd == desired_fd)
|
||||
{
|
||||
if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
|
||||
http://bugs.winehq.org/show_bug.cgi?id=21289 */
|
||||
if (desired_fd < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = dup2 (fd, desired_fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
errno = EBADF;
|
||||
result = -1;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
if (result == 0)
|
||||
result = desired_fd;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
# define dup2 ms_windows_dup2
|
||||
|
||||
# endif
|
||||
|
||||
int
|
||||
rpl_dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
# ifdef F_GETFL
|
||||
/* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
|
||||
On Cygwin 1.5.x, dup2 (1, 1) returns 0.
|
||||
On Cygwin 1.7.17, dup2 (1, -1) dumps core.
|
||||
On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
|
||||
if (desired_fd < 0)
|
||||
fd = desired_fd;
|
||||
if (fd == desired_fd)
|
||||
return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
|
||||
# endif
|
||||
|
||||
result = dup2 (fd, desired_fd);
|
||||
|
||||
/* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
|
||||
if (result == -1 && errno == EMFILE)
|
||||
errno = EBADF;
|
||||
# if REPLACE_FCHDIR
|
||||
if (fd != desired_fd && result != -1)
|
||||
result = _gl_register_dup (fd, result);
|
||||
# endif
|
||||
return result;
|
||||
}
|
||||
|
||||
#else /* !HAVE_DUP2 */
|
||||
|
||||
/* On older platforms, dup2 did not exist. */
|
||||
|
||||
# ifndef F_DUPFD
|
||||
static int
|
||||
dupfd (int fd, int desired_fd)
|
||||
{
|
||||
int duplicated_fd = dup (fd);
|
||||
if (duplicated_fd < 0 || duplicated_fd == desired_fd)
|
||||
return duplicated_fd;
|
||||
else
|
||||
{
|
||||
int r = dupfd (fd, desired_fd);
|
||||
int e = errno;
|
||||
close (duplicated_fd);
|
||||
errno = e;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
int
|
||||
dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
|
||||
if (result == -1 || fd == desired_fd)
|
||||
return result;
|
||||
close (desired_fd);
|
||||
# ifdef F_DUPFD
|
||||
result = fcntl (fd, F_DUPFD, desired_fd);
|
||||
# if REPLACE_FCHDIR
|
||||
if (0 <= result)
|
||||
result = _gl_register_dup (fd, result);
|
||||
# endif
|
||||
# else
|
||||
result = dupfd (fd, desired_fd);
|
||||
# endif
|
||||
if (result == -1 && (errno == EMFILE || errno == EINVAL))
|
||||
errno = EBADF;
|
||||
return result;
|
||||
}
|
||||
#endif /* !HAVE_DUP2 */
|
||||
311
gl/fcntl.c
Normal file
311
gl/fcntl.c
Normal file
@@ -0,0 +1,311 @@
|
||||
/* Provide file descriptor control.
|
||||
|
||||
Copyright (C) 2009-2013 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 Eric Blake <ebb9@byu.net>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if !HAVE_FCNTL
|
||||
# define rpl_fcntl fcntl
|
||||
#endif
|
||||
#undef fcntl
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
/* Get _get_osfhandle. */
|
||||
# include "msvc-nothrow.h"
|
||||
|
||||
/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
|
||||
# define OPEN_MAX_MAX 0x10000
|
||||
|
||||
/* Duplicate OLDFD into the first available slot of at least NEWFD,
|
||||
which must be positive, with FLAGS determining whether the duplicate
|
||||
will be inheritable. */
|
||||
static int
|
||||
dupfd (int oldfd, int newfd, int flags)
|
||||
{
|
||||
/* Mingw has no way to create an arbitrary fd. Iterate until all
|
||||
file descriptors less than newfd are filled up. */
|
||||
HANDLE curr_process = GetCurrentProcess ();
|
||||
HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
|
||||
unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
|
||||
unsigned int fds_to_close_bound = 0;
|
||||
int result;
|
||||
BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
|
||||
int mode;
|
||||
|
||||
if (newfd < 0 || getdtablesize () <= newfd)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (old_handle == INVALID_HANDLE_VALUE
|
||||
|| (mode = setmode (oldfd, O_BINARY)) == -1)
|
||||
{
|
||||
/* oldfd is not open, or is an unassigned standard file
|
||||
descriptor. */
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
setmode (oldfd, mode);
|
||||
flags |= mode;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
HANDLE new_handle;
|
||||
int duplicated_fd;
|
||||
unsigned int index;
|
||||
|
||||
if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
|
||||
old_handle, /* SourceHandle */
|
||||
curr_process, /* TargetProcessHandle */
|
||||
(PHANDLE) &new_handle, /* TargetHandle */
|
||||
(DWORD) 0, /* DesiredAccess */
|
||||
inherit, /* InheritHandle */
|
||||
DUPLICATE_SAME_ACCESS)) /* Options */
|
||||
{
|
||||
/* TODO: Translate GetLastError () into errno. */
|
||||
errno = EMFILE;
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags);
|
||||
if (duplicated_fd < 0)
|
||||
{
|
||||
CloseHandle (new_handle);
|
||||
errno = EMFILE;
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if (newfd <= duplicated_fd)
|
||||
{
|
||||
result = duplicated_fd;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the bit duplicated_fd in fds_to_close[]. */
|
||||
index = (unsigned int) duplicated_fd / CHAR_BIT;
|
||||
if (fds_to_close_bound <= index)
|
||||
{
|
||||
if (sizeof fds_to_close <= index)
|
||||
/* Need to increase OPEN_MAX_MAX. */
|
||||
abort ();
|
||||
memset (fds_to_close + fds_to_close_bound, '\0',
|
||||
index + 1 - fds_to_close_bound);
|
||||
fds_to_close_bound = index + 1;
|
||||
}
|
||||
fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT);
|
||||
}
|
||||
|
||||
/* Close the previous fds that turned out to be too small. */
|
||||
{
|
||||
int saved_errno = errno;
|
||||
unsigned int duplicated_fd;
|
||||
|
||||
for (duplicated_fd = 0;
|
||||
duplicated_fd < fds_to_close_bound * CHAR_BIT;
|
||||
duplicated_fd++)
|
||||
if ((fds_to_close[duplicated_fd / CHAR_BIT]
|
||||
>> (duplicated_fd % CHAR_BIT))
|
||||
& 1)
|
||||
close (duplicated_fd);
|
||||
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
# if REPLACE_FCHDIR
|
||||
if (0 <= result)
|
||||
result = _gl_register_dup (oldfd, result);
|
||||
# endif
|
||||
return result;
|
||||
}
|
||||
#endif /* W32 */
|
||||
|
||||
/* Perform the specified ACTION on the file descriptor FD, possibly
|
||||
using the argument ARG further described below. This replacement
|
||||
handles the following actions, and forwards all others on to the
|
||||
native fcntl. An unrecognized ACTION returns -1 with errno set to
|
||||
EINVAL.
|
||||
|
||||
F_DUPFD - duplicate FD, with int ARG being the minimum target fd.
|
||||
If successful, return the duplicate, which will be inheritable;
|
||||
otherwise return -1 and set errno.
|
||||
|
||||
F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum
|
||||
target fd. If successful, return the duplicate, which will not be
|
||||
inheritable; otherwise return -1 and set errno.
|
||||
|
||||
F_GETFD - ARG need not be present. If successful, return a
|
||||
non-negative value containing the descriptor flags of FD (only
|
||||
FD_CLOEXEC is portable, but other flags may be present); otherwise
|
||||
return -1 and set errno. */
|
||||
|
||||
int
|
||||
rpl_fcntl (int fd, int action, /* arg */...)
|
||||
{
|
||||
va_list arg;
|
||||
int result = -1;
|
||||
va_start (arg, action);
|
||||
switch (action)
|
||||
{
|
||||
|
||||
#if !HAVE_FCNTL
|
||||
case F_DUPFD:
|
||||
{
|
||||
int target = va_arg (arg, int);
|
||||
result = dupfd (fd, target, 0);
|
||||
break;
|
||||
}
|
||||
#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
|
||||
case F_DUPFD:
|
||||
{
|
||||
int target = va_arg (arg, int);
|
||||
/* Detect invalid target; needed for cygwin 1.5.x. */
|
||||
if (target < 0 || getdtablesize () <= target)
|
||||
errno = EINVAL;
|
||||
else
|
||||
{
|
||||
/* Haiku alpha 2 loses fd flags on original. */
|
||||
int flags = fcntl (fd, F_GETFD);
|
||||
if (flags < 0)
|
||||
{
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
result = fcntl (fd, action, target);
|
||||
if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
close (result);
|
||||
result = -1;
|
||||
errno = saved_errno;
|
||||
}
|
||||
# if REPLACE_FCHDIR
|
||||
if (0 <= result)
|
||||
result = _gl_register_dup (fd, result);
|
||||
# endif
|
||||
}
|
||||
break;
|
||||
} /* F_DUPFD */
|
||||
#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */
|
||||
|
||||
case F_DUPFD_CLOEXEC:
|
||||
{
|
||||
int target = va_arg (arg, int);
|
||||
|
||||
#if !HAVE_FCNTL
|
||||
result = dupfd (fd, target, O_CLOEXEC);
|
||||
break;
|
||||
#else /* HAVE_FCNTL */
|
||||
/* Try the system call first, if the headers claim it exists
|
||||
(that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
|
||||
may be running with a glibc that has the macro but with an
|
||||
older kernel that does not support it. Cache the
|
||||
information on whether the system call really works, but
|
||||
avoid caching failure if the corresponding F_DUPFD fails
|
||||
for any reason. 0 = unknown, 1 = yes, -1 = no. */
|
||||
static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
|
||||
if (0 <= have_dupfd_cloexec)
|
||||
{
|
||||
result = fcntl (fd, action, target);
|
||||
if (0 <= result || errno != EINVAL)
|
||||
{
|
||||
have_dupfd_cloexec = 1;
|
||||
# if REPLACE_FCHDIR
|
||||
if (0 <= result)
|
||||
result = _gl_register_dup (fd, result);
|
||||
# endif
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rpl_fcntl (fd, F_DUPFD, target);
|
||||
if (result < 0)
|
||||
break;
|
||||
have_dupfd_cloexec = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
result = rpl_fcntl (fd, F_DUPFD, target);
|
||||
if (0 <= result && have_dupfd_cloexec == -1)
|
||||
{
|
||||
int flags = fcntl (result, F_GETFD);
|
||||
if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
close (result);
|
||||
errno = saved_errno;
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif /* HAVE_FCNTL */
|
||||
} /* F_DUPFD_CLOEXEC */
|
||||
|
||||
#if !HAVE_FCNTL
|
||||
case F_GETFD:
|
||||
{
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
HANDLE handle = (HANDLE) _get_osfhandle (fd);
|
||||
DWORD flags;
|
||||
if (handle == INVALID_HANDLE_VALUE
|
||||
|| GetHandleInformation (handle, &flags) == 0)
|
||||
errno = EBADF;
|
||||
else
|
||||
result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC;
|
||||
# else /* !W32 */
|
||||
/* Use dup2 to reject invalid file descriptors. No way to
|
||||
access this information, so punt. */
|
||||
if (0 <= dup2 (fd, fd))
|
||||
result = 0;
|
||||
# endif /* !W32 */
|
||||
break;
|
||||
} /* F_GETFD */
|
||||
#endif /* !HAVE_FCNTL */
|
||||
|
||||
/* Implementing F_SETFD on mingw is not trivial - there is no
|
||||
API for changing the O_NOINHERIT bit on an fd, and merely
|
||||
changing the HANDLE_FLAG_INHERIT bit on the underlying handle
|
||||
can lead to odd state. It may be possible by duplicating the
|
||||
handle, using _open_osfhandle with the right flags, then
|
||||
using dup2 to move the duplicate onto the original, but that
|
||||
is not supported for now. */
|
||||
|
||||
default:
|
||||
{
|
||||
#if HAVE_FCNTL
|
||||
void *p = va_arg (arg, void *);
|
||||
result = fcntl (fd, action, p);
|
||||
#else
|
||||
errno = EINVAL;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
va_end (arg);
|
||||
return result;
|
||||
}
|
||||
347
gl/fcntl.in.h
Normal file
347
gl/fcntl.in.h
Normal file
@@ -0,0 +1,347 @@
|
||||
/* Like <fcntl.h>, but with non-working flags defined to 0.
|
||||
|
||||
Copyright (C) 2006-2013 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 Paul Eggert */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_system_fcntl_h
|
||||
/* Special invocation convention. */
|
||||
|
||||
/* Needed before <sys/stat.h>.
|
||||
May also define off_t to a 64-bit type on native Windows. */
|
||||
#include <sys/types.h>
|
||||
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
|
||||
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
|
||||
But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
|
||||
extern "C" { ... } block, which leads to errors in C++ mode with the
|
||||
overridden <sys/stat.h> from gnulib. These errors are known to be gone
|
||||
with g++ version >= 4.3. */
|
||||
#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_FCNTL_H
|
||||
|
||||
/* Needed before <sys/stat.h>.
|
||||
May also define off_t to a 64-bit type on native Windows. */
|
||||
#include <sys/types.h>
|
||||
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
|
||||
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
|
||||
But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
|
||||
extern "C" { ... } block, which leads to errors in C++ mode with the
|
||||
overridden <sys/stat.h> from gnulib. These errors are known to be gone
|
||||
with g++ version >= 4.3. */
|
||||
#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_FCNTL_H
|
||||
#define _@GUARD_PREFIX@_FCNTL_H
|
||||
|
||||
#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* Native Windows platforms declare open(), creat() in <io.h>. */
|
||||
#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
|
||||
&& ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
|
||||
# include <io.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. */
|
||||
|
||||
|
||||
/* Declare overridden functions. */
|
||||
|
||||
#if @GNULIB_FCNTL@
|
||||
# if @REPLACE_FCNTL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef fcntl
|
||||
# define fcntl rpl_fcntl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
|
||||
_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
|
||||
# else
|
||||
# if !@HAVE_FCNTL@
|
||||
_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (fcntl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fcntl
|
||||
# if HAVE_RAW_DECL_FCNTL
|
||||
_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
|
||||
"use gnulib module fcntl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_OPEN@
|
||||
# if @REPLACE_OPEN@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef open
|
||||
# define open rpl_open
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
# endif
|
||||
/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
|
||||
default argument. _GL_CXXALIASWARN does not work in this case. */
|
||||
# if !defined __hpux
|
||||
_GL_CXXALIASWARN (open);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef open
|
||||
/* Assume open is always declared. */
|
||||
_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
|
||||
"use gnulib module open for portability");
|
||||
#endif
|
||||
|
||||
#if @GNULIB_OPENAT@
|
||||
# if @REPLACE_OPENAT@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef openat
|
||||
# define openat rpl_openat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...));
|
||||
# else
|
||||
# if !@HAVE_OPENAT@
|
||||
_GL_FUNCDECL_SYS (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (openat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef openat
|
||||
# if HAVE_RAW_DECL_OPENAT
|
||||
_GL_WARN_ON_USE (openat, "openat is not portable - "
|
||||
"use gnulib module openat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Fix up the FD_* macros, only known to be missing on mingw. */
|
||||
|
||||
#ifndef FD_CLOEXEC
|
||||
# define FD_CLOEXEC 1
|
||||
#endif
|
||||
|
||||
/* Fix up the supported F_* macros. Intentionally leave other F_*
|
||||
macros undefined. Only known to be missing on mingw. */
|
||||
|
||||
#ifndef F_DUPFD_CLOEXEC
|
||||
# define F_DUPFD_CLOEXEC 0x40000000
|
||||
/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
|
||||
# define GNULIB_defined_F_DUPFD_CLOEXEC 1
|
||||
#else
|
||||
# define GNULIB_defined_F_DUPFD_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifndef F_DUPFD
|
||||
# define F_DUPFD 1
|
||||
#endif
|
||||
|
||||
#ifndef F_GETFD
|
||||
# define F_GETFD 2
|
||||
#endif
|
||||
|
||||
/* Fix up the O_* macros. */
|
||||
|
||||
#if !defined O_DIRECT && defined O_DIRECTIO
|
||||
/* Tru64 spells it 'O_DIRECTIO'. */
|
||||
# define O_DIRECT O_DIRECTIO
|
||||
#endif
|
||||
|
||||
#if !defined O_CLOEXEC && defined O_NOINHERIT
|
||||
/* Mingw spells it 'O_NOINHERIT'. */
|
||||
# define O_CLOEXEC O_NOINHERIT
|
||||
#endif
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
# define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DIRECT
|
||||
# define O_DIRECT 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
# define O_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DSYNC
|
||||
# define O_DSYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_EXEC
|
||||
# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
|
||||
#endif
|
||||
|
||||
#ifndef O_IGNORE_CTTY
|
||||
# define O_IGNORE_CTTY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NDELAY
|
||||
# define O_NDELAY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
# define O_NONBLOCK O_NDELAY
|
||||
#endif
|
||||
|
||||
/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
|
||||
value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
|
||||
or to 0 as fallback. */
|
||||
#if @GNULIB_NONBLOCKING@
|
||||
# if O_NONBLOCK
|
||||
# define GNULIB_defined_O_NONBLOCK 0
|
||||
# else
|
||||
# define GNULIB_defined_O_NONBLOCK 1
|
||||
# undef O_NONBLOCK
|
||||
# define O_NONBLOCK 0x40000000
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef O_NOCTTY
|
||||
# define O_NOCTTY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOFOLLOW
|
||||
# define O_NOFOLLOW 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOLINK
|
||||
# define O_NOLINK 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOLINKS
|
||||
# define O_NOLINKS 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOTRANS
|
||||
# define O_NOTRANS 0
|
||||
#endif
|
||||
|
||||
#ifndef O_RSYNC
|
||||
# define O_RSYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_SEARCH
|
||||
# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
|
||||
#endif
|
||||
|
||||
#ifndef O_SYNC
|
||||
# define O_SYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_TTY_INIT
|
||||
# define O_TTY_INIT 0
|
||||
#endif
|
||||
|
||||
#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
|
||||
# undef O_ACCMODE
|
||||
# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
|
||||
#endif
|
||||
|
||||
/* For systems that distinguish between text and binary I/O.
|
||||
O_BINARY is usually declared in fcntl.h */
|
||||
#if !defined O_BINARY && defined _O_BINARY
|
||||
/* For MSC-compatible compilers. */
|
||||
# define O_BINARY _O_BINARY
|
||||
# define O_TEXT _O_TEXT
|
||||
#endif
|
||||
|
||||
#if defined __BEOS__ || defined __HAIKU__
|
||||
/* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
|
||||
# undef O_BINARY
|
||||
# undef O_TEXT
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
# define O_TEXT 0
|
||||
#endif
|
||||
|
||||
/* Fix up the AT_* macros. */
|
||||
|
||||
/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
|
||||
value exceeds INT_MAX, so its use as an int doesn't conform to the
|
||||
C standard, and GCC and Sun C complain in some cases. If the bug
|
||||
is present, undef AT_FDCWD here, so it can be redefined below. */
|
||||
#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
|
||||
# undef AT_FDCWD
|
||||
#endif
|
||||
|
||||
/* Use the same bit pattern as Solaris 9, but with the proper
|
||||
signedness. The bit pattern is important, in case this actually is
|
||||
Solaris with the above workaround. */
|
||||
#ifndef AT_FDCWD
|
||||
# define AT_FDCWD (-3041965)
|
||||
#endif
|
||||
|
||||
/* Use the same values as Solaris 9. This shouldn't matter, but
|
||||
there's no real reason to differ. */
|
||||
#ifndef AT_SYMLINK_NOFOLLOW
|
||||
# define AT_SYMLINK_NOFOLLOW 4096
|
||||
#endif
|
||||
|
||||
#ifndef AT_REMOVEDIR
|
||||
# define AT_REMOVEDIR 1
|
||||
#endif
|
||||
|
||||
/* Solaris 9 lacks these two, so just pick unique values. */
|
||||
#ifndef AT_SYMLINK_FOLLOW
|
||||
# define AT_SYMLINK_FOLLOW 2
|
||||
#endif
|
||||
|
||||
#ifndef AT_EACCESS
|
||||
# define AT_EACCESS 4
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_FCNTL_H */
|
||||
#endif /* _@GUARD_PREFIX@_FCNTL_H */
|
||||
#endif
|
||||
116
gl/fd-hook.c
Normal file
116
gl/fd-hook.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/* Hook for making making file descriptor functions close(), ioctl() extensible.
|
||||
Copyright (C) 2009-2013 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2009.
|
||||
|
||||
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/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "fd-hook.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Currently, this entire code is only needed for the handling of sockets
|
||||
on native Windows platforms. */
|
||||
#if WINDOWS_SOCKETS
|
||||
|
||||
/* The first and last link in the doubly linked list.
|
||||
Initially the list is empty. */
|
||||
static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
|
||||
|
||||
int
|
||||
execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
|
||||
int fd)
|
||||
{
|
||||
if (remaining_list == &anchor)
|
||||
/* End of list reached. */
|
||||
return primary (fd);
|
||||
else
|
||||
return remaining_list->private_close_fn (remaining_list->private_next,
|
||||
primary, fd);
|
||||
}
|
||||
|
||||
int
|
||||
execute_all_close_hooks (gl_close_fn primary, int fd)
|
||||
{
|
||||
return execute_close_hooks (anchor.private_next, primary, fd);
|
||||
}
|
||||
|
||||
int
|
||||
execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg)
|
||||
{
|
||||
if (remaining_list == &anchor)
|
||||
/* End of list reached. */
|
||||
return primary (fd, request, arg);
|
||||
else
|
||||
return remaining_list->private_ioctl_fn (remaining_list->private_next,
|
||||
primary, fd, request, arg);
|
||||
}
|
||||
|
||||
int
|
||||
execute_all_ioctl_hooks (gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg)
|
||||
{
|
||||
return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
|
||||
}
|
||||
|
||||
void
|
||||
register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
|
||||
{
|
||||
if (close_hook == NULL)
|
||||
close_hook = execute_close_hooks;
|
||||
if (ioctl_hook == NULL)
|
||||
ioctl_hook = execute_ioctl_hooks;
|
||||
|
||||
if (link->private_next == NULL && link->private_prev == NULL)
|
||||
{
|
||||
/* Add the link to the doubly linked list. */
|
||||
link->private_next = anchor.private_next;
|
||||
link->private_prev = &anchor;
|
||||
link->private_close_fn = close_hook;
|
||||
link->private_ioctl_fn = ioctl_hook;
|
||||
anchor.private_next->private_prev = link;
|
||||
anchor.private_next = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The link is already in use. */
|
||||
if (link->private_close_fn != close_hook
|
||||
|| link->private_ioctl_fn != ioctl_hook)
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_fd_hook (struct fd_hook *link)
|
||||
{
|
||||
struct fd_hook *next = link->private_next;
|
||||
struct fd_hook *prev = link->private_prev;
|
||||
|
||||
if (next != NULL && prev != NULL)
|
||||
{
|
||||
/* The link is in use. Remove it from the doubly linked list. */
|
||||
prev->private_next = next;
|
||||
next->private_prev = prev;
|
||||
/* Clear the link, to mark it unused. */
|
||||
link->private_next = NULL;
|
||||
link->private_prev = NULL;
|
||||
link->private_close_fn = NULL;
|
||||
link->private_ioctl_fn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
119
gl/fd-hook.h
Normal file
119
gl/fd-hook.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/* Hook for making making file descriptor functions close(), ioctl() extensible.
|
||||
Copyright (C) 2009-2013 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 FD_HOOK_H
|
||||
#define FD_HOOK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Currently, this entire code is only needed for the handling of sockets
|
||||
on native Windows platforms. */
|
||||
#if WINDOWS_SOCKETS
|
||||
|
||||
|
||||
/* Type of function that closes FD. */
|
||||
typedef int (*gl_close_fn) (int fd);
|
||||
|
||||
/* Type of function that applies a control request to FD. */
|
||||
typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
|
||||
|
||||
/* An element of the list of file descriptor hooks.
|
||||
In CLOS (Common Lisp Object System) speak, it consists of an "around"
|
||||
method for the close() function and an "around" method for the ioctl()
|
||||
function.
|
||||
The fields of this structure are considered private. */
|
||||
struct fd_hook
|
||||
{
|
||||
/* Doubly linked list. */
|
||||
struct fd_hook *private_next;
|
||||
struct fd_hook *private_prev;
|
||||
/* Function that treats the types of FD that it knows about and calls
|
||||
execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback. */
|
||||
int (*private_close_fn) (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
/* Function that treats the types of FD that it knows about and calls
|
||||
execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
|
||||
fallback. */
|
||||
int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
};
|
||||
|
||||
/* This type of function closes FD, applying special knowledge for the FD
|
||||
types it knows about, and calls
|
||||
execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
|
||||
for the other FD types.
|
||||
In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
|
||||
and PRIMARY is the "primary" method for close(). */
|
||||
typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
|
||||
/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like close() would do. */
|
||||
extern int execute_close_hooks (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
|
||||
/* Execute all close hooks, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like close() would do. */
|
||||
extern int execute_all_close_hooks (gl_close_fn primary, int fd);
|
||||
|
||||
/* This type of function applies a control request to FD, applying special
|
||||
knowledge for the FD types it knows about, and calls
|
||||
execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
|
||||
for the other FD types.
|
||||
In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
|
||||
and PRIMARY is the "primary" method for ioctl(). */
|
||||
typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like ioctl() would do. */
|
||||
extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Execute all ioctl hooks, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like ioctl() would do. */
|
||||
extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Add a function pair to the list of file descriptor hooks.
|
||||
CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
|
||||
The LINK variable points to a piece of memory which is guaranteed to be
|
||||
accessible until the corresponding call to unregister_fd_hook. */
|
||||
extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
|
||||
struct fd_hook *link);
|
||||
|
||||
/* Removes a hook from the list of file descriptor hooks. */
|
||||
extern void unregister_fd_hook (struct fd_hook *link);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FD_HOOK_H */
|
||||
86
gl/getdtablesize.c
Normal file
86
gl/getdtablesize.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/* getdtablesize() function for platforms that don't have it.
|
||||
Copyright (C) 2008-2013 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2008.
|
||||
|
||||
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/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static int
|
||||
_setmaxstdio_nothrow (int newmax)
|
||||
{
|
||||
int result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _setmaxstdio (newmax);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
# define _setmaxstdio _setmaxstdio_nothrow
|
||||
#endif
|
||||
|
||||
/* Cache for the previous getdtablesize () result. */
|
||||
static int dtablesize;
|
||||
|
||||
int
|
||||
getdtablesize (void)
|
||||
{
|
||||
if (dtablesize == 0)
|
||||
{
|
||||
/* We are looking for the number N such that the valid file descriptors
|
||||
are 0..N-1. It can be obtained through a loop as follows:
|
||||
{
|
||||
int fd;
|
||||
for (fd = 3; fd < 65536; fd++)
|
||||
if (dup2 (0, fd) == -1)
|
||||
break;
|
||||
return fd;
|
||||
}
|
||||
On Windows XP, the result is 2048.
|
||||
The drawback of this loop is that it allocates memory for a libc
|
||||
internal array that is never freed.
|
||||
|
||||
The number N can also be obtained as the upper bound for
|
||||
_getmaxstdio (). _getmaxstdio () returns the maximum number of open
|
||||
FILE objects. The sanity check in _setmaxstdio reveals the maximum
|
||||
number of file descriptors. This too allocates memory, but it is
|
||||
freed when we call _setmaxstdio with the original value. */
|
||||
int orig_max_stdio = _getmaxstdio ();
|
||||
unsigned int bound;
|
||||
for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2)
|
||||
;
|
||||
_setmaxstdio (orig_max_stdio);
|
||||
dtablesize = bound;
|
||||
}
|
||||
return dtablesize;
|
||||
}
|
||||
|
||||
#endif
|
||||
33
gl/m4/close.m4
Normal file
33
gl/m4/close.m4
Normal file
@@ -0,0 +1,33 @@
|
||||
# close.m4 serial 8
|
||||
dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_CLOSE],
|
||||
[
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
AC_REQUIRE([gl_MSVC_INVAL])
|
||||
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
|
||||
REPLACE_CLOSE=1
|
||||
fi
|
||||
m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
|
||||
gl_PREREQ_SYS_H_WINSOCK2
|
||||
if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
|
||||
dnl Even if the 'socket' module is not used here, another part of the
|
||||
dnl application may use it and pass file descriptors that refer to
|
||||
dnl sockets to the close() function. So enable the support for sockets.
|
||||
REPLACE_CLOSE=1
|
||||
fi
|
||||
])
|
||||
dnl Replace close() for supporting the gnulib-defined fchdir() function,
|
||||
dnl to keep fchdir's bookkeeping up-to-date.
|
||||
m4_ifdef([gl_FUNC_FCHDIR], [
|
||||
if test $REPLACE_CLOSE = 0; then
|
||||
gl_TEST_FCHDIR
|
||||
if test $HAVE_FCHDIR = 0; then
|
||||
REPLACE_CLOSE=1
|
||||
fi
|
||||
fi
|
||||
])
|
||||
])
|
||||
84
gl/m4/dup2.m4
Normal file
84
gl/m4/dup2.m4
Normal file
@@ -0,0 +1,84 @@
|
||||
#serial 19
|
||||
dnl Copyright (C) 2002, 2005, 2007, 2009-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_DUP2],
|
||||
[
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
|
||||
AC_CHECK_FUNCS_ONCE([dup2])
|
||||
if test $ac_cv_func_dup2 = no; then
|
||||
HAVE_DUP2=0
|
||||
fi
|
||||
], [
|
||||
AC_DEFINE([HAVE_DUP2], [1], [Define to 1 if you have the 'dup2' function.])
|
||||
])
|
||||
if test $HAVE_DUP2 = 1; then
|
||||
AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
|
||||
[AC_RUN_IFELSE([
|
||||
AC_LANG_PROGRAM([[#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>]],
|
||||
[int result = 0;
|
||||
#ifdef FD_CLOEXEC
|
||||
if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
|
||||
result |= 1;
|
||||
#endif
|
||||
if (dup2 (1, 1) == 0)
|
||||
result |= 2;
|
||||
#ifdef FD_CLOEXEC
|
||||
if (fcntl (1, F_GETFD) != FD_CLOEXEC)
|
||||
result |= 4;
|
||||
#endif
|
||||
close (0);
|
||||
if (dup2 (0, 0) != -1)
|
||||
result |= 8;
|
||||
/* Many gnulib modules require POSIX conformance of EBADF. */
|
||||
if (dup2 (2, 1000000) == -1 && errno != EBADF)
|
||||
result |= 16;
|
||||
/* Flush out a cygwin core dump. */
|
||||
if (dup2 (2, -1) != -1 || errno != EBADF)
|
||||
result |= 32;
|
||||
return result;
|
||||
])
|
||||
],
|
||||
[gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
|
||||
[case "$host_os" in
|
||||
mingw*) # on this platform, dup2 always returns 0 for success
|
||||
gl_cv_func_dup2_works="guessing no" ;;
|
||||
cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
|
||||
gl_cv_func_dup2_works="guessing no" ;;
|
||||
linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
|
||||
# closed fd may yield -EBADF instead of -1 / errno=EBADF.
|
||||
gl_cv_func_dup2_works="guessing no" ;;
|
||||
freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF.
|
||||
gl_cv_func_dup2_works="guessing no" ;;
|
||||
haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
|
||||
gl_cv_func_dup2_works="guessing no" ;;
|
||||
*) gl_cv_func_dup2_works="guessing yes" ;;
|
||||
esac])
|
||||
])
|
||||
case "$gl_cv_func_dup2_works" in
|
||||
*yes) ;;
|
||||
*)
|
||||
REPLACE_DUP2=1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
dnl Replace dup2() for supporting the gnulib-defined fchdir() function,
|
||||
dnl to keep fchdir's bookkeeping up-to-date.
|
||||
m4_ifdef([gl_FUNC_FCHDIR], [
|
||||
gl_TEST_FCHDIR
|
||||
if test $HAVE_FCHDIR = 0; then
|
||||
if test $HAVE_DUP2 = 1; then
|
||||
REPLACE_DUP2=1
|
||||
fi
|
||||
fi
|
||||
])
|
||||
])
|
||||
|
||||
# Prerequisites of lib/dup2.c.
|
||||
AC_DEFUN([gl_PREREQ_DUP2], [])
|
||||
134
gl/m4/fcntl-o.m4
Normal file
134
gl/m4/fcntl-o.m4
Normal file
@@ -0,0 +1,134 @@
|
||||
# fcntl-o.m4 serial 4
|
||||
dnl Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl Written by Paul Eggert.
|
||||
|
||||
# Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
|
||||
# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
|
||||
# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
|
||||
AC_DEFUN([gl_FCNTL_O_FLAGS],
|
||||
[
|
||||
dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
|
||||
dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
|
||||
dnl AC_GNU_SOURCE.
|
||||
m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
|
||||
[AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
|
||||
[AC_REQUIRE([AC_GNU_SOURCE])])
|
||||
|
||||
AC_CHECK_HEADERS_ONCE([unistd.h])
|
||||
AC_CHECK_FUNCS_ONCE([symlink])
|
||||
AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
|
||||
[AC_RUN_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#else /* on Windows with MSVC */
|
||||
# include <io.h>
|
||||
# include <stdlib.h>
|
||||
# defined sleep(n) _sleep ((n) * 1000)
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#ifndef O_NOATIME
|
||||
#define O_NOATIME 0
|
||||
#endif
|
||||
#ifndef O_NOFOLLOW
|
||||
#define O_NOFOLLOW 0
|
||||
#endif
|
||||
static int const constants[] =
|
||||
{
|
||||
O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
|
||||
O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
|
||||
};
|
||||
]],
|
||||
[[
|
||||
int result = !constants;
|
||||
#if HAVE_SYMLINK
|
||||
{
|
||||
static char const sym[] = "conftest.sym";
|
||||
if (symlink ("/dev/null", sym) != 0)
|
||||
result |= 2;
|
||||
else
|
||||
{
|
||||
int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
|
||||
if (fd >= 0)
|
||||
{
|
||||
close (fd);
|
||||
result |= 4;
|
||||
}
|
||||
}
|
||||
if (unlink (sym) != 0 || symlink (".", sym) != 0)
|
||||
result |= 2;
|
||||
else
|
||||
{
|
||||
int fd = open (sym, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd >= 0)
|
||||
{
|
||||
close (fd);
|
||||
result |= 4;
|
||||
}
|
||||
}
|
||||
unlink (sym);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
static char const file[] = "confdefs.h";
|
||||
int fd = open (file, O_RDONLY | O_NOATIME);
|
||||
if (fd < 0)
|
||||
result |= 8;
|
||||
else
|
||||
{
|
||||
struct stat st0;
|
||||
if (fstat (fd, &st0) != 0)
|
||||
result |= 16;
|
||||
else
|
||||
{
|
||||
char c;
|
||||
sleep (1);
|
||||
if (read (fd, &c, 1) != 1)
|
||||
result |= 24;
|
||||
else
|
||||
{
|
||||
if (close (fd) != 0)
|
||||
result |= 32;
|
||||
else
|
||||
{
|
||||
struct stat st1;
|
||||
if (stat (file, &st1) != 0)
|
||||
result |= 40;
|
||||
else
|
||||
if (st0.st_atime != st1.st_atime)
|
||||
result |= 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;]])],
|
||||
[gl_cv_header_working_fcntl_h=yes],
|
||||
[case $? in #(
|
||||
4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
|
||||
64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
|
||||
68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
|
||||
*) gl_cv_header_working_fcntl_h='no';;
|
||||
esac],
|
||||
[gl_cv_header_working_fcntl_h=cross-compiling])])
|
||||
|
||||
case $gl_cv_header_working_fcntl_h in #(
|
||||
*O_NOATIME* | no | cross-compiling) ac_val=0;; #(
|
||||
*) ac_val=1;;
|
||||
esac
|
||||
AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
|
||||
[Define to 1 if O_NOATIME works.])
|
||||
|
||||
case $gl_cv_header_working_fcntl_h in #(
|
||||
*O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
|
||||
*) ac_val=1;;
|
||||
esac
|
||||
AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
|
||||
[Define to 1 if O_NOFOLLOW works.])
|
||||
])
|
||||
95
gl/m4/fcntl.m4
Normal file
95
gl/m4/fcntl.m4
Normal file
@@ -0,0 +1,95 @@
|
||||
# fcntl.m4 serial 5
|
||||
dnl Copyright (C) 2009-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# For now, this module ensures that fcntl()
|
||||
# - supports F_DUPFD correctly
|
||||
# - supports or emulates F_DUPFD_CLOEXEC
|
||||
# - supports F_GETFD
|
||||
# Still to be ported to mingw:
|
||||
# - F_SETFD
|
||||
# - F_GETFL, F_SETFL
|
||||
# - F_GETOWN, F_SETOWN
|
||||
# - F_GETLK, F_SETLK, F_SETLKW
|
||||
AC_DEFUN([gl_FUNC_FCNTL],
|
||||
[
|
||||
dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
|
||||
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
|
||||
AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_CHECK_FUNCS_ONCE([fcntl])
|
||||
if test $ac_cv_func_fcntl = no; then
|
||||
gl_REPLACE_FCNTL
|
||||
else
|
||||
dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
|
||||
dnl haiku alpha 2 F_DUPFD has wrong errno
|
||||
AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
|
||||
[gl_cv_func_fcntl_f_dupfd_works],
|
||||
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
]], [[int result = 0;
|
||||
if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
|
||||
if (errno != EINVAL) result |= 2;
|
||||
return result;
|
||||
]])],
|
||||
[gl_cv_func_fcntl_f_dupfd_works=yes],
|
||||
[gl_cv_func_fcntl_f_dupfd_works=no],
|
||||
[# Guess that it works on glibc systems
|
||||
case $host_os in #((
|
||||
*-gnu*) gl_cv_func_fcntl_f_dupfd_works="guessing yes";;
|
||||
*) gl_cv_func_fcntl_f_dupfd_works="guessing no";;
|
||||
esac])])
|
||||
case $gl_cv_func_fcntl_f_dupfd_works in
|
||||
*yes) ;;
|
||||
*) gl_REPLACE_FCNTL
|
||||
AC_DEFINE([FCNTL_DUPFD_BUGGY], [1], [Define this to 1 if F_DUPFD
|
||||
behavior does not match POSIX]) ;;
|
||||
esac
|
||||
|
||||
dnl Many systems lack F_DUPFD_CLOEXEC
|
||||
AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
|
||||
[gl_cv_func_fcntl_f_dupfd_cloexec],
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <fcntl.h>
|
||||
#ifndef F_DUPFD_CLOEXEC
|
||||
choke me
|
||||
#endif
|
||||
]])],
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#ifdef __linux__
|
||||
/* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
|
||||
it to support the semantics on older kernels that failed with EINVAL. */
|
||||
choke me
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_func_fcntl_f_dupfd_cloexec=yes],
|
||||
[gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])],
|
||||
[gl_cv_func_fcntl_f_dupfd_cloexec=no])])
|
||||
if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then
|
||||
gl_REPLACE_FCNTL
|
||||
dnl No witness macro needed for this bug.
|
||||
fi
|
||||
fi
|
||||
dnl Replace fcntl() for supporting the gnulib-defined fchdir() function,
|
||||
dnl to keep fchdir's bookkeeping up-to-date.
|
||||
m4_ifdef([gl_FUNC_FCHDIR], [
|
||||
gl_TEST_FCHDIR
|
||||
if test $HAVE_FCHDIR = 0; then
|
||||
gl_REPLACE_FCNTL
|
||||
fi
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_REPLACE_FCNTL],
|
||||
[
|
||||
AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
|
||||
AC_CHECK_FUNCS_ONCE([fcntl])
|
||||
if test $ac_cv_func_fcntl = no; then
|
||||
HAVE_FCNTL=0
|
||||
else
|
||||
REPLACE_FCNTL=1
|
||||
fi
|
||||
])
|
||||
50
gl/m4/fcntl_h.m4
Normal file
50
gl/m4/fcntl_h.m4
Normal file
@@ -0,0 +1,50 @@
|
||||
# serial 15
|
||||
# Configure fcntl.h.
|
||||
dnl Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl Written by Paul Eggert.
|
||||
|
||||
AC_DEFUN([gl_FCNTL_H],
|
||||
[
|
||||
AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
|
||||
AC_REQUIRE([gl_FCNTL_O_FLAGS])
|
||||
gl_NEXT_HEADERS([fcntl.h])
|
||||
|
||||
dnl Ensure the type pid_t gets defined.
|
||||
AC_REQUIRE([AC_TYPE_PID_T])
|
||||
|
||||
dnl Ensure the type mode_t gets defined.
|
||||
AC_REQUIRE([AC_TYPE_MODE_T])
|
||||
|
||||
dnl Check for declarations of anything we want to poison if the
|
||||
dnl corresponding gnulib module is not in use, if it is not common
|
||||
dnl enough to be declared everywhere.
|
||||
gl_WARN_ON_USE_PREPARE([[#include <fcntl.h>
|
||||
]], [fcntl openat])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
|
||||
[
|
||||
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
|
||||
AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
|
||||
gl_MODULE_INDICATOR_SET_VARIABLE([$1])
|
||||
dnl Define it also as a C macro, for the benefit of the unit tests.
|
||||
gl_MODULE_INDICATOR_FOR_TESTS([$1])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_FCNTL_H_DEFAULTS],
|
||||
[
|
||||
GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL])
|
||||
GNULIB_NONBLOCKING=0; AC_SUBST([GNULIB_NONBLOCKING])
|
||||
GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN])
|
||||
GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT])
|
||||
dnl Assume proper GNU behavior unless another module says otherwise.
|
||||
HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL])
|
||||
HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT])
|
||||
REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL])
|
||||
REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
|
||||
REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT])
|
||||
])
|
||||
17
gl/m4/getdtablesize.m4
Normal file
17
gl/m4/getdtablesize.m4
Normal file
@@ -0,0 +1,17 @@
|
||||
# getdtablesize.m4 serial 4
|
||||
dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_GETDTABLESIZE],
|
||||
[
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
AC_CHECK_FUNCS_ONCE([getdtablesize])
|
||||
if test $ac_cv_func_getdtablesize != yes; then
|
||||
HAVE_GETDTABLESIZE=0
|
||||
fi
|
||||
])
|
||||
|
||||
# Prerequisites of lib/getdtablesize.c.
|
||||
AC_DEFUN([gl_PREREQ_GETDTABLESIZE], [:])
|
||||
@@ -27,11 +27,12 @@
|
||||
|
||||
|
||||
# Specification in the form of a command-line invocation:
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl gettime hash-pjw-bare memmem
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec gettime hash-pjw-bare memmem
|
||||
|
||||
# Specification in the form of a few gnulib-tool.m4 macro invocations:
|
||||
gl_LOCAL_DIR([])
|
||||
gl_MODULES([
|
||||
cloexec
|
||||
gettime
|
||||
hash-pjw-bare
|
||||
memmem
|
||||
|
||||
@@ -39,9 +39,16 @@ AC_DEFUN([gl_EARLY],
|
||||
m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
|
||||
AC_REQUIRE([gl_PROG_AR_RANLIB])
|
||||
# Code from module clock-time:
|
||||
# Code from module cloexec:
|
||||
# Code from module close:
|
||||
# Code from module dup2:
|
||||
# Code from module extensions:
|
||||
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
|
||||
# Code from module extern-inline:
|
||||
# Code from module fcntl:
|
||||
# Code from module fcntl-h:
|
||||
# Code from module fd-hook:
|
||||
# Code from module getdtablesize:
|
||||
# Code from module gettime:
|
||||
# Code from module gettimeofday:
|
||||
# Code from module hash-pjw-bare:
|
||||
@@ -49,16 +56,22 @@ AC_DEFUN([gl_EARLY],
|
||||
# Code from module memchr:
|
||||
# Code from module memmem:
|
||||
# Code from module memmem-simple:
|
||||
# Code from module msvc-inval:
|
||||
# Code from module msvc-nothrow:
|
||||
# Code from module multiarch:
|
||||
# Code from module snippet/arg-nonnull:
|
||||
# Code from module snippet/c++defs:
|
||||
# Code from module snippet/warn-on-use:
|
||||
# Code from module ssize_t:
|
||||
# Code from module stdbool:
|
||||
# Code from module stddef:
|
||||
# Code from module stdint:
|
||||
# Code from module string:
|
||||
# Code from module sys_time:
|
||||
# Code from module sys_types:
|
||||
# Code from module time:
|
||||
# Code from module timespec:
|
||||
# Code from module unistd:
|
||||
])
|
||||
|
||||
# This macro should be invoked from ./configure.ac, in the section
|
||||
@@ -78,7 +91,31 @@ AC_DEFUN([gl_INIT],
|
||||
gl_COMMON
|
||||
gl_source_base='gl'
|
||||
gl_CLOCK_TIME
|
||||
gl_MODULE_INDICATOR_FOR_TESTS([cloexec])
|
||||
gl_FUNC_CLOSE
|
||||
if test $REPLACE_CLOSE = 1; then
|
||||
AC_LIBOBJ([close])
|
||||
fi
|
||||
gl_UNISTD_MODULE_INDICATOR([close])
|
||||
gl_FUNC_DUP2
|
||||
if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then
|
||||
AC_LIBOBJ([dup2])
|
||||
gl_PREREQ_DUP2
|
||||
fi
|
||||
gl_UNISTD_MODULE_INDICATOR([dup2])
|
||||
AC_REQUIRE([gl_EXTERN_INLINE])
|
||||
gl_FUNC_FCNTL
|
||||
if test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1; then
|
||||
AC_LIBOBJ([fcntl])
|
||||
fi
|
||||
gl_FCNTL_MODULE_INDICATOR([fcntl])
|
||||
gl_FCNTL_H
|
||||
gl_FUNC_GETDTABLESIZE
|
||||
if test $HAVE_GETDTABLESIZE = 0; then
|
||||
AC_LIBOBJ([getdtablesize])
|
||||
gl_PREREQ_GETDTABLESIZE
|
||||
fi
|
||||
gl_UNISTD_MODULE_INDICATOR([getdtablesize])
|
||||
gl_GETTIME
|
||||
gl_FUNC_GETTIMEOFDAY
|
||||
if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
|
||||
@@ -101,14 +138,27 @@ AC_DEFUN([gl_INIT],
|
||||
AC_LIBOBJ([memmem])
|
||||
fi
|
||||
gl_STRING_MODULE_INDICATOR([memmem])
|
||||
gl_MSVC_INVAL
|
||||
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
|
||||
AC_LIBOBJ([msvc-inval])
|
||||
fi
|
||||
gl_MSVC_NOTHROW
|
||||
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
|
||||
AC_LIBOBJ([msvc-nothrow])
|
||||
fi
|
||||
gl_MULTIARCH
|
||||
gt_TYPE_SSIZE_T
|
||||
AM_STDBOOL_H
|
||||
gl_STDDEF_H
|
||||
gl_STDINT_H
|
||||
gl_HEADER_STRING_H
|
||||
gl_HEADER_SYS_TIME_H
|
||||
AC_PROG_MKDIR_P
|
||||
gl_SYS_TYPES_H
|
||||
AC_PROG_MKDIR_P
|
||||
gl_HEADER_TIME_H
|
||||
gl_TIMESPEC
|
||||
gl_UNISTD_H
|
||||
# End of code from modules
|
||||
m4_ifval(gl_LIBSOURCES_LIST, [
|
||||
m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
|
||||
@@ -252,6 +302,15 @@ AC_DEFUN([gl_FILE_LIST], [
|
||||
build-aux/snippet/arg-nonnull.h
|
||||
build-aux/snippet/c++defs.h
|
||||
build-aux/snippet/warn-on-use.h
|
||||
lib/cloexec.c
|
||||
lib/cloexec.h
|
||||
lib/close.c
|
||||
lib/dup2.c
|
||||
lib/fcntl.c
|
||||
lib/fcntl.in.h
|
||||
lib/fd-hook.c
|
||||
lib/fd-hook.h
|
||||
lib/getdtablesize.c
|
||||
lib/gettime.c
|
||||
lib/gettimeofday.c
|
||||
lib/hash-pjw-bare.c
|
||||
@@ -259,18 +318,32 @@ AC_DEFUN([gl_FILE_LIST], [
|
||||
lib/memchr.c
|
||||
lib/memchr.valgrind
|
||||
lib/memmem.c
|
||||
lib/msvc-inval.c
|
||||
lib/msvc-inval.h
|
||||
lib/msvc-nothrow.c
|
||||
lib/msvc-nothrow.h
|
||||
lib/stdbool.in.h
|
||||
lib/stddef.in.h
|
||||
lib/stdint.in.h
|
||||
lib/str-two-way.h
|
||||
lib/string.in.h
|
||||
lib/sys_time.in.h
|
||||
lib/sys_types.in.h
|
||||
lib/time.in.h
|
||||
lib/timespec.c
|
||||
lib/timespec.h
|
||||
lib/unistd.c
|
||||
lib/unistd.in.h
|
||||
m4/00gnulib.m4
|
||||
m4/clock_time.m4
|
||||
m4/close.m4
|
||||
m4/dup2.m4
|
||||
m4/extensions.m4
|
||||
m4/extern-inline.m4
|
||||
m4/fcntl-o.m4
|
||||
m4/fcntl.m4
|
||||
m4/fcntl_h.m4
|
||||
m4/getdtablesize.m4
|
||||
m4/gettime.m4
|
||||
m4/gettimeofday.m4
|
||||
m4/gnulib-common.m4
|
||||
@@ -279,14 +352,21 @@ AC_DEFUN([gl_FILE_LIST], [
|
||||
m4/memchr.m4
|
||||
m4/memmem.m4
|
||||
m4/mmap-anon.m4
|
||||
m4/msvc-inval.m4
|
||||
m4/msvc-nothrow.m4
|
||||
m4/multiarch.m4
|
||||
m4/off_t.m4
|
||||
m4/ssize_t.m4
|
||||
m4/stdbool.m4
|
||||
m4/stddef_h.m4
|
||||
m4/stdint.m4
|
||||
m4/string_h.m4
|
||||
m4/sys_socket_h.m4
|
||||
m4/sys_time_h.m4
|
||||
m4/sys_types_h.m4
|
||||
m4/time_h.m4
|
||||
m4/timespec.m4
|
||||
m4/unistd_h.m4
|
||||
m4/warn-on-use.m4
|
||||
m4/wchar_t.m4
|
||||
])
|
||||
|
||||
19
gl/m4/msvc-inval.m4
Normal file
19
gl/m4/msvc-inval.m4
Normal file
@@ -0,0 +1,19 @@
|
||||
# msvc-inval.m4 serial 1
|
||||
dnl Copyright (C) 2011-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_MSVC_INVAL],
|
||||
[
|
||||
AC_CHECK_FUNCS_ONCE([_set_invalid_parameter_handler])
|
||||
if test $ac_cv_func__set_invalid_parameter_handler = yes; then
|
||||
HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
|
||||
AC_DEFINE([HAVE_MSVC_INVALID_PARAMETER_HANDLER], [1],
|
||||
[Define to 1 on MSVC platforms that have the "invalid parameter handler"
|
||||
concept.])
|
||||
else
|
||||
HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
|
||||
fi
|
||||
AC_SUBST([HAVE_MSVC_INVALID_PARAMETER_HANDLER])
|
||||
])
|
||||
10
gl/m4/msvc-nothrow.m4
Normal file
10
gl/m4/msvc-nothrow.m4
Normal file
@@ -0,0 +1,10 @@
|
||||
# msvc-nothrow.m4 serial 1
|
||||
dnl Copyright (C) 2011-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_MSVC_NOTHROW],
|
||||
[
|
||||
AC_REQUIRE([gl_MSVC_INVAL])
|
||||
])
|
||||
18
gl/m4/off_t.m4
Normal file
18
gl/m4/off_t.m4
Normal file
@@ -0,0 +1,18 @@
|
||||
# off_t.m4 serial 1
|
||||
dnl Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl Check whether to override the 'off_t' type.
|
||||
dnl Set WINDOWS_64_BIT_OFF_T.
|
||||
|
||||
AC_DEFUN([gl_TYPE_OFF_T],
|
||||
[
|
||||
m4_ifdef([gl_LARGEFILE], [
|
||||
AC_REQUIRE([gl_LARGEFILE])
|
||||
], [
|
||||
WINDOWS_64_BIT_OFF_T=0
|
||||
])
|
||||
AC_SUBST([WINDOWS_64_BIT_OFF_T])
|
||||
])
|
||||
23
gl/m4/ssize_t.m4
Normal file
23
gl/m4/ssize_t.m4
Normal file
@@ -0,0 +1,23 @@
|
||||
# ssize_t.m4 serial 5 (gettext-0.18.2)
|
||||
dnl Copyright (C) 2001-2003, 2006, 2010-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Bruno Haible.
|
||||
dnl Test whether ssize_t is defined.
|
||||
|
||||
AC_DEFUN([gt_TYPE_SSIZE_T],
|
||||
[
|
||||
AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <sys/types.h>]],
|
||||
[[int x = sizeof (ssize_t *) + sizeof (ssize_t);
|
||||
return !x;]])],
|
||||
[gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
|
||||
if test $gt_cv_ssize_t = no; then
|
||||
AC_DEFINE([ssize_t], [int],
|
||||
[Define as a signed type of the same size as size_t.])
|
||||
fi
|
||||
])
|
||||
100
gl/m4/stdbool.m4
Normal file
100
gl/m4/stdbool.m4
Normal file
@@ -0,0 +1,100 @@
|
||||
# Check for stdbool.h that conforms to C99.
|
||||
|
||||
dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
#serial 5
|
||||
|
||||
# Prepare for substituting <stdbool.h> if it is not supported.
|
||||
|
||||
AC_DEFUN([AM_STDBOOL_H],
|
||||
[
|
||||
AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
|
||||
|
||||
# Define two additional variables used in the Makefile substitution.
|
||||
|
||||
if test "$ac_cv_header_stdbool_h" = yes; then
|
||||
STDBOOL_H=''
|
||||
else
|
||||
STDBOOL_H='stdbool.h'
|
||||
fi
|
||||
AC_SUBST([STDBOOL_H])
|
||||
AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
|
||||
|
||||
if test "$ac_cv_type__Bool" = yes; then
|
||||
HAVE__BOOL=1
|
||||
else
|
||||
HAVE__BOOL=0
|
||||
fi
|
||||
AC_SUBST([HAVE__BOOL])
|
||||
])
|
||||
|
||||
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
|
||||
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
|
||||
|
||||
# This version of the macro is needed in autoconf <= 2.68.
|
||||
|
||||
AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
|
||||
[AC_CACHE_CHECK([for stdbool.h that conforms to C99],
|
||||
[ac_cv_header_stdbool_h],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[
|
||||
#include <stdbool.h>
|
||||
#ifndef bool
|
||||
"error: bool is not defined"
|
||||
#endif
|
||||
#ifndef false
|
||||
"error: false is not defined"
|
||||
#endif
|
||||
#if false
|
||||
"error: false is not 0"
|
||||
#endif
|
||||
#ifndef true
|
||||
"error: true is not defined"
|
||||
#endif
|
||||
#if true != 1
|
||||
"error: true is not 1"
|
||||
#endif
|
||||
#ifndef __bool_true_false_are_defined
|
||||
"error: __bool_true_false_are_defined is not defined"
|
||||
#endif
|
||||
|
||||
struct s { _Bool s: 1; _Bool t; } s;
|
||||
|
||||
char a[true == 1 ? 1 : -1];
|
||||
char b[false == 0 ? 1 : -1];
|
||||
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
|
||||
char d[(bool) 0.5 == true ? 1 : -1];
|
||||
/* See body of main program for 'e'. */
|
||||
char f[(_Bool) 0.0 == false ? 1 : -1];
|
||||
char g[true];
|
||||
char h[sizeof (_Bool)];
|
||||
char i[sizeof s.t];
|
||||
enum { j = false, k = true, l = false * true, m = true * 256 };
|
||||
/* The following fails for
|
||||
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
|
||||
_Bool n[m];
|
||||
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
|
||||
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
|
||||
/* Catch a bug in an HP-UX C compiler. See
|
||||
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
|
||||
*/
|
||||
_Bool q = true;
|
||||
_Bool *pq = &q;
|
||||
]],
|
||||
[[
|
||||
bool e = &s;
|
||||
*pq |= q;
|
||||
*pq |= ! q;
|
||||
/* Refer to every declared value, to avoid compiler optimizations. */
|
||||
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
|
||||
+ !m + !n + !o + !p + !q + !pq);
|
||||
]])],
|
||||
[ac_cv_header_stdbool_h=yes],
|
||||
[ac_cv_header_stdbool_h=no])])
|
||||
AC_CHECK_TYPES([_Bool])
|
||||
])
|
||||
24
gl/m4/sys_types_h.m4
Normal file
24
gl/m4/sys_types_h.m4
Normal file
@@ -0,0 +1,24 @@
|
||||
# sys_types_h.m4 serial 4
|
||||
dnl Copyright (C) 2011-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_SYS_TYPES_H],
|
||||
[
|
||||
AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
|
||||
gl_NEXT_HEADERS([sys/types.h])
|
||||
|
||||
dnl Ensure the type pid_t gets defined.
|
||||
AC_REQUIRE([AC_TYPE_PID_T])
|
||||
|
||||
dnl Ensure the type mode_t gets defined.
|
||||
AC_REQUIRE([AC_TYPE_MODE_T])
|
||||
|
||||
dnl Whether to override the 'off_t' type.
|
||||
AC_REQUIRE([gl_TYPE_OFF_T])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS],
|
||||
[
|
||||
])
|
||||
186
gl/m4/unistd_h.m4
Normal file
186
gl/m4/unistd_h.m4
Normal file
@@ -0,0 +1,186 @@
|
||||
# unistd_h.m4 serial 66
|
||||
dnl Copyright (C) 2006-2013 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl Written by Simon Josefsson, Bruno Haible.
|
||||
|
||||
AC_DEFUN([gl_UNISTD_H],
|
||||
[
|
||||
dnl Use AC_REQUIRE here, so that the default behavior below is expanded
|
||||
dnl once only, before all statements that occur in other macros.
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
|
||||
gl_CHECK_NEXT_HEADERS([unistd.h])
|
||||
if test $ac_cv_header_unistd_h = yes; then
|
||||
HAVE_UNISTD_H=1
|
||||
else
|
||||
HAVE_UNISTD_H=0
|
||||
fi
|
||||
AC_SUBST([HAVE_UNISTD_H])
|
||||
|
||||
dnl Ensure the type pid_t gets defined.
|
||||
AC_REQUIRE([AC_TYPE_PID_T])
|
||||
|
||||
dnl Determine WINDOWS_64_BIT_OFF_T.
|
||||
AC_REQUIRE([gl_TYPE_OFF_T])
|
||||
|
||||
dnl Check for declarations of anything we want to poison if the
|
||||
dnl corresponding gnulib module is not in use.
|
||||
gl_WARN_ON_USE_PREPARE([[
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
/* Some systems declare various items in the wrong headers. */
|
||||
#if !(defined __GLIBC__ && !defined __UCLIBC__)
|
||||
# include <fcntl.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
# include <io.h>
|
||||
# endif
|
||||
#endif
|
||||
]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat
|
||||
fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups
|
||||
gethostname getlogin getlogin_r getpagesize
|
||||
getusershell setusershell endusershell
|
||||
group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite
|
||||
readlink readlinkat rmdir sethostname sleep symlink symlinkat ttyname_r
|
||||
unlink unlinkat usleep])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
|
||||
[
|
||||
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
gl_MODULE_INDICATOR_SET_VARIABLE([$1])
|
||||
dnl Define it also as a C macro, for the benefit of the unit tests.
|
||||
gl_MODULE_INDICATOR_FOR_TESTS([$1])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_UNISTD_H_DEFAULTS],
|
||||
[
|
||||
GNULIB_CHDIR=0; AC_SUBST([GNULIB_CHDIR])
|
||||
GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
|
||||
GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE])
|
||||
GNULIB_DUP=0; AC_SUBST([GNULIB_DUP])
|
||||
GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
|
||||
GNULIB_DUP3=0; AC_SUBST([GNULIB_DUP3])
|
||||
GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON])
|
||||
GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS])
|
||||
GNULIB_FACCESSAT=0; AC_SUBST([GNULIB_FACCESSAT])
|
||||
GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
|
||||
GNULIB_FCHOWNAT=0; AC_SUBST([GNULIB_FCHOWNAT])
|
||||
GNULIB_FDATASYNC=0; AC_SUBST([GNULIB_FDATASYNC])
|
||||
GNULIB_FSYNC=0; AC_SUBST([GNULIB_FSYNC])
|
||||
GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
|
||||
GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
|
||||
GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME])
|
||||
GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE])
|
||||
GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS])
|
||||
GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME])
|
||||
GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN])
|
||||
GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
|
||||
GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
|
||||
GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL])
|
||||
GNULIB_GROUP_MEMBER=0; AC_SUBST([GNULIB_GROUP_MEMBER])
|
||||
GNULIB_ISATTY=0; AC_SUBST([GNULIB_ISATTY])
|
||||
GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
|
||||
GNULIB_LINK=0; AC_SUBST([GNULIB_LINK])
|
||||
GNULIB_LINKAT=0; AC_SUBST([GNULIB_LINKAT])
|
||||
GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
|
||||
GNULIB_PIPE=0; AC_SUBST([GNULIB_PIPE])
|
||||
GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2])
|
||||
GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD])
|
||||
GNULIB_PWRITE=0; AC_SUBST([GNULIB_PWRITE])
|
||||
GNULIB_READ=0; AC_SUBST([GNULIB_READ])
|
||||
GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
|
||||
GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT])
|
||||
GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR])
|
||||
GNULIB_SETHOSTNAME=0; AC_SUBST([GNULIB_SETHOSTNAME])
|
||||
GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
|
||||
GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK])
|
||||
GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT])
|
||||
GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R])
|
||||
GNULIB_UNISTD_H_NONBLOCKING=0; AC_SUBST([GNULIB_UNISTD_H_NONBLOCKING])
|
||||
GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE])
|
||||
GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK])
|
||||
GNULIB_UNLINKAT=0; AC_SUBST([GNULIB_UNLINKAT])
|
||||
GNULIB_USLEEP=0; AC_SUBST([GNULIB_USLEEP])
|
||||
GNULIB_WRITE=0; AC_SUBST([GNULIB_WRITE])
|
||||
dnl Assume proper GNU behavior unless another module says otherwise.
|
||||
HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN])
|
||||
HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
|
||||
HAVE_DUP3=1; AC_SUBST([HAVE_DUP3])
|
||||
HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS])
|
||||
HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT])
|
||||
HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR])
|
||||
HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT])
|
||||
HAVE_FDATASYNC=1; AC_SUBST([HAVE_FDATASYNC])
|
||||
HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC])
|
||||
HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
|
||||
HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE])
|
||||
HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS])
|
||||
HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME])
|
||||
HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN])
|
||||
HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
|
||||
HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER])
|
||||
HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN])
|
||||
HAVE_LINK=1; AC_SUBST([HAVE_LINK])
|
||||
HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT])
|
||||
HAVE_PIPE=1; AC_SUBST([HAVE_PIPE])
|
||||
HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2])
|
||||
HAVE_PREAD=1; AC_SUBST([HAVE_PREAD])
|
||||
HAVE_PWRITE=1; AC_SUBST([HAVE_PWRITE])
|
||||
HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
|
||||
HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT])
|
||||
HAVE_SETHOSTNAME=1; AC_SUBST([HAVE_SETHOSTNAME])
|
||||
HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
|
||||
HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK])
|
||||
HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT])
|
||||
HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT])
|
||||
HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP])
|
||||
HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON])
|
||||
HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR])
|
||||
HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC])
|
||||
HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME])
|
||||
HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
|
||||
HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
|
||||
HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL])
|
||||
HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME])
|
||||
HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R])
|
||||
HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
|
||||
HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
|
||||
REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
|
||||
REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE])
|
||||
REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
|
||||
REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2])
|
||||
REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
|
||||
REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE])
|
||||
REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
|
||||
REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME])
|
||||
REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R])
|
||||
REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS])
|
||||
REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
|
||||
REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY])
|
||||
REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
|
||||
REPLACE_LINK=0; AC_SUBST([REPLACE_LINK])
|
||||
REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT])
|
||||
REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
|
||||
REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD])
|
||||
REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE])
|
||||
REPLACE_READ=0; AC_SUBST([REPLACE_READ])
|
||||
REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK])
|
||||
REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR])
|
||||
REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP])
|
||||
REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK])
|
||||
REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R])
|
||||
REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK])
|
||||
REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT])
|
||||
REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP])
|
||||
REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE])
|
||||
UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
|
||||
UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
|
||||
AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
|
||||
])
|
||||
129
gl/msvc-inval.c
Normal file
129
gl/msvc-inval.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2013 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/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
|
||||
/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
|
||||
declaration. */
|
||||
# include <stdlib.h>
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
# if defined _MSC_VER
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* An index to thread-local storage. */
|
||||
static DWORD tls_index;
|
||||
static int tls_initialized /* = 0 */;
|
||||
|
||||
/* Used as a fallback only. */
|
||||
static struct gl_msvc_inval_per_thread not_per_thread;
|
||||
|
||||
struct gl_msvc_inval_per_thread *
|
||||
gl_msvc_inval_current (void)
|
||||
{
|
||||
if (!tls_initialized)
|
||||
{
|
||||
tls_index = TlsAlloc ();
|
||||
tls_initialized = 1;
|
||||
}
|
||||
if (tls_index == TLS_OUT_OF_INDEXES)
|
||||
/* TlsAlloc had failed. */
|
||||
return ¬_per_thread;
|
||||
else
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *pointer =
|
||||
(struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
|
||||
if (pointer == NULL)
|
||||
{
|
||||
/* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
|
||||
pointer =
|
||||
(struct gl_msvc_inval_per_thread *)
|
||||
malloc (sizeof (struct gl_msvc_inval_per_thread));
|
||||
if (pointer == NULL)
|
||||
/* Could not allocate memory. Use the global storage. */
|
||||
pointer = ¬_per_thread;
|
||||
TlsSetValue (tls_index, pointer);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
}
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
|
||||
if (current->restart_valid)
|
||||
longjmp (current->restart, 1);
|
||||
else
|
||||
/* An invalid parameter notification from outside the gnulib code.
|
||||
Give the caller a chance to intervene. */
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
static int gl_msvc_inval_initialized /* = 0 */;
|
||||
|
||||
void
|
||||
gl_msvc_inval_ensure_handler (void)
|
||||
{
|
||||
if (gl_msvc_inval_initialized == 0)
|
||||
{
|
||||
_set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
|
||||
gl_msvc_inval_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
222
gl/msvc-inval.h
Normal file
222
gl/msvc-inval.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2013 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/>. */
|
||||
|
||||
#ifndef _MSVC_INVAL_H
|
||||
#define _MSVC_INVAL_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines macros that turn such an invalid parameter notification
|
||||
into a non-local exit. An error code can then be produced at the target
|
||||
of this exit. You can thus write code like
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
<Code that can trigger an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
<Code that handles an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
This entire block expands to a single statement.
|
||||
|
||||
The handling of invalid parameters can be done in three ways:
|
||||
|
||||
* The default way, which is reasonable for programs (not libraries):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
|
||||
|
||||
* The way for libraries that make "hairy" calls (like close(-1), or
|
||||
fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
|
||||
|
||||
* The way for libraries that make no "hairy" calls:
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
|
||||
*/
|
||||
|
||||
#define DEFAULT_HANDLING 0
|
||||
#define HAIRY_LIBRARY_HANDLING 1
|
||||
#define SANE_LIBRARY_HANDLING 2
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
/* A native Windows platform with the "invalid parameter handler" concept,
|
||||
and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
/* Default handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that just returns.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Handling for hairy libraries. */
|
||||
|
||||
# include <excpt.h>
|
||||
|
||||
/* Gnulib can define its own status codes, as described in the page
|
||||
"Raising Software Exceptions" on microsoft.com
|
||||
<http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
|
||||
Our status codes are composed of
|
||||
- 0xE0000000, mandatory for all user-defined status codes,
|
||||
- 0x474E550, a API identifier ("GNU"),
|
||||
- 0, 1, 2, ..., used to distinguish different status codes from the
|
||||
same API. */
|
||||
# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
|
||||
|
||||
# if defined _MSC_VER
|
||||
/* A compiler that supports __try/__except, as described in the page
|
||||
"try-except statement" on microsoft.com
|
||||
<http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
|
||||
With __try/__except, we can use the multithread-safe exception handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
__try
|
||||
# define CATCH_MSVC_INVAL \
|
||||
__except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \
|
||||
? EXCEPTION_EXECUTE_HANDLER \
|
||||
: EXCEPTION_CONTINUE_SEARCH)
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Any compiler.
|
||||
We can only use setjmp/longjmp. */
|
||||
|
||||
# include <setjmp.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
struct gl_msvc_inval_per_thread
|
||||
{
|
||||
/* The restart that will resume execution at the code between
|
||||
CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between
|
||||
TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */
|
||||
jmp_buf restart;
|
||||
|
||||
/* Tells whether the contents of restart is valid. */
|
||||
int restart_valid;
|
||||
};
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that passes
|
||||
control to the gl_msvc_inval_restart if it is valid, or raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
/* Return a pointer to the per-thread data for the current thread. */
|
||||
extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
struct gl_msvc_inval_per_thread *msvc_inval_current; \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
msvc_inval_current = gl_msvc_inval_current (); \
|
||||
/* First, initialize gl_msvc_inval_restart. */ \
|
||||
if (setjmp (msvc_inval_current->restart) == 0) \
|
||||
{ \
|
||||
/* Then, mark it as valid. */ \
|
||||
msvc_inval_current->restart_valid = 1;
|
||||
# define CATCH_MSVC_INVAL \
|
||||
/* Execution completed. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Execution triggered an invalid parameter notification. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0;
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* A platform that does not need to the invalid parameter handler,
|
||||
or when SANE_LIBRARY_HANDLING is desired. */
|
||||
|
||||
/* The braces here avoid GCC warnings like
|
||||
"warning: suggest explicit braces to avoid ambiguous 'else'". */
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_INVAL_H */
|
||||
49
gl/msvc-nothrow.c
Normal file
49
gl/msvc-nothrow.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2013 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/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-nothrow.h"
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#undef _get_osfhandle
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
intptr_t
|
||||
_gl_nothrow_get_osfhandle (int fd)
|
||||
{
|
||||
intptr_t result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _get_osfhandle (fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = (intptr_t) INVALID_HANDLE_VALUE;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
43
gl/msvc-nothrow.h
Normal file
43
gl/msvc-nothrow.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2013 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/>. */
|
||||
|
||||
#ifndef _MSVC_NOTHROW_H
|
||||
#define _MSVC_NOTHROW_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines wrappers that turn such an invalid parameter notification
|
||||
into an error code. */
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
/* Get original declaration of _get_osfhandle. */
|
||||
# include <io.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
|
||||
/* Override _get_osfhandle. */
|
||||
extern intptr_t _gl_nothrow_get_osfhandle (int fd);
|
||||
# define _get_osfhandle _gl_nothrow_get_osfhandle
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_NOTHROW_H */
|
||||
132
gl/stdbool.in.h
Normal file
132
gl/stdbool.in.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
|
||||
|
||||
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 _GL_STDBOOL_H
|
||||
#define _GL_STDBOOL_H
|
||||
|
||||
/* ISO C 99 <stdbool.h> for platforms that lack it. */
|
||||
|
||||
/* Usage suggestions:
|
||||
|
||||
Programs that use <stdbool.h> should be aware of some limitations
|
||||
and standards compliance issues.
|
||||
|
||||
Standards compliance:
|
||||
|
||||
- <stdbool.h> must be #included before 'bool', 'false', 'true'
|
||||
can be used.
|
||||
|
||||
- You cannot assume that sizeof (bool) == 1.
|
||||
|
||||
- Programs should not undefine the macros bool, true, and false,
|
||||
as C99 lists that as an "obsolescent feature".
|
||||
|
||||
Limitations of this substitute, when used in a C89 environment:
|
||||
|
||||
- <stdbool.h> must be #included before the '_Bool' type can be used.
|
||||
|
||||
- You cannot assume that _Bool is a typedef; it might be a macro.
|
||||
|
||||
- Bit-fields of type 'bool' are not supported. Portable code
|
||||
should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
|
||||
|
||||
- In C99, casts and automatic conversions to '_Bool' or 'bool' are
|
||||
performed in such a way that every nonzero value gets converted
|
||||
to 'true', and zero gets converted to 'false'. This doesn't work
|
||||
with this substitute. With this substitute, only the values 0 and 1
|
||||
give the expected result when converted to _Bool' or 'bool'.
|
||||
|
||||
- C99 allows the use of (_Bool)0.0 in constant expressions, but
|
||||
this substitute cannot always provide this property.
|
||||
|
||||
Also, it is suggested that programs use 'bool' rather than '_Bool';
|
||||
this isn't required, but 'bool' is more common. */
|
||||
|
||||
|
||||
/* 7.16. Boolean type and values */
|
||||
|
||||
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
|
||||
definitions below, but temporarily we have to #undef them. */
|
||||
#if defined __BEOS__ && !defined __HAIKU__
|
||||
# include <OS.h> /* defines bool but not _Bool */
|
||||
# undef false
|
||||
# undef true
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define _Bool bool
|
||||
# define bool bool
|
||||
#else
|
||||
# if defined __BEOS__ && !defined __HAIKU__
|
||||
/* A compiler known to have 'bool'. */
|
||||
/* If the compiler already has both 'bool' and '_Bool', we can assume they
|
||||
are the same types. */
|
||||
# if !@HAVE__BOOL@
|
||||
typedef bool _Bool;
|
||||
# endif
|
||||
# else
|
||||
# if !defined __GNUC__
|
||||
/* If @HAVE__BOOL@:
|
||||
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
|
||||
the built-in _Bool type is used. See
|
||||
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
|
||||
Similar bugs are likely with other compilers as well; this file
|
||||
wouldn't be used if <stdbool.h> was working.
|
||||
So we override the _Bool type.
|
||||
If !@HAVE__BOOL@:
|
||||
Need to define _Bool ourselves. As 'signed char' or as an enum type?
|
||||
Use of a typedef, with SunPRO C, leads to a stupid
|
||||
"warning: _Bool is a keyword in ISO C99".
|
||||
Use of an enum type, with IRIX cc, leads to a stupid
|
||||
"warning(1185): enumerated type mixed with another type".
|
||||
Even the existence of an enum type, without a typedef,
|
||||
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
|
||||
The only benefit of the enum, debuggability, is not important
|
||||
with these compilers. So use 'signed char' and no enum. */
|
||||
# define _Bool signed char
|
||||
# else
|
||||
/* With this compiler, trust the _Bool type if the compiler has it. */
|
||||
# if !@HAVE__BOOL@
|
||||
/* For the sake of symbolic names in gdb, define true and false as
|
||||
enum constants, not only as macros.
|
||||
It is tempting to write
|
||||
typedef enum { false = 0, true = 1 } _Bool;
|
||||
so that gdb prints values of type 'bool' symbolically. But then
|
||||
values of type '_Bool' might promote to 'int' or 'unsigned int'
|
||||
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
|
||||
(see ISO C 99 6.3.1.1.(2)). So add a negative value to the
|
||||
enum; this ensures that '_Bool' promotes to 'int'. */
|
||||
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# define bool _Bool
|
||||
#endif
|
||||
|
||||
/* The other macros must be usable in preprocessor directives. */
|
||||
#ifdef __cplusplus
|
||||
# define false false
|
||||
# define true true
|
||||
#else
|
||||
# define false 0
|
||||
# define true 1
|
||||
#endif
|
||||
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#endif /* _GL_STDBOOL_H */
|
||||
51
gl/sys_types.in.h
Normal file
51
gl/sys_types.in.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Provide a more complete sys/types.h.
|
||||
|
||||
Copyright (C) 2011-2013 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/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
#define _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
|
||||
/* Override off_t if Large File Support is requested on native Windows. */
|
||||
#if @WINDOWS_64_BIT_OFF_T@
|
||||
/* Same as int64_t in <stdint.h>. */
|
||||
# if defined _MSC_VER
|
||||
# define off_t __int64
|
||||
# else
|
||||
# define off_t long long int
|
||||
# endif
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_64_BIT_OFF_T 1
|
||||
#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__) \
|
||||
&& ! defined __GLIBC__
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
|
||||
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
|
||||
3
gl/unistd.c
Normal file
3
gl/unistd.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <config.h>
|
||||
#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
|
||||
#include "unistd.h"
|
||||
1527
gl/unistd.in.h
Normal file
1527
gl/unistd.in.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user