aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6rc/s6rc_read_major.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-10-03 02:19:00 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-10-03 02:19:00 +0000
commit3245c92eaa3528a4176e05ab9beaa9718afc8868 (patch)
tree3b3fdae569baac1d9fc866e72993c0ce27bd680c /src/libs6rc/s6rc_read_major.c
parent7c93a058c8d7e21aea2aad8f3114c8422bf6faf7 (diff)
downloads6-rc-3245c92eaa3528a4176e05ab9beaa9718afc8868.tar.gz
Prepare for 0.7.1.0; add major version to every compiled db
Diffstat (limited to 'src/libs6rc/s6rc_read_major.c')
-rw-r--r--src/libs6rc/s6rc_read_major.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_read_major.c b/src/libs6rc/s6rc_read_major.c
new file mode 100644
index 0000000..978f29c
--- /dev/null
+++ b/src/libs6rc/s6rc_read_major.c
@@ -0,0 +1,30 @@
+/* ISC license. */
+
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+
+#include <skalibs/uint32.h>
+#include <skalibs/djbunix.h>
+
+#include <s6-rc/s6rc-utils.h>
+
+#include <skalibs/posixishard.h>
+
+uint32_t s6rc_read_major (char const *compiled)
+{
+ size_t clen = strlen(compiled) ;
+ ssize_t r ;
+ uint32_t res ;
+ char tmp[UINT32_FMT] ;
+ char fn[clen + 7] ;
+ memcpy(fn, compiled, clen) ;
+ memcpy(fn + clen, "/major", 7) ;
+ r = openreadnclose(fn, tmp, UINT32_FMT) ;
+ if (r == -1) return errno == ENOENT ? 6 : 0 ; /* up to 0.6.x.y doesn't have db/major */
+ if (!r) return 0 ;
+ if (tmp[r] != '\n') return (errno = EPROTO, 0) ;
+ tmp[r] = 0 ;
+ if (uint320_scan(tmp, &res) != r) return (errno = EPROTO, 0) ;
+ return res ;
+}