diff --git a/qse/configure b/qse/configure index 2c233d41..8d01f4a8 100755 --- a/qse/configure +++ b/qse/configure @@ -17628,7 +17628,7 @@ _ACEOF fi done -for ac_func in sysconf prctl fdopendir setrlimit getrlimit +for ac_func in sysconf prctl fdopendir setrlimit getrlimit getpgid getpgrp do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -19051,6 +19051,24 @@ _ACEOF fi +ac_fn_c_check_type "$LINENO" "struct timespec" "ac_cv_type_struct_timespec" "#include + #ifdef HAVE_TIME_H + #include + #endif + #ifdef HAVE_SYS_TIME_H + #include + #endif +" +if test "x$ac_cv_type_struct_timespec" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_TIMESPEC 1 +_ACEOF + + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for va_copy" >&5 $as_echo_n "checking for va_copy... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext diff --git a/qse/configure.ac b/qse/configure.ac index 603ae36b..58f4298d 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -148,7 +148,7 @@ AC_CHECK_FUNCS([lseek64 stat64 fstat64 lstat64 ftruncate64 readdir64 dirfd]) AC_CHECK_FUNCS([lstat fchmod fsync ftruncate]) AC_CHECK_FUNCS([timegm timelocal localtime_r gettimeofday settimeofday]) AC_CHECK_FUNCS([utime utimes futimes lutimes futimens]) -AC_CHECK_FUNCS([sysconf prctl fdopendir setrlimit getrlimit]) +AC_CHECK_FUNCS([sysconf prctl fdopendir setrlimit getrlimit getpgid getpgrp]) AC_CHECK_FUNCS([backtrace backtrace_symbols]) AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select]) AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) @@ -331,6 +331,15 @@ AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [], #include #include ]) +AC_CHECK_TYPES([struct timespec], [], [], + [#include + #ifdef HAVE_TIME_H + #include + #endif + #ifdef HAVE_SYS_TIME_H + #include + #endif]) + AC_MSG_CHECKING([for va_copy]) AC_TRY_LINK( [#include ], diff --git a/qse/include/qse/config.h.in b/qse/include/qse/config.h.in index b04ae2e4..da99d682 100644 --- a/qse/include/qse/config.h.in +++ b/qse/include/qse/config.h.in @@ -263,6 +263,12 @@ /* Define to 1 if you have the `getifaddrs' function. */ #undef HAVE_GETIFADDRS +/* Define to 1 if you have the `getpgid' function. */ +#undef HAVE_GETPGID + +/* Define to 1 if you have the `getpgrp' function. */ +#undef HAVE_GETPGRP + /* Define to 1 if you have the `getrlimit' function. */ #undef HAVE_GETRLIMIT @@ -602,6 +608,9 @@ /* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC +/* Define to 1 if the system has the type `struct timespec'. */ +#undef HAVE_STRUCT_TIMESPEC + /* Define to 1 if you have the `swapcontext' function. */ #undef HAVE_SWAPCONTEXT diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index 92a4f66c..974d47b0 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -41,7 +41,9 @@ # define QSE_INLINE inline # define QSE_HAVE_INLINE #elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) -# define QSE_INLINE /*extern*/ inline + /* gcc disables inline when -std=c89 or -ansi is used. + * so use __inline__ supported by gcc regardless of the options */ +# define QSE_INLINE /*extern*/ __inline__ # define QSE_HAVE_INLINE #else # define QSE_INLINE @@ -49,7 +51,7 @@ #endif #if defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) -# define QSE_INLINE_ALWAYS inline __attribute__((__always_inline__)) +# define QSE_INLINE_ALWAYS __inline__ __attribute__((__always_inline__)) # define QSE_HAVE_INLINE_ALWAYS #elif defined(_MSC_VER) || (defined(__CC_ARM) || defined(__ARMCC__)) # define QSE_INLINE_ALWAYS __forceinline @@ -60,7 +62,7 @@ #endif #if defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) -# define QSE_INLINE_NEVER inline __attribute__((__noinline__)) +# define QSE_INLINE_NEVER __inline__ __attribute__((__noinline__)) # define QSE_HAVE_INLINE_NEVER #elif (defined(__CC_ARM) || defined(__ARMCC__)) # define QSE_INLINE_NEVER __declspec(noinline) @@ -160,7 +162,9 @@ * that it does not point to anything. */ #if defined(__cplusplus) -# if QSE_SIZEOF_VOID_P == QSE_SIZEOF_INT +# if (__cplusplus >= 201103L) /* C++11 */ +# define QSE_NULL nullptr +# elif QSE_SIZEOF_VOID_P == QSE_SIZEOF_INT # define QSE_NULL (0) # elif QSE_SIZEOF_VOID_P == QSE_SIZEOF_LONG # define QSE_NULL (0l) diff --git a/qse/lib/awk/mod-sys.c b/qse/lib/awk/mod-sys.c index 75087b38..a0d4cc22 100644 --- a/qse/lib/awk/mod-sys.c +++ b/qse/lib/awk/mod-sys.c @@ -146,7 +146,7 @@ static int fnc_kill (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) return 0; } -static int fnc_getpgrp (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +static int fnc_getpgid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { qse_awk_int_t pid; qse_awk_val_t* retv; @@ -164,7 +164,14 @@ static int fnc_getpgrp (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) pid = -1; #else + /* TODO: support specifing calling process id other than 0 */ + #if defined(HAVE_GETPGID) + pid = getpgid (0); + #elif defined(HAVE_GETPGRP) pid = getpgrp (); + #else + pid = -1; + #endif #endif retv = qse_awk_rtx_makeintval (rtx, pid); @@ -679,7 +686,7 @@ static fnctab_t fnctab[] = { QSE_T("geteuid"), { { 0, 0, QSE_NULL }, fnc_geteuid, 0 } }, { QSE_T("getgid"), { { 0, 0, QSE_NULL }, fnc_getgid, 0 } }, { QSE_T("getnwifcfg"), { { 3, 3, QSE_T("vvr") }, fnc_getnwifcfg, 0 } }, - { QSE_T("getpgrp"), { { 0, 0, QSE_NULL }, fnc_getpgrp, 0 } }, + { QSE_T("getpgid"), { { 0, 0, QSE_NULL }, fnc_getpgid, 0 } }, { QSE_T("getpid"), { { 0, 0, QSE_NULL }, fnc_getpid, 0 } }, { QSE_T("getppid"), { { 0, 0, QSE_NULL }, fnc_getppid, 0 } }, { QSE_T("gettid"), { { 0, 0, QSE_NULL }, fnc_gettid, 0 } }, diff --git a/qse/lib/cmn/fmt-intmax.c b/qse/lib/cmn/fmt-intmax.c index c8187555..70591094 100644 --- a/qse/lib/cmn/fmt-intmax.c +++ b/qse/lib/cmn/fmt-intmax.c @@ -194,7 +194,7 @@ int qse_fmtfltmaxtombs (qse_mchar_t* buf, qse_size_t bufsize, qse_fltmax_t f, qs if (len + 1 < bufsize) { - buf[len++] = point; // add decimal point to string + buf[len++] = point; /* add decimal point to string */ buf[len] = QSE_MT('\0'); } diff --git a/qse/lib/cmn/fs-copy.c b/qse/lib/cmn/fs-copy.c index 9aaa4811..d999499e 100644 --- a/qse/lib/cmn/fs-copy.c +++ b/qse/lib/cmn/fs-copy.c @@ -237,7 +237,7 @@ static int copy_file_in_fs (qse_fs_t* fs, cpfile_t* cpfile) if (cpfile->flags & QSE_FS_CPFILE_PRESERVE) { - #if defined(HAVE_FUTIMENS) + #if defined(HAVE_FUTIMENS) && defined(HAVE_STRUCT_TIMESPEC) struct timespec ts[2]; #elif defined(HAVE_FUTIMES) struct timeval tv[2]; @@ -254,7 +254,7 @@ static int copy_file_in_fs (qse_fs_t* fs, cpfile_t* cpfile) goto oops; } - #if defined(HAVE_FUTIMENS) + #if defined(HAVE_FUTIMENS) && defined(HAVE_STRUCT_TIMESPEC) QSE_MEMSET (&ts, 0, QSE_SIZEOF(ts)); ts[0].tv_sec = cpfile->src_attr.atime.sec; diff --git a/qse/lib/cmn/fs.c b/qse/lib/cmn/fs.c index 2f1c60de..e90f028f 100644 --- a/qse/lib/cmn/fs.c +++ b/qse/lib/cmn/fs.c @@ -645,7 +645,7 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags) if (flags & QSE_FS_ENT_TYPE) { - #if defined(HAVE_STRUCT_DIRENT_D_TYPE) + #if defined(HAVE_STRUCT_DIRENT_D_TYPE) && defined(DT_DIR) && defined(DT_REG) /* and more */ switch (ent->d_type) { case DT_DIR: @@ -678,18 +678,26 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags) default: fs->ent.type = QSE_FS_ENT_UNKNOWN; break; - } + } #else + #if defined(__S_IFMT) && !defined(S_IFMT) + # define S_IFMT __S_IFMT + #endif + #if defined(__S_IFDIR) && !defined(S_IFDIR) + # define S_IFDIR __S_IFDIR + #endif #define IS_TYPE(st,type) ((st.st_mode & S_IFMT) == S_IFDIR) fs->ent.type = IS_TYPE(st,S_IFDIR)? QSE_FS_ENT_SUBDIR: - IS_TYPE(st,S_IFREG)? QSE_FS_ENT_REGULAR: - IS_TYPE(st,S_IFLNK)? QSE_FS_ENT_SYMLINK: - IS_TYPE(st,S_IFCHR)? QSE_FS_ENT_CHRDEV: - IS_TYPE(st,S_IFBLK)? QSE_FS_ENT_BLKDEV: - IS_TYPE(st,S_IFIFO)? QSE_FS_ENT_PIPE: - IS_TYPE(st,S_IFSOCK)? QSE_FS_ENT_PIPE: - QSE_FS_ENT_UNKNOWN; + IS_TYPE(st,S_IFREG)? QSE_FS_ENT_REGULAR: + IS_TYPE(st,S_IFLNK)? QSE_FS_ENT_SYMLINK: + IS_TYPE(st,S_IFCHR)? QSE_FS_ENT_CHRDEV: + IS_TYPE(st,S_IFBLK)? QSE_FS_ENT_BLKDEV: + IS_TYPE(st,S_IFIFO)? QSE_FS_ENT_PIPE: + #if defined(S_IFSOCK) + IS_TYPE(st,S_IFSOCK)? QSE_FS_ENT_PIPE: + #endif + QSE_FS_ENT_UNKNOWN; #undef IS_TYPE #endif fs->ent.flags |= QSE_FS_ENT_TYPE;