summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-11-06 10:03:43 -0500
committerTavian Barnes <tavianator@tavianator.com>2023-11-06 10:07:50 -0500
commit816574513e0e163aff9f183721697f157eb158fa (patch)
tree3cde4d557838a9af08803e5314350f81276129af /src/bfstd.c
parent5fb1ed2d9803bfa5eefdc49ae232f9ea4afff018 (diff)
downloadbfs-816574513e0e163aff9f183721697f157eb158fa.tar.xz
bfstd: Expose rlim_cmp()
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 06226a2..985a268 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -368,6 +369,38 @@ void xstrmode(mode_t mode, char str[11]) {
}
}
+/** Check if an rlimit value is infinite. */
+static bool rlim_isinf(rlim_t r) {
+ // Consider RLIM_{INFINITY,SAVED_{CUR,MAX}} all equally infinite
+ if (r == RLIM_INFINITY) {
+ return true;
+ }
+
+#ifdef RLIM_SAVED_CUR
+ if (r == RLIM_SAVED_CUR) {
+ return true;
+ }
+#endif
+
+#ifdef RLIM_SAVED_MAX
+ if (r == RLIM_SAVED_MAX) {
+ return true;
+ }
+#endif
+
+ return false;
+}
+
+int rlim_cmp(rlim_t a, rlim_t b) {
+ bool a_inf = rlim_isinf(a);
+ bool b_inf = rlim_isinf(b);
+ if (a_inf || b_inf) {
+ return a_inf - b_inf;
+ }
+
+ return (a > b) - (a < b);
+}
+
dev_t xmakedev(int ma, int mi) {
#ifdef makedev
return makedev(ma, mi);