diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-02-05 23:56:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-02-05 23:56:14 +0000 |
commit | 153a646667ff5ae7578a6027938524db91c40821 (patch) | |
tree | 429f092f8254acbb207302d9dd8c790bc596322f /src/include | |
parent | cea441e894405c6d28e302ae4360e9f848b37797 (diff) | |
download | skalibs-153a646667ff5ae7578a6027938524db91c40821.tar.xz |
- Add siovec_trunc
- Add openwritevnclose
- replace buffer_read/write with fd_readsv/writesv
- add localtmn_from_tain_g
- refactor cdb_make
- rewrite buffer_getvall and buffer_putvall, with a bugfix
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/skalibs/buffer.h | 20 | ||||
-rw-r--r-- | src/include/skalibs/cdb_make.h | 10 | ||||
-rw-r--r-- | src/include/skalibs/djbtime.h | 2 | ||||
-rw-r--r-- | src/include/skalibs/djbunix.h | 13 | ||||
-rw-r--r-- | src/include/skalibs/siovec.h | 1 |
5 files changed, 30 insertions, 16 deletions
diff --git a/src/include/skalibs/buffer.h b/src/include/skalibs/buffer.h index 5cf0950..7397b6e 100644 --- a/src/include/skalibs/buffer.h +++ b/src/include/skalibs/buffer.h @@ -4,18 +4,16 @@ #define BUFFER_H #include <skalibs/gccattributes.h> +#include <skalibs/allreadwrite.h> #include <skalibs/bytestr.h> #include <skalibs/cbuffer.h> -#include <skalibs/diuint.h> +#include <skalibs/functypes.h> #include <skalibs/siovec.h> -typedef int buffer_io_func_t (int, siovec_t const *, unsigned int) ; -typedef buffer_io_func_t *buffer_io_func_t_ref ; - typedef struct buffer_s buffer, buffer_t, *buffer_ref, *buffer_t_ref ; struct buffer_s { - buffer_io_func_t *op ; + iovfunc_t_ref op ; int fd ; cbuffer_t c ; } ; @@ -34,7 +32,7 @@ struct buffer_s #define BUFFER_OUTSIZE_SMALL 512 #define BUFFER_INIT(f, d, buf, len) { .op = (f), .fd = (d), .c = CBUFFER_INIT(buf, len) } -extern int buffer_init (buffer *, buffer_io_func_t *, int, char *, unsigned int) ; +extern int buffer_init (buffer *, iovfunc_t_ref, int, char *, unsigned int) ; /* Writing */ @@ -50,7 +48,7 @@ extern int buffer_putvallnoflush (buffer *, siovec_t const *, unsigned int) ; #define buffer_putsallnoflush(b, s) buffer_putallnoflush(b, (s), str_len(s)) extern int buffer_putall (buffer *, char const *, unsigned int, unsigned int *) ; -extern int buffer_putvall (buffer *, siovec_t const *, unsigned int, diuint *) ; +extern int buffer_putvall (buffer *, siovec_t const *, unsigned int, unsigned int *) ; #define buffer_putsall(b, s, w) buffer_putall(b, s, str_len(s), w) #define buffer_putallflush(b, s, len, w) (buffer_putall(b, s, len, w) && buffer_flush(b)) @@ -68,7 +66,6 @@ extern int buffer_putvflush (buffer *, siovec_t const *, unsigned int) ; #define buffer_unput(b, n) cbuffer_unput(&(b)->c, n) #define buffer_wpeek(b, v) cbuffer_wpeek(&(b)->c, v) #define buffer_wseek(b, n) cbuffer_wseek(&(b)->c, n) -extern buffer_io_func_t buffer_write ; /* Reading */ @@ -82,7 +79,7 @@ extern int buffer_getallnofill (buffer *, char *, unsigned int) ; extern int buffer_getvallnofill (buffer *, siovec_t const *, unsigned int) ; extern int buffer_getall (buffer *, char *, unsigned int, unsigned int *) ; -extern int buffer_getvall (buffer *, siovec_t const *, unsigned int, diuint *) ; +extern int buffer_getvall (buffer *, siovec_t const *, unsigned int, unsigned int *) ; extern int buffer_get (buffer *, char *, unsigned int) ; extern int buffer_getv (buffer *, siovec_t const *, unsigned int) ; @@ -90,7 +87,6 @@ extern int buffer_getv (buffer *, siovec_t const *, unsigned int) ; #define buffer_unget(b, n) cbuffer_unget(&(b)->c, n) #define buffer_rpeek(b, n) cbuffer_rpeek(&(b)->c, n) #define buffer_rseek(b, n) cbuffer_rseek(&(b)->c, n) -extern buffer_io_func_t buffer_read ; /* Utility */ @@ -108,7 +104,9 @@ extern int buffer_getfd (buffer const *) gccattr_pure ; /* Globals */ -extern buffer_io_func_t buffer_flush1read ; +#define buffer_read fd_readsv +#define buffer_write fd_writesv +extern iovfunc_t buffer_flush1read ; extern buffer buffer_0_ ; #define buffer_0 (&buffer_0_) diff --git a/src/include/skalibs/cdb_make.h b/src/include/skalibs/cdb_make.h index d0a949b..2858358 100644 --- a/src/include/skalibs/cdb_make.h +++ b/src/include/skalibs/cdb_make.h @@ -5,20 +5,20 @@ #include <skalibs/uint32.h> #include <skalibs/diuint32.h> +#include <skalibs/allreadwrite.h> #include <skalibs/genalloc.h> #include <skalibs/buffer.h> typedef struct cdb_make cdb_make, *cdb_make_ref ; struct cdb_make { - char buf[BUFFER_OUTSIZE] ; - genalloc hplist ; /* diuint32 */ - buffer b ; + genalloc hplist ; /* array of diuint32 */ uint32 pos ; - int fd ; + buffer b ; + char buf[BUFFER_OUTSIZE] ; } ; -#define CDB_MAKE_ZERO { .buf = "", .hplist = GENALLOC_ZERO, .b = BUFFER_INIT(&buffer_write, -1, 0, 0), .pos = 2048, .fd = -1 } +#define CDB_MAKE_ZERO { .hplist = GENALLOC_ZERO, .pos = 2048, .b = BUFFER_INIT(&fd_writesv, -1, 0, 0) } extern int cdb_make_start (struct cdb_make *, int) ; extern int cdb_make_add (struct cdb_make *, char const *, unsigned int, char const *, unsigned int) ; diff --git a/src/include/skalibs/djbtime.h b/src/include/skalibs/djbtime.h index 7e60cd4..229966f 100644 --- a/src/include/skalibs/djbtime.h +++ b/src/include/skalibs/djbtime.h @@ -23,6 +23,7 @@ extern int sysclock_from_utc (uint64 *) ; #define NTP_OFFSET 2208988800UL extern int ntp_from_tain (uint64 *, tain_t const *) ; +#define ntp_from_tain_g(u) ntp_from_tain((u), &STAMP) extern int tain_from_ntp (tain_t *, uint64) ; @@ -55,6 +56,7 @@ extern int localtm_from_tai (struct tm *, tai_t const *, int) ; extern int tai_from_localtm (tai_t *, struct tm const *) ; extern int localtmn_from_tain (localtmn_t *, tain_t const *, int) ; +#define localtmn_from_tain_g(l, h) localtmn_from_tain(l, &STAMP, h) extern int tain_from_localtmn (tain_t *, localtmn_t const *) ; extern int localtmn_from_sysclock (localtmn_t *, tain_t const *, int) ; extern int sysclock_from_localtmn (tain_t *, localtmn_t const *) ; diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index 2f1192f..d22740b 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -10,6 +10,7 @@ #include <unistd.h> #include <skalibs/gccattributes.h> #include <skalibs/uint64.h> +#include <skalibs/siovec.h> #include <skalibs/stralloc.h> #include <skalibs/envalloc.h> #include <skalibs/env.h> /* compatibility */ @@ -122,6 +123,18 @@ extern int openwritenclose_unsafe_internal (char const *, char const *, unsigned #define openwritenclose_suffix_devino_sync(f, s, n, t, dev, ino) openwritenclose_suffix_internal(f, s, n, dev, (ino), 1, t) extern int openwritenclose_suffix_internal (char const *, char const *, unsigned int, uint64 *, uint64 *, int, char const *) ; +#define openwritevnclose_unsafe(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 0) +#define openwritevnclose_unsafe_sync(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 1) +#define openwritevnclose_unsafe_devino(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 0) +#define openwritevnclose_unsafe_devino_sync(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 1) +extern int openwritevnclose_unsafe_internal (char const *, siovec_t const *, unsigned int, uint64 *, uint64 *, int) ; + +#define openwritevnclose_suffix(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 0, t) +#define openwritevnclose_suffix_sync(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 1, t) +#define openwritevnclose_suffix_devino(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 0, t) +#define openwritevnclose_suffix_devino_sync(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 1, t) +extern int openwritevnclose_suffix_internal (char const *, siovec_t const *, unsigned int, uint64 *, uint64 *, int, char const *) ; + extern int rm_rf (char const *) ; extern int rm_rf_tmp (char const *, stralloc *) ; extern int rm_rf_in_tmp (stralloc *, unsigned int) ; /* caution ! */ diff --git a/src/include/skalibs/siovec.h b/src/include/skalibs/siovec.h index 8c8161f..55ef993 100644 --- a/src/include/skalibs/siovec.h +++ b/src/include/skalibs/siovec.h @@ -19,6 +19,7 @@ extern unsigned int siovec_gather (siovec_t const *, unsigned int, char *, unsig extern unsigned int siovec_scatter (siovec_t const *, unsigned int, char const *, unsigned int) ; extern unsigned int siovec_deal (siovec_t const *, unsigned int, siovec_t const *, unsigned int) ; extern unsigned int siovec_seek (siovec_t *, unsigned int, unsigned int) ; +extern unsigned int siovec_trunc (siovec_t *, unsigned int, unsigned int) ; extern void siovec_from_iovec (siovec_t *, struct iovec const *, unsigned int) ; extern void iovec_from_siovec (struct iovec *, siovec_t const *, unsigned int) ; |