summaryrefslogtreecommitdiff
path: root/src/serverlib/s6rc_read_uint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/serverlib/s6rc_read_uint.c')
-rw-r--r--src/serverlib/s6rc_read_uint.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/serverlib/s6rc_read_uint.c b/src/serverlib/s6rc_read_uint.c
new file mode 100644
index 0000000..1f148ac
--- /dev/null
+++ b/src/serverlib/s6rc_read_uint.c
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <skalibs/types.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/djbunix.h>
+#include <s6-rc/s6rc-utils.h>
+
+int s6rc_read_uint (char const *file, unsigned int *u)
+{
+ char buf[UINT_FMT + 1] ;
+ ssize_t r = openreadnclose(file, buf, UINT_FMT) ;
+ if (r < 0) return (errno == ENOENT) ? 0 : -1 ;
+ buf[byte_chr(buf, r, '\n')] = 0 ;
+ if (!uint0_scan(buf, u)) return (errno = EINVAL, -1) ;
+ return 1 ;
+}