commit 153a646667ff5ae7578a6027938524db91c40821 parent cea441e894405c6d28e302ae4360e9f848b37797 Author: Laurent Bercot <ska-skaware@skarnet.org> Date: Thu, 5 Feb 2015 23:56:14 +0000 - 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:
32 files changed, 232 insertions(+), 152 deletions(-)
diff --git a/package/deps.mak b/package/deps.mak @@ -10,15 +10,15 @@ src/include/skalibs/avltreen.h: src/include/skalibs/avlnode.h src/include/skalib src/include/skalibs/biguint.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h src/include/skalibs/bitarray.h: src/include/skalibs/gccattributes.h src/include/skalibs/bufalloc.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h -src/include/skalibs/buffer.h: src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/diuint.h src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h +src/include/skalibs/buffer.h: src/include/skalibs/allreadwrite.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h src/include/skalibs/bytestr.h: src/include/skalibs/config.h src/include/skalibs/gccattributes.h src/include/skalibs/cbuffer.h: src/include/skalibs/bytestr.h src/include/skalibs/diuint.h src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h src/include/skalibs/cdb.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h -src/include/skalibs/cdb_make.h: src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h +src/include/skalibs/cdb_make.h: src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h src/include/skalibs/datastruct.h: src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h src/include/skalibs/gensetdyn.h src/include/skalibs/diuint32.h: src/include/skalibs/uint32.h src/include/skalibs/djbtime.h: src/include/skalibs/config.h src/include/skalibs/tai.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h -src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h +src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h src/include/skalibs/fmtscan.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h @@ -169,7 +169,7 @@ src/librandom/unirandom_init.o src/librandom/unirandom_init.lo: src/librandom/un src/librandom/unirandom_readb.o src/librandom/unirandom_readb.lo: src/librandom/unirandom_readb.c src/include/skalibs/unirandom.h src/librandom/unirandom_readnb.o src/librandom/unirandom_readnb.lo: src/librandom/unirandom_readnb.c src/include/skalibs/unirandom.h src/librandom/unirandom_register.o src/librandom/unirandom_register.lo: src/librandom/unirandom_register.c src/librandom/random-internal.h src/include/skalibs/unirandom.h -src/librandom/unirandomdev.o src/librandom/unirandomdev.lo: src/librandom/unirandomdev.c src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/unirandom.h src/include/skalibs/unirandomdev.h +src/librandom/unirandomdev.o src/librandom/unirandomdev.lo: src/librandom/unirandomdev.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/unirandom.h src/include/skalibs/unirandomdev.h src/librandom/unirandomegd.o src/librandom/unirandomegd.lo: src/librandom/unirandomegd.c src/include/skalibs/djbunix.h src/include/skalibs/randomegd.h src/include/skalibs/unirandom.h src/include/skalibs/unirandomegd.h src/librandom/unisurf.o src/librandom/unisurf.lo: src/librandom/unisurf.c src/include/skalibs/surf.h src/include/skalibs/unirandom.h src/include/skalibs/unisurf.h src/librandom/unisurf_init.o src/librandom/unisurf_init.lo: src/librandom/unisurf_init.c src/librandom/random-internal.h src/include/skalibs/surf.h src/include/skalibs/unirandom.h src/include/skalibs/unisurf.h @@ -217,34 +217,32 @@ src/libstddjb/bufalloc_flush.o src/libstddjb/bufalloc_flush.lo: src/libstddjb/bu src/libstddjb/bufalloc_getfd.o src/libstddjb/bufalloc_getfd.lo: src/libstddjb/bufalloc_getfd.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_getlen.o src/libstddjb/bufalloc_getlen.lo: src/libstddjb/bufalloc_getlen.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_init.o src/libstddjb/bufalloc_init.lo: src/libstddjb/bufalloc_init.c src/include/skalibs/bufalloc.h src/include/skalibs/stralloc.h -src/libstddjb/buffer_0.o src/libstddjb/buffer_0.lo: src/libstddjb/buffer_0.c src/include/skalibs/buffer.h +src/libstddjb/buffer_0.o src/libstddjb/buffer_0.lo: src/libstddjb/buffer_0.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_0f1.o src/libstddjb/buffer_0f1.lo: src/libstddjb/buffer_0f1.c src/include/skalibs/buffer.h -src/libstddjb/buffer_0small.o src/libstddjb/buffer_0small.lo: src/libstddjb/buffer_0small.c src/include/skalibs/buffer.h -src/libstddjb/buffer_1.o src/libstddjb/buffer_1.lo: src/libstddjb/buffer_1.c src/include/skalibs/buffer.h -src/libstddjb/buffer_1small.o src/libstddjb/buffer_1small.lo: src/libstddjb/buffer_1small.c src/include/skalibs/buffer.h -src/libstddjb/buffer_2.o src/libstddjb/buffer_2.lo: src/libstddjb/buffer_2.c src/include/skalibs/buffer.h +src/libstddjb/buffer_0small.o src/libstddjb/buffer_0small.lo: src/libstddjb/buffer_0small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h +src/libstddjb/buffer_1.o src/libstddjb/buffer_1.lo: src/libstddjb/buffer_1.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h +src/libstddjb/buffer_1small.o src/libstddjb/buffer_1small.lo: src/libstddjb/buffer_1small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h +src/libstddjb/buffer_2.o src/libstddjb/buffer_2.lo: src/libstddjb/buffer_2.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_fill.o src/libstddjb/buffer_fill.lo: src/libstddjb/buffer_fill.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/libstddjb/buffer_flush.o src/libstddjb/buffer_flush.lo: src/libstddjb/buffer_flush.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h -src/libstddjb/buffer_flush1read.o src/libstddjb/buffer_flush1read.lo: src/libstddjb/buffer_flush1read.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h +src/libstddjb/buffer_flush1read.o src/libstddjb/buffer_flush1read.lo: src/libstddjb/buffer_flush1read.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_get.o src/libstddjb/buffer_get.lo: src/libstddjb/buffer_get.c src/include/skalibs/buffer.h src/libstddjb/buffer_getall.o src/libstddjb/buffer_getall.lo: src/libstddjb/buffer_getall.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_getallnf.o src/libstddjb/buffer_getallnf.lo: src/libstddjb/buffer_getallnf.c src/include/skalibs/buffer.h src/libstddjb/buffer_getfd.o src/libstddjb/buffer_getfd.lo: src/libstddjb/buffer_getfd.c src/include/skalibs/buffer.h src/libstddjb/buffer_getlen.o src/libstddjb/buffer_getlen.lo: src/libstddjb/buffer_getlen.c src/include/skalibs/buffer.h -src/libstddjb/buffer_getv.o src/libstddjb/buffer_getv.lo: src/libstddjb/buffer_getv.c src/include/skalibs/buffer.h src/include/skalibs/diuint.h src/include/skalibs/siovec.h -src/libstddjb/buffer_getvall.o src/libstddjb/buffer_getvall.lo: src/libstddjb/buffer_getvall.c src/include/skalibs/buffer.h src/include/skalibs/diuint.h src/include/skalibs/siovec.h +src/libstddjb/buffer_getv.o src/libstddjb/buffer_getv.lo: src/libstddjb/buffer_getv.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h +src/libstddjb/buffer_getvall.o src/libstddjb/buffer_getvall.lo: src/libstddjb/buffer_getvall.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_getvallnf.o src/libstddjb/buffer_getvallnf.lo: src/libstddjb/buffer_getvallnf.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h -src/libstddjb/buffer_init.o src/libstddjb/buffer_init.lo: src/libstddjb/buffer_init.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h +src/libstddjb/buffer_init.o src/libstddjb/buffer_init.lo: src/libstddjb/buffer_init.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/functypes.h src/libstddjb/buffer_put.o src/libstddjb/buffer_put.lo: src/libstddjb/buffer_put.c src/include/skalibs/buffer.h src/libstddjb/buffer_putall.o src/libstddjb/buffer_putall.lo: src/libstddjb/buffer_putall.c src/include/skalibs/buffer.h src/libstddjb/buffer_putallnf.o src/libstddjb/buffer_putallnf.lo: src/libstddjb/buffer_putallnf.c src/include/skalibs/buffer.h src/libstddjb/buffer_putflush.o src/libstddjb/buffer_putflush.lo: src/libstddjb/buffer_putflush.c src/include/skalibs/buffer.h -src/libstddjb/buffer_putv.o src/libstddjb/buffer_putv.lo: src/libstddjb/buffer_putv.c src/include/skalibs/buffer.h src/include/skalibs/diuint.h src/include/skalibs/siovec.h -src/libstddjb/buffer_putvall.o src/libstddjb/buffer_putvall.lo: src/libstddjb/buffer_putvall.c src/include/skalibs/buffer.h src/include/skalibs/diuint.h src/include/skalibs/siovec.h +src/libstddjb/buffer_putv.o src/libstddjb/buffer_putv.lo: src/libstddjb/buffer_putv.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h +src/libstddjb/buffer_putvall.o src/libstddjb/buffer_putvall.lo: src/libstddjb/buffer_putvall.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_putvallnf.o src/libstddjb/buffer_putvallnf.lo: src/libstddjb/buffer_putvallnf.c src/include/skalibs/buffer.h src/libstddjb/buffer_putvflush.o src/libstddjb/buffer_putvflush.lo: src/libstddjb/buffer_putvflush.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h -src/libstddjb/buffer_read.o src/libstddjb/buffer_read.lo: src/libstddjb/buffer_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h -src/libstddjb/buffer_write.o src/libstddjb/buffer_write.lo: src/libstddjb/buffer_write.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/byte_chr.o src/libstddjb/byte_chr.lo: src/libstddjb/byte_chr.c src/include/skalibs/bytestr.h src/include/skalibs/config.h src/libstddjb/byte_copy.o src/libstddjb/byte_copy.lo: src/libstddjb/byte_copy.c src/include/skalibs/bytestr.h src/include/skalibs/config.h src/libstddjb/byte_count.o src/libstddjb/byte_count.lo: src/libstddjb/byte_count.c src/include/skalibs/bytestr.h @@ -276,7 +274,7 @@ src/libstddjb/cdb_findnext.o src/libstddjb/cdb_findnext.lo: src/libstddjb/cdb_fi src/libstddjb/cdb_free.o src/libstddjb/cdb_free.lo: src/libstddjb/cdb_free.c src/include/skalibs/cdb.h src/libstddjb/cdb_hash.o src/libstddjb/cdb_hash.lo: src/libstddjb/cdb_hash.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h src/libstddjb/cdb_init_map.o src/libstddjb/cdb_init_map.lo: src/libstddjb/cdb_init_map.c src/include/skalibs/cdb.h -src/libstddjb/cdb_make.o src/libstddjb/cdb_make.lo: src/libstddjb/cdb_make.c src/include/skalibs/buffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/diuint32.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h +src/libstddjb/cdb_make.o src/libstddjb/cdb_make.lo: src/libstddjb/cdb_make.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/diuint32.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h src/libstddjb/cdb_mapfile.o src/libstddjb/cdb_mapfile.lo: src/libstddjb/cdb_mapfile.c src/include/skalibs/cdb.h src/include/skalibs/djbunix.h src/libstddjb/cdb_nextkey.o src/libstddjb/cdb_nextkey.lo: src/libstddjb/cdb_nextkey.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h src/libstddjb/cdb_read.o src/libstddjb/cdb_read.lo: src/libstddjb/cdb_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/bytestr.h src/include/skalibs/cdb.h src/include/skalibs/djbunix.h src/include/skalibs/error.h src/include/skalibs/uint32.h @@ -357,7 +355,7 @@ src/libstddjb/iobufferk_nosys.o src/libstddjb/iobufferk_nosys.lo: src/libstddjb/ src/libstddjb/iobufferu_fill.o src/libstddjb/iobufferu_fill.lo: src/libstddjb/iobufferu_fill.c src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/libstddjb/iobufferu_finish.o src/libstddjb/iobufferu_finish.lo: src/libstddjb/iobufferu_finish.c src/include/skalibs/alloc.h src/include/skalibs/iobuffer.h src/libstddjb/iobufferu_flush.o src/libstddjb/iobufferu_flush.lo: src/libstddjb/iobufferu_flush.c src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h -src/libstddjb/iobufferu_init.o src/libstddjb/iobufferu_init.lo: src/libstddjb/iobufferu_init.c src/include/skalibs/alloc.h src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h +src/libstddjb/iobufferu_init.o src/libstddjb/iobufferu_init.lo: src/libstddjb/iobufferu_init.c src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/libstddjb/iopause.o src/libstddjb/iopause.lo: src/libstddjb/iopause.c src/include/skalibs/config.h src/include/skalibs/iopause.h src/include/skalibs/sysdeps.h src/libstddjb/iopause_poll.o src/libstddjb/iopause_poll.lo: src/libstddjb/iopause_poll.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/iopause_ppoll.o src/libstddjb/iopause_ppoll.lo: src/libstddjb/iopause_ppoll.c src/include/skalibs/iopause.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h @@ -441,6 +439,8 @@ src/libstddjb/openreadnclose.o src/libstddjb/openreadnclose.lo: src/libstddjb/op src/libstddjb/openslurpclose.o src/libstddjb/openslurpclose.lo: src/libstddjb/openslurpclose.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/openwritenclose_suffix.o src/libstddjb/openwritenclose_suffix.lo: src/libstddjb/openwritenclose_suffix.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/uint64.h src/libstddjb/openwritenclose_unsafe.o src/libstddjb/openwritenclose_unsafe.lo: src/libstddjb/openwritenclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/uint64.h +src/libstddjb/openwritevnclose_suffix.o src/libstddjb/openwritevnclose_suffix.lo: src/libstddjb/openwritevnclose_suffix.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h src/include/skalibs/uint64.h +src/libstddjb/openwritevnclose_unsafe.o src/libstddjb/openwritevnclose_unsafe.lo: src/libstddjb/openwritevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h src/include/skalibs/uint64.h src/libstddjb/pathexec.o src/libstddjb/pathexec.lo: src/libstddjb/pathexec.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/environ.h src/libstddjb/pathexec0.o src/libstddjb/pathexec0.lo: src/libstddjb/pathexec0.c src/include/skalibs/djbunix.h src/libstddjb/pathexec0_run.o src/libstddjb/pathexec0_run.lo: src/libstddjb/pathexec0_run.c src/include/skalibs/djbunix.h @@ -502,6 +502,7 @@ src/libstddjb/siovec_gather.o src/libstddjb/siovec_gather.lo: src/libstddjb/siov src/libstddjb/siovec_len.o src/libstddjb/siovec_len.lo: src/libstddjb/siovec_len.c src/include/skalibs/siovec.h src/libstddjb/siovec_scatter.o src/libstddjb/siovec_scatter.lo: src/libstddjb/siovec_scatter.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h src/libstddjb/siovec_seek.o src/libstddjb/siovec_seek.lo: src/libstddjb/siovec_seek.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h +src/libstddjb/siovec_trunc.o src/libstddjb/siovec_trunc.lo: src/libstddjb/siovec_trunc.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h src/libstddjb/skagetln.o src/libstddjb/skagetln.lo: src/libstddjb/skagetln.c src/include/skalibs/buffer.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skagetln_nofill.o src/libstddjb/skagetln_nofill.lo: src/libstddjb/skagetln_nofill.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skagetlnsep.o src/libstddjb/skagetlnsep.lo: src/libstddjb/skagetlnsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h @@ -721,8 +722,8 @@ src/libunixonacid/open_truncat.o src/libunixonacid/open_truncat.lo: src/libunixo src/libunixonacid/open_truncatb.o src/libunixonacid/open_truncatb.lo: src/libunixonacid/open_truncatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeat.o src/libunixonacid/open_writeat.lo: src/libunixonacid/open_writeat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeatb.o src/libunixonacid/open_writeatb.lo: src/libunixonacid/open_writeatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h -src/libunixonacid/opengetlnclose.o src/libunixonacid/opengetlnclose.lo: src/libunixonacid/opengetlnclose.c src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h -src/libunixonacid/opengetlnclose_at.o src/libunixonacid/opengetlnclose_at.lo: src/libunixonacid/opengetlnclose_at.c src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h +src/libunixonacid/opengetlnclose.o src/libunixonacid/opengetlnclose.lo: src/libunixonacid/opengetlnclose.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h +src/libunixonacid/opengetlnclose_at.o src/libunixonacid/opengetlnclose_at.lo: src/libunixonacid/opengetlnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/openreadnclose_at.o src/libunixonacid/openreadnclose_at.lo: src/libunixonacid/openreadnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/openslurpclose_at.o src/libunixonacid/openslurpclose_at.lo: src/libunixonacid/openslurpclose_at.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/openwritenclose.o src/libunixonacid/openwritenclose.lo: src/libunixonacid/openwritenclose.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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) ; diff --git a/src/librandom/unirandomdev.c b/src/librandom/unirandomdev.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> #include <skalibs/unirandom.h> @@ -17,7 +18,7 @@ int unirandomdev_sinit (union unirandominfo *u, char const *file) errno = e ; return 0 ; } - buffer_init(&u->device.b, &buffer_read, fd, u->device.buf, RANDOMBUF_BUFSIZE) ; + buffer_init(&u->device.b, &fd_readsv, fd, u->device.buf, RANDOMBUF_BUFSIZE) ; u->device.nb = 1 ; return 1 ; } diff --git a/src/libstddjb/allreadwritev.c b/src/libstddjb/allreadwritev.c @@ -10,7 +10,7 @@ unsigned int allreadwritev (iovfunc_t_ref op, int fd, siovec_t const *v, unsigne siovec_t vv[vlen] ; for (; written < vlen ; written++) vv[written] = v[written] ; written = 0 ; - while (siovec_len(v, vlen)) + while (siovec_len(vv, vlen)) { register int w = (*op)(fd, vv, vlen) ; if (w <= 0) break ; diff --git a/src/libstddjb/bufalloc_init.c b/src/libstddjb/bufalloc_init.c @@ -5,7 +5,7 @@ void bufalloc_init (bufalloc *ba, int (*op)(int, char const *, unsigned int), int fd) { - ba->x.len = 0 ; + ba->x = stralloc_zero ; ba->op = op ; ba->fd = fd ; ba->p = 0 ; diff --git a/src/libstddjb/buffer_0.c b/src/libstddjb/buffer_0.c @@ -2,7 +2,8 @@ /* MT-unsafe */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> static char buf[BUFFER_INSIZE] ; -buffer buffer_0_ = BUFFER_INIT(&buffer_read, 0, buf, BUFFER_INSIZE) ; +buffer buffer_0_ = BUFFER_INIT(&fd_readsv, 0, buf, BUFFER_INSIZE) ; diff --git a/src/libstddjb/buffer_0small.c b/src/libstddjb/buffer_0small.c @@ -2,7 +2,8 @@ /* MT-unsafe */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> static char buf[BUFFER_INSIZE_SMALL] ; -buffer buffer_0small_ = BUFFER_INIT(&buffer_read, 0, buf, BUFFER_INSIZE_SMALL) ; +buffer buffer_0small_ = BUFFER_INIT(&fd_readsv, 0, buf, BUFFER_INSIZE_SMALL) ; diff --git a/src/libstddjb/buffer_1.c b/src/libstddjb/buffer_1.c @@ -2,7 +2,8 @@ /* MT-unsafe */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> static char buf[BUFFER_OUTSIZE] ; -buffer buffer_1_ = BUFFER_INIT(&buffer_write, 1, buf, BUFFER_OUTSIZE) ; +buffer buffer_1_ = BUFFER_INIT(&fd_writesv, 1, buf, BUFFER_OUTSIZE) ; diff --git a/src/libstddjb/buffer_1small.c b/src/libstddjb/buffer_1small.c @@ -2,7 +2,8 @@ /* MT-unsafe */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> static char buf[BUFFER_OUTSIZE_SMALL] ; -buffer buffer_1small_ = BUFFER_INIT(&buffer_write, 1, buf, BUFFER_OUTSIZE_SMALL) ; +buffer buffer_1small_ = BUFFER_INIT(&fd_writesv, 1, buf, BUFFER_OUTSIZE_SMALL) ; diff --git a/src/libstddjb/buffer_2.c b/src/libstddjb/buffer_2.c @@ -2,7 +2,8 @@ /* MT-unsafe */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> static char buf[BUFFER_ERRSIZE] ; -buffer buffer_2_ = BUFFER_INIT(&buffer_write, 2, buf, BUFFER_ERRSIZE) ; +buffer buffer_2_ = BUFFER_INIT(&fd_writesv, 2, buf, BUFFER_ERRSIZE) ; diff --git a/src/libstddjb/buffer_flush1read.c b/src/libstddjb/buffer_flush1read.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/siovec.h> int buffer_flush1read (int fd, siovec_t const *v, unsigned int n) { if (!buffer_flush(buffer_1)) return -1 ; - return buffer_read(fd, v, n) ; + return fd_readsv(fd, v, n) ; } diff --git a/src/libstddjb/buffer_getall.c b/src/libstddjb/buffer_getall.c @@ -7,12 +7,13 @@ int buffer_getall (buffer *b, char *buf, unsigned int len, unsigned int *w) { if (*w > len) return (errno = EINVAL, -1) ; - *w += buffer_getnofill(b, buf + *w, len - *w) ; - while (*w < len) + for (;;) { - register int r = sanitize_read(buffer_fill(b)) ; - if (r <= 0) return r ; + register int r ; *w += buffer_getnofill(b, buf + *w, len - *w) ; + if (*w >= len) break ; + r = sanitize_read(buffer_fill(b)) ; + if (r <= 0) return r ; } return 1 ; } diff --git a/src/libstddjb/buffer_getv.c b/src/libstddjb/buffer_getv.c @@ -1,15 +1,12 @@ /* ISC license. */ -#include <errno.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> -#include <skalibs/diuint.h> #include <skalibs/siovec.h> int buffer_getv (buffer *b, siovec_t const *v, unsigned int n) { - diuint w = DIUINT_ZERO ; - register int r = buffer_getvall(b, v, n, &w) ; - return r == -1 ? errno == EPIPE ? (errno = 0, 0) : -1 : - !r ? (errno = EWOULDBLOCK, -1) : - (int)(siovec_len(v, w.left) + w.right) ; + unsigned int w = 0 ; + register int r = unsanitize_read(buffer_getvall(b, v, n, &w)) ; + return r <= 0 ? r : w ; } diff --git a/src/libstddjb/buffer_getvall.c b/src/libstddjb/buffer_getvall.c @@ -1,18 +1,30 @@ /* ISC license. */ #include <errno.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> -#include <skalibs/diuint.h> #include <skalibs/siovec.h> -int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, diuint *w) +int buffer_getvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written) { - if (w->left > n || (w->left == n && w->right) || w->right >= v[w->left].len) - return (errno = EINVAL, -1) ; - for (; w->left < n ; w->left++, w->right = 0) + unsigned int len = siovec_len(v, n) ; + siovec_t vv[n] ; + if (*written > len) return (errno = EINVAL, -1) ; { - register int r = buffer_getall(b, v[w->left].s, v[w->left].len, &w->right) ; + register unsigned int i = n ; + while (i--) vv[i] = v[i] ; + } + siovec_seek(vv, n, *written) ; + for (;;) + { + register int r ; + unsigned int w = buffer_getvnofill(b, vv, n) ; + *written += w ; + if (*written >= len) break ; + siovec_seek(vv, n, w) ; + r = sanitize_read(buffer_fill(b)) ; if (r <= 0) return r ; } return 1 ; } + diff --git a/src/libstddjb/buffer_init.c b/src/libstddjb/buffer_init.c @@ -2,9 +2,10 @@ #include <errno.h> #include <skalibs/cbuffer.h> +#include <skalibs/functypes.h> #include <skalibs/buffer.h> -int buffer_init (buffer *b, buffer_io_func_t *op, int fd, char *s, unsigned int len) +int buffer_init (buffer *b, iovfunc_t_ref op, int fd, char *s, unsigned int len) { if (!cbuffer_init(&b->c, s, len)) return 0 ; b->fd = fd ; diff --git a/src/libstddjb/buffer_putv.c b/src/libstddjb/buffer_putv.c @@ -1,12 +1,10 @@ /* ISC license. */ #include <skalibs/buffer.h> -#include <skalibs/diuint.h> #include <skalibs/siovec.h> int buffer_putv (buffer *b, siovec_t const *v, unsigned int n) { - diuint w = DIUINT_ZERO ; - if (!buffer_putvall(b, v, n, &w)) return -1 ; - return (int)(siovec_len(v, w.left) + w.right) ; + unsigned int w = 0 ; + return buffer_putvall(b, v, n, &w) ? w : -1 ; } diff --git a/src/libstddjb/buffer_putvall.c b/src/libstddjb/buffer_putvall.c @@ -2,14 +2,23 @@ #include <errno.h> #include <skalibs/buffer.h> -#include <skalibs/diuint.h> #include <skalibs/siovec.h> -int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, diuint *w) +int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written) { - if (w->left > n || (w->left == n && w->right) || w->right >= v[w->left].len) - return (errno = EINVAL, 0) ; - for (; w->left < n ; w->left++, w->right = 0) - if (!buffer_putall(b, v[w->left].s, v[w->left].len, &w->right)) return 0 ; - return 1 ; + unsigned int len = siovec_len(v, n) ; + unsigned int w = n ; + siovec_t vv[n] ; + if (*written > len) return (errno = EINVAL, 0) ; + while (w--) vv[w] = v[w] ; + w = *written ; + for (;;) + { + siovec_seek(vv, n, w) ; + w = buffer_putvnoflush(b, vv, n) ; + *written += w ; + if (*written >= len) return 1 ; + buffer_flush(b) ; + if (buffer_isfull(b)) return 0 ; + } } diff --git a/src/libstddjb/buffer_read.c b/src/libstddjb/buffer_read.c @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> -#include <skalibs/buffer.h> - -int buffer_read (int fd, siovec_t const *v, unsigned int n) -{ - struct iovec iov[n] ; - iovec_from_siovec(iov, v, n) ; - return fd_readv(fd, iov, n) ; -} diff --git a/src/libstddjb/buffer_write.c b/src/libstddjb/buffer_write.c @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <skalibs/allreadwrite.h> -#include <skalibs/siovec.h> -#include <skalibs/buffer.h> - -int buffer_write (int fd, siovec_t const *v, unsigned int n) -{ - unsigned int w = allreadwritev(&fd_writesv, fd, v, n) ; - return w ? (int)w : -1 ; -} diff --git a/src/libstddjb/cdb_make.c b/src/libstddjb/cdb_make.c @@ -4,26 +4,19 @@ #include <errno.h> #include <skalibs/uint32.h> #include <skalibs/diuint32.h> -#include <skalibs/genalloc.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> +#include <skalibs/genalloc.h> #include <skalibs/cdb.h> #include <skalibs/cdb_make.h> -static void cdb_make_free (struct cdb_make *c) -{ - struct cdb_make zero = CDB_MAKE_ZERO ; - genalloc_free(diuint32, &c->hplist) ; - *c = zero ; -} - int cdb_make_start (struct cdb_make *c, int fd) { c->hplist = genalloc_zero ; - c->fd = fd ; c->pos = 2048 ; - buffer_init(&c->b, &buffer_write, fd, c->buf, BUFFER_OUTSIZE) ; - return seek_set(fd, c->pos) ; + buffer_init(&c->b, &fd_writesv, fd, c->buf, BUFFER_OUTSIZE) ; + return (int)lseek(fd, c->pos, SEEK_SET) ; } static int posplus (struct cdb_make *c, uint32 len) @@ -34,41 +27,30 @@ static int posplus (struct cdb_make *c, uint32 len) return 1 ; } -static int cdb_make_addend (struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h) +static inline int cdb_make_addend (struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h) { - diuint32 blah = { h, c->pos } ; - if (!genalloc_append(diuint32, &c->hplist, &blah) || !posplus(c, 8) || !posplus(c, keylen) || !posplus(c, datalen)) - { - cdb_make_free(c) ; - return -1 ; - } - return 0 ; + diuint32 blah = { .left = h, .right = c->pos } ; + return genalloc_append(diuint32, &c->hplist, &blah) && posplus(c, 8) && posplus(c, keylen) && posplus(c, datalen) ; } -static int cdb_make_addbegin (struct cdb_make *c, unsigned int keylen, unsigned int datalen) +static inline int cdb_make_addbegin (struct cdb_make *c, unsigned int keylen, unsigned int datalen) { char buf[8] ; - if ((keylen > 0xffffffff) || (datalen > 0xffffffff)) - { - errno = ENOMEM ; - goto err ; - } - uint32_pack(buf, keylen) ; - uint32_pack(buf + 4, datalen) ; - if (buffer_put(&c->b, buf, 8) < 0) goto err ; - return 0 ; -err: - cdb_make_free(c) ; - return -1 ; + uint32_pack(buf, (uint32)keylen) ; + uint32_pack(buf + 4, (uint32)datalen) ; + return buffer_put(&c->b, buf, 8) ; } int cdb_make_add (struct cdb_make *c, char const *key, unsigned int keylen, char const *data, unsigned int datalen) { - if ((cdb_make_addbegin(c, keylen, datalen) < 0) - || (buffer_put(&c->b, key, keylen) < 0) - || (buffer_put(&c->b, data, datalen) < 0) - || (cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen)) < 0)) + if (cdb_make_addbegin(c, keylen, datalen) < 0 + || buffer_put(&c->b, key, keylen) < 0 + || buffer_put(&c->b, data, datalen) < 0 + || !cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen))) + { + genalloc_free(diuint32, &c->hplist) ; return -1 ; + } return 0 ; } @@ -82,7 +64,7 @@ int cdb_make_finish (struct cdb_make *c) register unsigned int i = 0 ; register diuint32 *hp = genalloc_s(diuint32, &c->hplist) ; - for ( ; i < 256 ; i++) count[i] = 0 ; + for (; i < 256 ; i++) count[i] = 0 ; for (i = 0 ; i < n ; i++) ++count[hp[i].left & 255] ; { @@ -115,7 +97,7 @@ int cdb_make_finish (struct cdb_make *c) uint32_pack(final + (i << 3), c->pos) ; uint32_pack(final + (i << 3) + 4, len) ; - for ( ; j < len ; j++) hp[j].left = hp[j].right = 0 ; + for (; j < len ; j++) hp[j].left = hp[j].right = 0 ; for (j = 0 ; j < k ; j++) { register uint32 where = (p->left >> 8) % len ; @@ -127,19 +109,14 @@ int cdb_make_finish (struct cdb_make *c) { uint32_pack(buf, hp[j].left) ; uint32_pack(buf + 4, hp[j].right) ; - if (buffer_put(&c->b, buf, 8) < 0) goto err0 ; - if (!posplus(c, 8)) goto err0 ; + if (buffer_put(&c->b, buf, 8) < 0) return -1 ; + if (!posplus(c, 8)) return -1 ; } } } - if (!buffer_flush(&c->b)) goto err0 ; - if (seek_begin(c->fd) == -1) goto err0 ; - if (buffer_putflush(&c->b, final, 2048) < 0) goto err0 ; - cdb_make_free(c) ; + if (!buffer_flush(&c->b)) return -1 ; + if (lseek(buffer_fd(&c->b), 0, SEEK_SET) < 0) return -1 ; + if (buffer_putflush(&c->b, final, 2048) < 0) return -1 ; return 0 ; - -err0: - cdb_make_free(c) ; - return -1 ; } diff --git a/src/libstddjb/fd_readsv.c b/src/libstddjb/fd_readsv.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> diff --git a/src/libstddjb/fd_writesv.c b/src/libstddjb/fd_writesv.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <sys/types.h> +#include <sys/uio.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> diff --git a/src/libstddjb/iobufferu_init.c b/src/libstddjb/iobufferu_init.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <skalibs/alloc.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/iobuffer.h> @@ -9,7 +10,7 @@ int iobufferu_init (iobufferu *b, int fdin, int fdout) register char *x = alloc(IOBUFFERU_SIZE) ; if (!x) return 0 ; b->buf = x ; - buffer_init(&b->b[0], &buffer_read, fdin, x, IOBUFFERU_SIZE) ; - buffer_init(&b->b[1], &buffer_write, fdout, x, IOBUFFERU_SIZE) ; + buffer_init(&b->b[0], &fd_readsv, fdin, x, IOBUFFERU_SIZE) ; + buffer_init(&b->b[1], &fd_writesv, fdout, x, IOBUFFERU_SIZE) ; return 1 ; } diff --git a/src/libstddjb/openwritevnclose_suffix.c b/src/libstddjb/openwritevnclose_suffix.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <skalibs/uint64.h> +#include <skalibs/bytestr.h> +#include <skalibs/siovec.h> +#include <skalibs/djbunix.h> + +int openwritevnclose_suffix_internal (char const *fn, siovec_t const *v, unsigned int n, uint64 *dev, uint64 *ino, int dosync, char const *suffix) +{ + uint64 tmpdev, tmpino ; + unsigned int len = str_len(fn) ; + unsigned int suffixlen = str_len(suffix) ; + char tmp[len + suffixlen + 1] ; + byte_copy(tmp, len, fn) ; + byte_copy(tmp + len, suffixlen + 1, suffix) ; + if (!openwritevnclose_unsafe_internal(tmp, v, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ; + if (rename(tmp, fn) < 0) + { + register int e = errno ; + unlink(tmp) ; + errno = e ; + return 0 ; + } + if (dev) *dev = tmpdev ; + if (ino) *ino = tmpino ; + return 1 ; +} diff --git a/src/libstddjb/openwritevnclose_unsafe.c b/src/libstddjb/openwritevnclose_unsafe.c @@ -0,0 +1,33 @@ +/* ISC license. */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <unistd.h> +#include <skalibs/uint64.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/siovec.h> +#include <skalibs/djbunix.h> + +int openwritevnclose_unsafe_internal (char const *fn, siovec_t const *v, unsigned int vlen, uint64 *dev, uint64 *ino, int dosync) +{ + struct stat st ; + int fd = open_trunc(fn) ; + if (fd < 0) return 0 ; + if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) goto fail ; + if ((dev || ino) && (fstat(fd, &st) < 0)) goto fail ; + if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) goto fail ; + fd_close(fd) ; + if (dev) *dev = (uint64)st.st_dev ; + if (ino) *ino = (uint64)st.st_ino ; + return 1 ; + + fail: + { + register int e = errno ; + fd_close(fd) ; + unlink(fn) ; + errno = e ; + } + return 0 ; +} diff --git a/src/libstddjb/siovec_trunc.c b/src/libstddjb/siovec_trunc.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include <skalibs/bytestr.h> +#include <skalibs/siovec.h> + +unsigned int siovec_trunc (siovec_t *v, unsigned int n, unsigned int len) +{ + register unsigned int i = siovec_len(v, n) ; + if (i < len) return n ; + len = i - len ; + i = n ; + while (len && i--) + { + register unsigned int w = len > v[i].len ? v[i].len : len ; + v[i].len -= w ; len -= w ; + } + return i ; +} diff --git a/src/libunixonacid/opengetlnclose.c b/src/libunixonacid/opengetlnclose.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -15,7 +16,7 @@ int opengetlnclose (char const *fn, stralloc *sa, int sep) register int e ; int fd = open_readb(fn) ; if (fd < 0) return -1 ; - buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; + buffer_init(&b, &fd_readsv, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; e = errno ; fd_close(fd) ; diff --git a/src/libunixonacid/opengetlnclose_at.c b/src/libunixonacid/opengetlnclose_at.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> +#include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -15,7 +16,7 @@ int opengetlnclose_at (int dirfd, char const *fn, stralloc *sa, int sep) register int e ; int fd = open_readatb(dirfd, fn) ; if (fd < 0) return -1 ; - buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; + buffer_init(&b, &fd_readsv, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; e = errno ; fd_close(fd) ;