summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_read_uint.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-08-25 23:14:00 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-08-25 23:14:00 +0000
commit4fb4eaecb937e3eddd8804c85ce20c80cc753480 (patch)
treea0f530151558a3c721f0aaf9b0e4e28f183de8c0 /src/libs6rc/s6rc_read_uint.c
parentfc91cc6cd1384a315a1f33bc83e6d6e9926fc791 (diff)
downloads6-rc-4fb4eaecb937e3eddd8804c85ce20c80cc753480.tar.xz
Some refactor + add servicedir copy functions in libs6rc
Diffstat (limited to 'src/libs6rc/s6rc_read_uint.c')
-rw-r--r--src/libs6rc/s6rc_read_uint.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_read_uint.c b/src/libs6rc/s6rc_read_uint.c
new file mode 100644
index 0000000..6953190
--- /dev/null
+++ b/src/libs6rc/s6rc_read_uint.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/uint.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/djbunix.h>
+
+int s6rc_read_uint (char const *file, unsigned int *u)
+{
+ char buf[UINT_FMT + 1] ;
+ register int 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 ;
+}