aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsimple.c233
-rw-r--r--libsimple.h6
2 files changed, 235 insertions, 4 deletions
diff --git a/libsimple.c b/libsimple.c
index df01ea1..b27f3bb 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -96,7 +96,8 @@ test_timeval(double d, time_t sec, long int usec, double rd, const char *s, cons
int
main(void)
{
- struct timespec ts;
+ struct timespec ts, ts1, ts2;
+ struct timeval tv1, tv2;
const char *cs;
char buf[1024], *s;
int intarray[10];
@@ -780,6 +781,236 @@ main(void)
assert(ts.tv_sec == -10);
assert(ts.tv_nsec == 1000L);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = TIME_MAX, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+
return 0;
}
diff --git a/libsimple.h b/libsimple.h
index 1e27b65..9d63c2c 100644
--- a/libsimple.h
+++ b/libsimple.h
@@ -477,7 +477,7 @@ extern int libsimple_default_failure_exit;
#endif
-#define FREE(PTR) (free(PTR), (PTR) = NULL, 0) /* TODO test */
+#define FREE(PTR) ((void)(free(PTR), (PTR) = NULL)) /* TODO test */
#define CLOSE(FD) libsimple_close(&(FD)) /* TODO test */
@@ -1398,7 +1398,7 @@ int libsimple_multimespec(struct timespec *, const struct timespec *, int);
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__)))
static inline int
-libsimple_cmptimespec(const struct timespec *__a, const struct timespec *__b) /* TODO test */
+libsimple_cmptimespec(const struct timespec *__a, const struct timespec *__b)
{
if (__a->tv_sec != __b->tv_sec)
return __a->tv_sec < __b->tv_sec ? -1 : +1;
@@ -1432,7 +1432,7 @@ int libsimple_multimeval(struct timeval *, const struct timeval *, int);
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __warn_unused_result__)))
static inline int
-libsimple_cmptimeval(const struct timeval *__a, const struct timeval *__b) /* TODO test */
+libsimple_cmptimeval(const struct timeval *__a, const struct timeval *__b)
{
if (__a->tv_sec != __b->tv_sec)
return __a->tv_sec < __b->tv_sec ? -1 : +1;