From ad44ceabd06f3c9c18fece98f55e4e54891a030c Mon Sep 17 00:00:00 2001 From: Thibault Godouet Date: Fri, 12 Jun 2015 21:18:24 +0100 Subject: [PATCH] added min/max convenience functions --- subs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ subs.h | 6 ++++++ 2 files changed, 54 insertions(+) diff --git a/subs.c b/subs.c index 1288f84..bdae71f 100644 --- a/subs.c +++ b/subs.c @@ -427,3 +427,51 @@ my_setenv_overwrite(const char *name, const char *value) #endif } + +time_t +tmax(time_t x, time_t y) +/* return the larger value (maximum) of x and y */ +{ + if (x > y) { + return x; + } + else { + return y; + } +} + +time_t +tmin(time_t x, time_t y) +/* return the smaller value (minimum) of x and y */ +{ + if (x < y) { + return x; + } + else { + return y; + } +} + +int +imax(int x, int y) +/* return the larger value (maximum) of x and y */ +{ + if (x > y) { + return x; + } + else { + return y; + } +} + +int +imin(int x, int y) +/* return the smaller value (minimum) of x and y */ +{ + if (x < y) { + return x; + } + else { + return y; + } +} diff --git a/subs.h b/subs.h index cef4a17..23a1590 100644 --- a/subs.h +++ b/subs.h @@ -44,4 +44,10 @@ extern int get_word(char **str); extern void my_unsetenv(const char *name); extern void my_setenv_overwrite(const char *name, const char *value); +extern time_t tmax(time_t x, time_t y); +extern time_t tmin(time_t x, time_t y); +extern int imax(int x, int y); +extern int imin(int x, int y); + +extern time_t my_time(void); #endif /* __SUBS_H__ */ -- 2.47.3