From c03f0c9c1d49218d1b5dcd5234ed4e5af43a245a Mon Sep 17 00:00:00 2001 From: Colum Paget Date: Fri, 23 Jun 2017 13:58:34 +0100 Subject: [PATCH] Improved autoconf feature detection --- libUseful-2.8/FileSystem.c | 8 +- libUseful-2.8/Makefile | 6 +- libUseful-2.8/Process.c | 2 +- libUseful-2.8/configure | 208 +++++++++++++++++++++++++++++++++++++ libUseful-2.8/configure.ac | 28 +++++ libUseful-2.8/file.c | 5 + 6 files changed, 251 insertions(+), 6 deletions(-) diff --git a/libUseful-2.8/FileSystem.c b/libUseful-2.8/FileSystem.c index f7c9791..f865ba0 100755 --- a/libUseful-2.8/FileSystem.c +++ b/libUseful-2.8/FileSystem.c @@ -379,10 +379,14 @@ if (ExtraFlags & UMOUNT_RECURSE) -#ifdef linux +#ifdef HAVE_UMOUNT2 result=umount2(MountPoint, Flags); -#else +#elif HAVE_UMOUNT +result=umount(MountPoint); +#elif HAVE_UNMOUNT result=unmount(MountPoint,0); +#else +result=-1 #endif if (ExtraFlags & UMOUNT_RMDIR) rmdir(MountPoint); diff --git a/libUseful-2.8/Makefile b/libUseful-2.8/Makefile index ed395db..0c2eb3d 100644 --- a/libUseful-2.8/Makefile +++ b/libUseful-2.8/Makefile @@ -1,8 +1,8 @@ -CC = cc +CC = gcc VERSION = 0.0.1 CFLAGS = -g -O2 -LIBS = -FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_PTSNAME_R=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_OSS=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK +LIBS = -lc -lc -lc -lc +FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBC=1 -DHAVE_PTSNAME_R=1 -DHAVE_LIBC=1 -DHAVE_UNSHARE=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT2=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT=1 -DHAVE_MKOSTMP=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DUSE_SENDFILE=1 -DHAVE_OSS=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK prefix=/usr/local OBJ=string.o list.o socket.o unix_socket.o file.o tar.o Terminal.o FileSystem.o GeneralFunctions.o DataProcessing.o EncryptedFiles.o g711.o sound.o pty.o Log.o http.o inet.o expect.o base64.o crc32.o md5c.o sha1.o sha2.o whirlpool.o jh_ref.o Hash.o ssh.o Compression.o oauth.o libsettings.o Vars.o Time.o Markup.o SpawnPrograms.o Tokenizer.o PatternMatch.o URL.o DataParser.o ConnectionChain.o openssl.o Process.o Encodings.o RawData.o securemem.o diff --git a/libUseful-2.8/Process.c b/libUseful-2.8/Process.c index 4d3f36d..8efbe0d 100755 --- a/libUseful-2.8/Process.c +++ b/libUseful-2.8/Process.c @@ -304,7 +304,7 @@ ptr=GetNameValuePair(ptr,"\\S","=",&Name,&Value); pid=getpid(); -#ifdef linux +#ifdef HAVE_UNSHARE #ifdef CLONE_NEWPID unshare(CLONE_NEWPID); #endif diff --git a/libUseful-2.8/configure b/libUseful-2.8/configure index 2e5f2d2..7616b34 100755 --- a/libUseful-2.8/configure +++ b/libUseful-2.8/configure @@ -3566,6 +3566,214 @@ $as_echo "#define HAVE_PTSNAME_R 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for unshare in -lc" >&5 +$as_echo_n "checking for unshare in -lc... " >&6; } +if ${ac_cv_lib_c_unshare+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char unshare (); +int +main () +{ +return unshare (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_unshare=yes +else + ac_cv_lib_c_unshare=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_unshare" >&5 +$as_echo "$ac_cv_lib_c_unshare" >&6; } +if test "x$ac_cv_lib_c_unshare" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBC 1 +_ACEOF + + LIBS="-lc $LIBS" + +fi + +cf_have_unshare=$ac_cv_lib_c_unshare +if test "$cf_have_unshare" +then +$as_echo "#define HAVE_UNSHARE 1" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for umount2 in -lc" >&5 +$as_echo_n "checking for umount2 in -lc... " >&6; } +if ${ac_cv_lib_c_umount2+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char umount2 (); +int +main () +{ +return umount2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_umount2=yes +else + ac_cv_lib_c_umount2=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_umount2" >&5 +$as_echo "$ac_cv_lib_c_umount2" >&6; } +if test "x$ac_cv_lib_c_umount2" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBC 1 +_ACEOF + + LIBS="-lc $LIBS" + +fi + +cf_have_umount2=$ac_cv_lib_c_umount2 +if test "$cf_have_umount2" +then +$as_echo "#define HAVE_UMOUNT2 1" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for umount in -lc" >&5 +$as_echo_n "checking for umount in -lc... " >&6; } +if ${ac_cv_lib_c_umount+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char umount (); +int +main () +{ +return umount (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_umount=yes +else + ac_cv_lib_c_umount=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_umount" >&5 +$as_echo "$ac_cv_lib_c_umount" >&6; } +if test "x$ac_cv_lib_c_umount" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBC 1 +_ACEOF + + LIBS="-lc $LIBS" + +fi + +cf_have_umount=$ac_cv_lib_c_umount +if test "$cf_have_umount" +then +$as_echo "#define HAVE_UMOUNT 1" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mkostemp in -lc" >&5 +$as_echo_n "checking for mkostemp in -lc... " >&6; } +if ${ac_cv_lib_c_mkostemp+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char mkostemp (); +int +main () +{ +return mkostemp (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_mkostemp=yes +else + ac_cv_lib_c_mkostemp=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_mkostemp" >&5 +$as_echo "$ac_cv_lib_c_mkostemp" >&6; } +if test "x$ac_cv_lib_c_mkostemp" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBC 1 +_ACEOF + + LIBS="-lc $LIBS" + +fi + +cf_have_mkostemp=$ac_cv_lib_c_mkostemp +if test "$cf_have_mkostemp" +then +$as_echo "#define HAVE_MKOSTEMP 1" >>confdefs.h + +fi + # Check whether --enable-sendfile was given. if test "${enable_sendfile+set}" = set; then : diff --git a/libUseful-2.8/configure.ac b/libUseful-2.8/configure.ac index cdd8229..c9ed96b 100755 --- a/libUseful-2.8/configure.ac +++ b/libUseful-2.8/configure.ac @@ -26,6 +26,34 @@ then AC_DEFINE([HAVE_PTSNAME_R]) fi +AC_CHECK_LIB(c,unshare,,) +cf_have_unshare=$ac_cv_lib_c_unshare +if test "$cf_have_unshare" +then +AC_DEFINE([HAVE_UNSHARE]) +fi + +AC_CHECK_LIB(c,umount2,,) +cf_have_umount2=$ac_cv_lib_c_umount2 +if test "$cf_have_umount2" +then +AC_DEFINE([HAVE_UMOUNT2]) +fi + +AC_CHECK_LIB(c,umount,,) +cf_have_umount=$ac_cv_lib_c_umount +if test "$cf_have_umount" +then +AC_DEFINE([HAVE_UMOUNT]) +fi + +AC_CHECK_LIB(c,mkostemp,,) +cf_have_mkostemp=$ac_cv_lib_c_mkostemp +if test "$cf_have_mkostemp" +then +AC_DEFINE([HAVE_MKOSTEMP]) +fi + AC_ARG_ENABLE(sendfile, [ --enable-sendfile enable sendfile support], cf_use_sendfile=$enableval ) diff --git a/libUseful-2.8/file.c b/libUseful-2.8/file.c index d0214af..83a0de9 100755 --- a/libUseful-2.8/file.c +++ b/libUseful-2.8/file.c @@ -630,7 +630,12 @@ if (Flags & SF_CREATE) Mode|=O_CREAT; { //Must make a copy because mkostemp internally alters path NewPath=CopyStr(NewPath, Path); + #ifdef HAVE_MKOSTEMP fd=mkostemp(NewPath, Mode); + #else + fd=mkstemp(NewPath); + chmod(NewPath,Mode); + #endif p_Path=NewPath; } else fd=open(Path, Mode, 0600);