diff --git a/stix/lib/exec.c b/stix/lib/exec.c index b4bbce4..9e35a58 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -28,7 +28,13 @@ /* TODO: remove this header after having changed clock_gettime() to a * platform independent function */ -#include +#if defined(HAVE_TIME_H) +# include +#endif + +#if defined(HAVE_SYS_TIME_H) +# include +#endif #define PROC_STATE_RUNNING 3 #define PROC_STATE_WAITING 2 @@ -159,9 +165,19 @@ static STIX_INLINE void vm_gettime (stix_ntime_t* now) { +#if defined(HAVE_CLOCK_GETTIME) struct timespec ts; + #if defined(CLOCK_MONOTONIC) clock_gettime (CLOCK_MONOTONIC, &ts); + #else + clock_gettime (CLOCK_REALTIME, &ts); + #endif STIX_INITNTIME(now, ts.tv_sec, ts.tv_nsec); +#else + struct timeval tv; + gettimeofday (&tv, STIX_NULL); + STIX_INITNTIME(now, tv.tv_sec, STIX_USEC_TO_NSEC(tv.tv_usec)); +#endif } static STIX_INLINE void vm_sleep (const stix_ntime_t* dur) diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 1b0a8e4..afbd836 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -97,8 +97,8 @@ # define STIX_MEMCMP(dst,src,size) memcmp(dst,src,size) # endif -#elif defined(__GNUC__) -/* TODO: may need to check a gnuc version or use autoconf to check the availibility ? */ +#elif defined(__GNUC__) && (__GNUC__ >= 3 || (defined(__GNUC_MINOR) && __GNUC__ == 2 && __GNUC_MINOR__ >= 91)) + /* gcc 2.91 or higher */ # define STIX_MEMSET(dst,src,size) __builtin_memset(dst,src,size) # define STIX_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size) # define STIX_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size)