[PATCH v5 01/12] common/rc: Add _min() and _max() helpers

Ojaswin Mujoo posted 11 patches 2 weeks, 1 day ago
[PATCH v5 01/12] common/rc: Add _min() and _max() helpers
Posted by Ojaswin Mujoo 2 weeks, 1 day ago
Many programs open code these functionalities so add it as a generic helper
in common/rc

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 common/rc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/common/rc b/common/rc
index ff5df203..35a1c835 100644
--- a/common/rc
+++ b/common/rc
@@ -5975,6 +5975,28 @@ _require_inplace_writes()
 	fi
 }
 
+_min() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg < $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
+_max() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg > $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
 ################################################################################
 # make sure this script returns success
 /bin/true
-- 
2.49.0