Skip to content

Commit

Permalink
Improved autoconf feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumPaget committed Jun 23, 2017
1 parent b40b2a7 commit c03f0c9
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 6 deletions.
8 changes: 6 additions & 2 deletions libUseful-2.8/FileSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions libUseful-2.8/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion libUseful-2.8/Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ ptr=GetNameValuePair(ptr,"\\S","=",&Name,&Value);

pid=getpid();

#ifdef linux
#ifdef HAVE_UNSHARE
#ifdef CLONE_NEWPID
unshare(CLONE_NEWPID);
#endif
Expand Down
208 changes: 208 additions & 0 deletions libUseful-2.8/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
28 changes: 28 additions & 0 deletions libUseful-2.8/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
5 changes: 5 additions & 0 deletions libUseful-2.8/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c03f0c9

Please sign in to comment.