From efd2b41c35d427c78c685b9a543578df3641135d Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 16 May 2015 00:26:24 +0000 Subject: - add bitarray_count - add openwritevnclose_at - rc for 2.3.5.0 --- src/include/skalibs/bitarray.h | 1 + src/include/skalibs/unix-transactional.h | 2 ++ src/libstddjb/bitarray_count.c | 20 ++++++++++++++++++++ src/libunixonacid/openwritevnclose_at.c | 25 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 src/libstddjb/bitarray_count.c create mode 100644 src/libunixonacid/openwritevnclose_at.c (limited to 'src') 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 #include #include +#include #include /* 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 + +#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 +#include +#include +#include +#include +#include + +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 ; +} -- cgit v1.2.3