]> granicus.if.org Git - fcron/commitdiff
added min/max convenience functions
authorThibault Godouet <fcron@free.fr>
Fri, 12 Jun 2015 20:18:24 +0000 (21:18 +0100)
committerThibault Godouet <fcron@free.fr>
Fri, 12 Jun 2015 21:38:24 +0000 (22:38 +0100)
subs.c
subs.h

diff --git a/subs.c b/subs.c
index 1288f84a01e226aaf537d9fbf2d5cae663a3710d..bdae71fb03b0dbc4408136de58acd6d4f8203fc1 100644 (file)
--- 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 cef4a17ab402cd2cdf26fb6ca96d6078c596bfb5..23a1590730a136df14933e1bb480deaa715d21e9 100644 (file)
--- 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__ */