diff options
Diffstat (limited to 'src/libs6rc/s6rc_read_uint.c')
-rw-r--r-- | src/libs6rc/s6rc_read_uint.c | 16 |
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 ; +} |