summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/bitarray.h1
-rw-r--r--src/include/skalibs/unix-transactional.h2
-rw-r--r--src/libstddjb/bitarray_count.c20
-rw-r--r--src/libunixonacid/openwritevnclose_at.c25
4 files changed, 48 insertions, 0 deletions
diff --git a/src/include/skalibs/bitarray.h b/src/include/skalibs/bitarray.h
index 7cf79b3..ed44fed 100644
--- a/src/include/skalibs/bitarray.h
+++ b/src/include/skalibs/bitarray.h
@@ -24,6 +24,7 @@ extern int bitarray_testandpoke (unsigned char *, unsigned int, int) ;
extern unsigned int bitarray_firstclear (unsigned char const *, unsigned int) gccattr_pure ;
extern unsigned int bitarray_firstset (unsigned char const *, unsigned int) gccattr_pure ;
#define bitarray_first(s, n, h) ((h) ? bitarray_firstset(s, n) : bitarray_firstclear(s, n))
+extern unsigned int bitarray_countones (unsigned char const *, unsigned int) gccattr_pure ;
extern void bitarray_not (unsigned char *, unsigned int, unsigned int) ;
extern void bitarray_and (unsigned char *, unsigned char const *, unsigned char const *, unsigned int) ;
diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h
index 13129f1..e1c8955 100644
--- a/src/include/skalibs/unix-transactional.h
+++ b/src/include/skalibs/unix-transactional.h
@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <skalibs/uint64.h>
+#include <skalibs/siovec.h>
#include <skalibs/stralloc.h>
/* Transactional/reliable filesystem operations */
@@ -36,6 +37,7 @@ extern int openwritenclose_devino (char const *, char const *, unsigned int, uin
extern int openwritenclose_tmp (char const *, char const *, unsigned int, stralloc *) ;
extern int openwritenclose_devino_tmp (char const *, char const *, unsigned int, uint64 *, uint64 *, stralloc *) ;
extern unsigned int openwritenclose_at (int, char const *, char const *, unsigned int) ;
+extern unsigned int openwritevnclose_at (int, char const *, siovec_t const *, unsigned int) ;
extern int mkdir_unique (stralloc *, char const *, unsigned int) ;
diff --git a/src/libstddjb/bitarray_count.c b/src/libstddjb/bitarray_count.c
new file mode 100644
index 0000000..724f2b3
--- /dev/null
+++ b/src/libstddjb/bitarray_count.c
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#include <skalibs/bitarray.h>
+
+#define B0(n) n, n+1, n+1, n+2
+#define B1(n) B0(n), B0(n+1), B0(n+1), B0(n+2)
+#define B2(n) B1(n), B1(n+1), B1(n+1), B1(n+2)
+#define B3(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
+
+unsigned int bitarray_countones (unsigned char const *c, unsigned int n)
+{
+ static unsigned char const table[256] = { B3(0) } ;
+ unsigned int len = bitarray_div8(n) ;
+ unsigned int total = 0 ;
+ register unsigned int i = 0 ;
+ if (n & 7) len-- ;
+ for (; i < len ; i++) total += table[c[i]] ;
+ if (n & 7) total += table[c[i] & ((1 << (n & 7)) - 1)] ;
+ return total ;
+}
diff --git a/src/libunixonacid/openwritevnclose_at.c b/src/libunixonacid/openwritevnclose_at.c
new file mode 100644
index 0000000..7cff485
--- /dev/null
+++ b/src/libunixonacid/openwritevnclose_at.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <unistd.h>
+#include <errno.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/siovec.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/unix-transactional.h>
+
+unsigned int openwritevnclose_at (int dirfd, char const *file, siovec_t const *v, unsigned int n)
+{
+ register unsigned int r ;
+ int fd = open_truncatb(dirfd, file) ;
+ if (fd < 0) return 0 ;
+ r = allwritev(fd, v, n) ;
+ if (r < siovec_len(v, n) || fsync(fd) < 0)
+ {
+ register int e = errno ;
+ fd_close(fd) ;
+ errno = e ;
+ return r ;
+ }
+ fd_close(fd) ;
+ return r ;
+}