diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-07-23 16:43:57 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-07-23 16:43:57 +0000 |
commit | dd6bb6c6b8298ebeff2d1882becb36580b969d6f (patch) | |
tree | 3d922a5791e7e34e2b041ea5f3489360bfa798e1 | |
parent | 122f9363682e5de8ce4056c4c05c1eaf8935cf19 (diff) | |
download | skalibs-dd6bb6c6b8298ebeff2d1882becb36580b969d6f.tar.xz |
New 2.11.0.0 branch with several modifications
- libbiguint removed
- cdb_make changed to cdbmake (because different ui)
- cdb redesigned
Signed-off-by: Laurent Bercot <ska@appnovation.com>
58 files changed, 285 insertions, 1171 deletions
@@ -1,5 +1,19 @@ Changelog for skalibs. +In 2.11.0.0 +----------- + + - libbiguint removed. + - New posixplz function: munmap_void. + - cdb_make renamed to cdbmake; ui changed to 1=success/0=failure. + - cdb redesigned. cdb is now fixed, cdb_reader holds the state for cdb_find, + which puts data pointer and len directly into a cdb_data. A cdb + is always a map, pointers should always work. + - cdb_successor removed (unsafe to use); cdb_nextkey changed to + cdb_traverse_next, which puts key and data into two cdb_data's. + - cdb does not touch errno anymore. + + In 2.10.0.3 ----------- diff --git a/doc/index.html b/doc/index.html index 203d4d2..3b5dba0 100644 --- a/doc/index.html +++ b/doc/index.html @@ -60,7 +60,7 @@ with a standard C development environment </li> <h3> Download </h3> <ul> - <li> The current released version of skalibs is <a href="skalibs-2.10.0.3.tar.gz">2.10.0.3</a>. </li> + <li> The current released version of skalibs is <a href="skalibs-2.11.0.0.tar.gz">2.11.0.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/skalibs/">skalibs git repository</a>: diff --git a/doc/libbiguint/index.html b/doc/libbiguint/index.html deleted file mode 100644 index f0378dd..0000000 --- a/doc/libbiguint/index.html +++ /dev/null @@ -1,388 +0,0 @@ -<html> - <head> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <meta http-equiv="Content-Language" content="en" /> - <title>skalibs: the biguint library interface</title> - <meta name="Description" content="skalibs: the biguint library interface" /> - <meta name="Keywords" content="skalibs biguint libbiguint library interface" /> - <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> - </head> -<body> - -<p> -<a href="../libskarnet.html">libskarnet</a><br /> -<a href="../index.html">skalibs</a><br /> -<a href="//skarnet.org/software/">Software</a><br /> -<a href="//skarnet.org/">www.skarnet.org</a> -</p> - -<h1> The <tt>biguint</tt> library interface </h1> - -<p> -<tt>biguint</tt> is set of simple primitives performing arithmetical -operations on (unsigned) integers of arbitrary length. It is nowhere -near as powerful or efficient as specialized, -assembly language-optimized libraries such as -<a href="https://gmplib.org/">GMP</a>, but it has the advantages -of smallness and simplicity. -</p> - -<h2> Compiling </h2> - -<ul> - <li> Use <tt>#include <skalibs/biguint.h></tt> </li> -</ul> - -<h2> Programming </h2> - -<p> - You should refer to the <tt>skalibs/biguint.h</tt> header for the exact function -prototypes. -</p> - -<h3> <a name="defs" /> -Definitions </h3> - -<ul> - <li> A <em>biguint</em> <tt>x</tt> is a pointer to an array <tt>u</tt> -of uint32_t, together with an unsigned integer <tt>n</tt> called its <em>length</em>. -<br><tt>x = (2^32)^0 * u[0] + (2^32)^1 * u[1] + ... + (2^32)^(n-1) * u[n-1]</tt>. </li> - <li> Every <tt>u[i]</tt> is called a <em>limb</em>. </li> - <li> The greatest integer <tt>i</tt> lesser than <tt>n</tt> for which -<tt>u[i]</tt> is non-zero is called the <em>order</em> of <tt>x</tt>. The -order of zero is 0. </li> -</ul> - -<h3> <a name="basic" /> -Basic operations </h3> - -<h4> Creating a biguint </h4> - -<p> - Just declare <tt>uint32_t x[n] ;</tt> - <em>n</em> being the length of the -biguint. You could also allocate <em>x</em> in the heap, possibly using a -uint32_t <a href="../libstddjb/genalloc.html">genalloc</a>. In the following, -a biguint is always referred to as a <tt>uint32_t *</tt> with its -<tt>unsigned int</tt> length ; it must always be pre-allocated. -</p> - -<p> - If an operation fails because a biguint's length <tt>n</tt> is too small to -accommodate the result, the function will write the first (i.e. least significant) -<tt>n</tt> limbs of the result, truncating it, then return 0 with errno set to -EOVERFLOW. -</p> - -<h4> Setting it to zero </h4> - -<pre> -uint32_t *x ; -unsigned int n ; - - bu_zero(x, n) ; -</pre> - -<p> -<tt>bu_zero()</tt> sets the first <tt>n</tt> limbs of <tt>x</tt> to zero. -</p> - -<h4> Copying a biguint </h4> - -<pre> -uint32_t const *x ; -unsigned int xn ; -uint32_t *y ; -unsigned int yn ; - - bu_copy(y, yn, x, xn) ; -</pre> - -<p> -<tt>bu_copy()</tt> copies <tt>x</tt> to <tt>y</tt>, setting higher limbs of <tt>y</tt> -to zero if needed. It then returns 1. If <tt>y</tt> is too small to contain <tt>x</tt>, -the function returns 0 EOVERFLOW. -</p> - -<h4> Calculating the order </h4> - -<pre> -uint32_t const *x ; -unsigned int n ; -unsigned int r ; - - r = bu_len(x, n) ; -</pre> - -<p> -<tt>bu_len()</tt> outputs the order of <tt>x</tt> of length <tt>n</tt>. -<tt>0 <= r <= n</tt>. -</p> - -<h4> Comparing two biguints </h4> - -<pre> -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; -int r ; - - r = bu_cmp(a, an, b, bn) ; -</pre> - -<p> -<tt>bu_cmp()</tt> returns -1 if <tt>a < b</tt>, 1 if -<tt>a > b</tt>, and 0 if <tt>a = b</tt>. -</p> - -<h3> <a name="io" /> -I/O operations </h3> - -<h4> Writing a biguint as an array of bytes </h4> - -<pre> -char *s ; -uint32_t const *x ; -unsigned int n ; - - bu_pack(s, x, n) ; - bu_pack_big(s, x, n) ; -</pre> - -<p> -<tt>bu_pack()</tt> writes <tt>4*n</tt> bytes to <tt>s</tt>. The bytes -are a little-endian representation of <tt>x</tt>.<br /> -<tt>bu_pack_big()</tt> is the same, with a big-endian representation. -</p> - -<h4> Reading a biguint from an array of bytes </h4> - -<pre> -char const *s ; -uint32_t *x ; -unsigned int n ; - - bu_unpack(s, x, n) ; - bu_unpack_big(s, x, n) ; -</pre> - -<p> -<tt>bu_unpack()</tt> reads <tt>4*n</tt> little-endian bytes from <tt>s</tt> -and writes them into the corresponding biguint <tt>x</tt>. <br /> -<tt>bu_unpack_big()</tt> is the same, but the bytes are interpreted as -big-endian. -</p> - -<h4> Formatting a biguint for readable output </h4> - -<pre> -char *s ; -uint32_t const *x ; -unsigned int n ; - - bu_fmt(s, x, n) ; -</pre> - -<p> -<tt>bu_fmt()</tt> writes <tt>x</tt> in <tt>s</tt> as a standard big-endian -hexadecimal number. <tt>x</tt> is considered of length <tt>n</tt>, so -<tt>8*n</tt> bytes will be written to <tt>s</tt>, even if it <tt>x</tt> -starts with zeros. <tt>bu_fmt</tt> returns the number of bytes written. -</p> - -<h4> Reading a biguint from readable format </h4> - -<pre> -char const *s ; -uint32_t *x ; -unsigned int xn ; -unsigned int z ; -unsigned int len ; - - len = bu_scanlen(s, &z) ; - bu_scan(s, len, x, xn, z) ; -</pre> - -<p> - bu_scanlen() scans <tt>s</tt> for a biguint written as a hexadecimal -number and returns the number of -bytes read. The reading stops at the first byte encountered that is not -in the 0-9, A-F or a-f range. The <tt>z</tt> integer then contains the -number of bytes excluding leading zeros. -</p> - -<p> - If x has not been allocated yet, you can use <tt>xn = bitarray_div8(z)</tt> -(if you have included the <tt>bitarray.h</tt> header) -and allocate <tt>x</tt> with length <tt>xn</tt>. -</p> - -<p> -<tt>bu_scan()</tt> then reads <tt>len</tt> bytes from <tt>s</tt>, assuming -there are <tt>z</tt> significant bytes (i.e. not leading zeros); it writes -the resulting biguint into <tt>x</tt> of length <tt>xn</tt>. It returns 1, -except if <tt>xn</tt> is too small, in which case it returns 0 EOVERFLOW. -</p> - -<h3> <a name="arith" /> -Arithmetic operations </h3> - -<h4> Addition </h4> - -<pre> -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; -uint32_t *c ; -unsigned int cn ; -unsigned char carrybefore ; -unsigned char carryafter ; - - bu_add(c, cn, a, an, b, bn) ; - bu_sub(c, cn, a, an, b, bn) ; -</pre> - -<p> -<tt>bu_add()</tt> adds <tt>a</tt> and <tt>b</tt>, and puts the result -into <tt>c</tt>. It returns 1 unless it has to truncate it. -</p> - -<p> -<tt>bu_sub()</tt> substracts <tt>b</tt> from <tt>a</tt>, and puts the -result into <tt>c</tt>. If the result should be negative, then it is -written as <tt>(2^32)^cn - c</tt> and the function returns 0 EOVERFLOW. -</p> - -<h4> Multiplication </h4> - -<pre> -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; -uint32_t *c ; -unsigned int cn ; - - bu_mul(c, cn, a, an, b, bn) ; -</pre> - -<p> -<tt>bu_mul()</tt> computes <tt>c=a*b</tt>. -Make sure that <tt>cn</tt> ≥ <tt>bu_len(a, an) + bu_len(b, bn)</tt>. -If it is not the case, the result will be truncated and bu_mul will return -0 EOVERFLOW. -</p> - -<h4> Division </h4> - -<pre> -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; -uint32_t *q ; -unsigned int qn ; -uint32_t *r ; -unsigned int rn ; - - bu_div(a, an, b, bn, q, qn, r, rn) ; - bu_mod(r, rn, b, bn) ; -</pre> - -<p> -<tt>bu_div()</tt> computes <tt>q</tt>, the quotient, and <tt>r</tt>, the -remainder, of <tt>a</tt> divided by <tt>b</tt>. If <tt>b</tt> is zero, it -returns 0 EDOM. If <tt>qn</tt> or <tt>rn</tt> is to small to store the -quotient or the remainder, it returns 0 EOVERFLOW. -<tt>bu_mod()</tt> computes only the remainder, and stores it in-place. -</p> - -<h4> GCD </h4> - -<pre> -uint32_t *r ; -unsigned int rn ; -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; - - bu_gcd(r, rn, a, an, b, bn) ; -</pre> - -<p> -<tt>bu_gcd()</tt> computes the greatest common divisor between <tt>a</tt> -and <tt>b</tt>, and stores it into <tt>r</tt>. It returns 1 if all went well. -</p> - -<p> - Note that this function iterates on divisions, so it might use a non totally -negligible amount of CPU time. -</p> - - -<h4> Left-shifts and right-shifts </h4> - -<pre> -uint32_t *x ; -unsigned int xn ; -unsigned char carryafter ; -unsigned char carrybefore ; - - carryafter = bu_slbc(x, xn, carrybefore) ; - carryafter = bu_srbc(x, xn, carrybefore) ; -</pre> - -<p> -<tt>bu_slbc()</tt> computes <tt>x <<= 1</tt>. -The least significant bit of <tt>x</tt> is then set to -<tt>carrybefore</tt>. <tt>bu_slbc()</tt> returns the -previous value of <tt>x</tt>'s most significant bit. <br /> -<tt>bu_srbc()</tt> computes <tt>x >>= 1</tt>. -The most significant bit of <tt>x</tt> is then set to -<tt>carrybefore</tt>. <tt>bu_slbc()</tt> returns the -previous value of <tt>x</tt>'s least significant bit.<br /> -<tt>bu_slb(x, n)</tt> and <tt>bu_srb(x, n)</tt> are macros for -respectively <tt>bu_slbc(x, n, 0)</tt> and <tt>bu_srbc(x, n, 0)</tt>. -</p> - -<h4> Modular operations </h4> - -<pre> -uint32_t const *a ; -unsigned int an ; -uint32_t const *b ; -unsigned int bn ; -uint32_t *c ; -unsigned int cn ; -uint32_t const *m ; -unsigned int mn ; - - bu_addmod(c, cn, a, an, b, bn, m, mn) ; - bu_submod(c, cn, a, an, b, bn, m, mn) ; - bu_mulmod(c, cn, a, an, b, bn, m, mn) ; - bu_divmod(c, cn, a, an, b, bn, m, mn) ; - bu_invmod(c, cn, m, mn) ; -</pre> - -<p> -<tt>bu_addmod()</tt> computes <tt>c = (a+b) mod m</tt>.<br /> -<tt>bu_submod()</tt> computes <tt>c = (a-b) mod m</tt>.<br /> -<tt>bu_mulmod()</tt> computes <tt>c = (a*b) mod m</tt>.<br /> -<tt>a</tt> and <tt>b</tt> must already be numbers modulo <tt>m</tt>.<br /> -The functions return 1 if all went well. -</p> - -<p> -<tt>bu_divmod()</tt> computes <tt>a</tt> divided by <tt>b</tt> modulo -<tt>m</tt> and stores it into <tt>c</tt>. <br /> -<tt>bu_invmod()</tt> computes the inverse of <tt>c</tt> modulo <tt>m</tt> -and stores it into <tt>c</tt>. <br /> -The divisor and <tt>m</tt> must be relatively prime, else -those functions return 0 EDOM. -</p> - -</body> -</html> diff --git a/doc/libskarnet.html b/doc/libskarnet.html index 5ff9154..0c28ebb 100644 --- a/doc/libskarnet.html +++ b/doc/libskarnet.html @@ -103,7 +103,6 @@ basic data structures like sets or trees</li> pseudorandom number generation </li> <li><a href="libunixonacid/">libunixonacid</a>: more advanced C/Unix APIs, mainly for safe asynchronous interprocess communication </li> -<li><a href="libbiguint/">libbiguint</a>: large integer arithmetic</li> </ul> </body> diff --git a/doc/libstddjb/cdb_make.html b/doc/libstddjb/cdbmake.html index 767601b..1ff9cbe 100644 --- a/doc/libstddjb/cdb_make.html +++ b/doc/libstddjb/cdbmake.html @@ -3,9 +3,9 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Language" content="en" /> - <title>skalibs: the cdb_make header</title> - <meta name="Description" content="skalibs: the cdb_make header" /> - <meta name="Keywords" content="skalibs header cdb_make constant database map hashmap writing" /> + <title>skalibs: the cdbmake header</title> + <meta name="Description" content="skalibs: the cdbmake header" /> + <meta name="Keywords" content="skalibs header cdbmake cdb constant database map hashmap writing" /> <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> </head> <body> @@ -18,7 +18,7 @@ <a href="//skarnet.org/">skarnet.org</a> </p> -<h1> The <tt>skalibs/cdb_make.h</tt> header </h1> +<h1> The <tt>skalibs/cdbmake.h</tt> header </h1> <p> TODO: write this documentation page. (Sorry!) diff --git a/doc/libstddjb/index.html b/doc/libstddjb/index.html index 2947530..e10482e 100644 --- a/doc/libstddjb/index.html +++ b/doc/libstddjb/index.html @@ -55,7 +55,7 @@ wrappers</a> around I/O functions, extra I/O functions </li> <li> <a href="bytestr.html">skalibs/bytestr.h</a>: basic operations on strings and byte arrays </li> <li> <a href="cdb.html">skalibs/cdb.h</a>: how to read <a href="https://en.wikipedia.org/wiki/Cdb_%28software%29">cdb</a> files </li> - <li> <a href="cdb_make.html">skalibs/cdb_make.h</a>: how to write + <li> <a href="cdbmake.html">skalibs/cdbmake.h</a>: how to write <a href="https://en.wikipedia.org/wiki/Cdb_%28software%29">cdb</a> files </li> <li> <a href="direntry.html">skalibs/direntry.h</a>: portable directory operations </li> <li> <a href="djbtime.html">skalibs/djbtime.h</a>: conversions between date and time formats </li> diff --git a/doc/upgrade.html b/doc/upgrade.html index fec512e..17b4ecf 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -16,6 +16,18 @@ <a href="//skarnet.org/">skarnet.org</a> </p> +<h2> in 2.11.0.0 </h2> + +<ul> + <li> <tt>libbiguint</tt> removed. </li> + <li> New <tt>skalibs/posixplz.h</tt> function: munmap_void()</tt>. </li> + <li> <tt>skalibs/cdb_make.h</tt> renamed to <tt>skalibs/cdbmake.h</tt>; + <tt>cdbmake</tt> functions now return 1 on success and 0 on failure. </li> + <li> <tt>skalibs/cdb.h</tt> redesigned to remove reader state from the + cdb structure itself. </li> + <li> The unsafe <tt>cdb_successor()</tt> API has been removed. +</ul> + <h2> in 2.10.0.3 </h2> <ul> diff --git a/package/deps.mak b/package/deps.mak index 83425c4..66ec52f 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -16,7 +16,7 @@ src/include/skalibs/buffer.h: src/include/skalibs/allreadwrite.h src/include/ska src/include/skalibs/bytestr.h: src/include/skalibs/gccattributes.h src/include/skalibs/cbuffer.h: src/include/skalibs/gccattributes.h src/include/skalibs/cdb.h: src/include/skalibs/gccattributes.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/cdbmake.h: src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/datastruct.h: src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/avltreen.h src/include/skalibs/bigkv.h src/include/skalibs/genqdyn.h src/include/skalibs/genset.h src/include/skalibs/gensetdyn.h src/include/skalibs/djbtime.h: src/include/skalibs/tai.h src/include/skalibs/uint64.h src/include/skalibs/djbunix.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h @@ -48,7 +48,7 @@ src/include/skalibs/skalibs.h: src/include/skalibs/biguint.h src/include/skalibs src/include/skalibs/skamisc.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/socket.h: src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h src/include/skalibs/tai.h src/include/skalibs/stdcrypto.h: src/include/skalibs/md5.h src/include/skalibs/rc4.h src/include/skalibs/sha1.h src/include/skalibs/sha256.h src/include/skalibs/sha512.h -src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/exec.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h +src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdbmake.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/exec.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint64.h @@ -66,38 +66,11 @@ src/libstdcrypto/md5-internal.h: src/include/skalibs/md5.h src/libstdcrypto/sha1-internal.h: src/include/skalibs/sha1.h src/libstdcrypto/sha256-internal.h: src/include/skalibs/sha256.h src/libstdcrypto/sha512-internal.h: src/include/skalibs/sha512.h +src/libstddjb/cdb-internal.h: src/include/skalibs/cdb.h src/include/skalibs/gccattributes.h src/libstddjb/djbtime-internal.h: src/include/skalibs/uint64.h src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/selfpipe-internal.h: src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libunixonacid/skaclient-internal.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h -src/libbiguint/bu_addc.o src/libbiguint/bu_addc.lo: src/libbiguint/bu_addc.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h -src/libbiguint/bu_addmod.o src/libbiguint/bu_addmod.lo: src/libbiguint/bu_addmod.c src/include/skalibs/biguint.h -src/libbiguint/bu_cmp.o src/libbiguint/bu_cmp.lo: src/libbiguint/bu_cmp.c src/include/skalibs/biguint.h -src/libbiguint/bu_copy.o src/libbiguint/bu_copy.lo: src/libbiguint/bu_copy.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h -src/libbiguint/bu_copy_internal.o src/libbiguint/bu_copy_internal.lo: src/libbiguint/bu_copy_internal.c src/include/skalibs/biguint.h -src/libbiguint/bu_div.o src/libbiguint/bu_div.lo: src/libbiguint/bu_div.c src/include/skalibs/biguint.h -src/libbiguint/bu_div_internal.o src/libbiguint/bu_div_internal.lo: src/libbiguint/bu_div_internal.c src/include/skalibs/biguint.h -src/libbiguint/bu_divmod.o src/libbiguint/bu_divmod.lo: src/libbiguint/bu_divmod.c src/include/skalibs/biguint.h -src/libbiguint/bu_divmod_internal.o src/libbiguint/bu_divmod_internal.lo: src/libbiguint/bu_divmod_internal.c src/include/skalibs/biguint.h -src/libbiguint/bu_fmt.o src/libbiguint/bu_fmt.lo: src/libbiguint/bu_fmt.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_gcd.o src/libbiguint/bu_gcd.lo: src/libbiguint/bu_gcd.c src/include/skalibs/biguint.h -src/libbiguint/bu_invmod.o src/libbiguint/bu_invmod.lo: src/libbiguint/bu_invmod.c src/include/skalibs/biguint.h -src/libbiguint/bu_len.o src/libbiguint/bu_len.lo: src/libbiguint/bu_len.c src/include/skalibs/biguint.h -src/libbiguint/bu_mod.o src/libbiguint/bu_mod.lo: src/libbiguint/bu_mod.c src/include/skalibs/biguint.h -src/libbiguint/bu_mul.o src/libbiguint/bu_mul.lo: src/libbiguint/bu_mul.c src/include/skalibs/biguint.h src/include/skalibs/uint64.h -src/libbiguint/bu_mulmod.o src/libbiguint/bu_mulmod.lo: src/libbiguint/bu_mulmod.c src/include/skalibs/biguint.h -src/libbiguint/bu_pack.o src/libbiguint/bu_pack.lo: src/libbiguint/bu_pack.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_pack_big.o src/libbiguint/bu_pack_big.lo: src/libbiguint/bu_pack_big.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_scan.o src/libbiguint/bu_scan.lo: src/libbiguint/bu_scan.c src/include/skalibs/biguint.h src/include/skalibs/bitarray.h src/include/skalibs/bsdsnowflake.h -src/libbiguint/bu_scan_internal.o src/libbiguint/bu_scan_internal.lo: src/libbiguint/bu_scan_internal.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_scanlen.o src/libbiguint/bu_scanlen.lo: src/libbiguint/bu_scanlen.c src/include/skalibs/biguint.h src/include/skalibs/fmtscan.h -src/libbiguint/bu_slbc.o src/libbiguint/bu_slbc.lo: src/libbiguint/bu_slbc.c src/include/skalibs/biguint.h -src/libbiguint/bu_srbc.o src/libbiguint/bu_srbc.lo: src/libbiguint/bu_srbc.c src/include/skalibs/biguint.h -src/libbiguint/bu_subc.o src/libbiguint/bu_subc.lo: src/libbiguint/bu_subc.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h -src/libbiguint/bu_submod.o src/libbiguint/bu_submod.lo: src/libbiguint/bu_submod.c src/include/skalibs/biguint.h -src/libbiguint/bu_unpack.o src/libbiguint/bu_unpack.lo: src/libbiguint/bu_unpack.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_unpack_big.o src/libbiguint/bu_unpack_big.lo: src/libbiguint/bu_unpack_big.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h -src/libbiguint/bu_zero.o src/libbiguint/bu_zero.lo: src/libbiguint/bu_zero.c src/include/skalibs/biguint.h src/libdatastruct/avlnode_delete.o src/libdatastruct/avlnode_delete.lo: src/libdatastruct/avlnode_delete.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_doublerotate.o src/libdatastruct/avlnode_doublerotate.lo: src/libdatastruct/avlnode_doublerotate.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_extreme.o src/libdatastruct/avlnode_extreme.lo: src/libdatastruct/avlnode_extreme.c src/include/skalibs/avlnode.h @@ -192,6 +165,7 @@ src/libposixplz/mklinktemp.o src/libposixplz/mklinktemp.lo: src/libposixplz/mkli src/libposixplz/mkltemp.o src/libposixplz/mkltemp.lo: src/libposixplz/mkltemp.c src/include/skalibs/posixplz.h src/libposixplz/mkptemp.o src/libposixplz/mkptemp.lo: src/libposixplz/mkptemp.c src/include/skalibs/posixplz.h src/libposixplz/mkptemp2.o src/libposixplz/mkptemp2.lo: src/libposixplz/mkptemp2.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libposixplz/munmap_void.o src/libposixplz/munmap_void.lo: src/libposixplz/munmap_void.c src/include/skalibs/posixplz.h src/libposixplz/setgroups.o src/libposixplz/setgroups.lo: src/libposixplz/setgroups.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/setgroups.h src/include/skalibs/sysdeps.h src/libposixplz/strnlen.o src/libposixplz/strnlen.lo: src/libposixplz/strnlen.c src/include/skalibs/bytestr.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h src/libposixplz/touch.o src/libposixplz/touch.lo: src/libposixplz/touch.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixplz.h src/include/skalibs/sysdeps.h @@ -317,16 +291,15 @@ src/libstddjb/cbuffer_unget.o src/libstddjb/cbuffer_unget.lo: src/libstddjb/cbuf src/libstddjb/cbuffer_unput.o src/libstddjb/cbuffer_unput.lo: src/libstddjb/cbuffer_unput.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_wpeek.o src/libstddjb/cbuffer_wpeek.lo: src/libstddjb/cbuffer_wpeek.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_wseek.o src/libstddjb/cbuffer_wseek.lo: src/libstddjb/cbuffer_wseek.c src/include/skalibs/cbuffer.h -src/libstddjb/cdb_findnext.o src/libstddjb/cdb_findnext.lo: src/libstddjb/cdb_findnext.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h -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/libstddjb/cdb_init.o src/libstddjb/cdb_init.lo: src/libstddjb/cdb_init.c src/include/skalibs/bsdsnowflake.h 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/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/cdb.h src/include/skalibs/posixishard.h -src/libstddjb/cdb_successor.o src/libstddjb/cdb_successor.lo: src/libstddjb/cdb_successor.c src/include/skalibs/cdb.h +src/libstddjb/cdb_find.o src/libstddjb/cdb_find.lo: src/libstddjb/cdb_find.c src/libstddjb/cdb-internal.h src/include/skalibs/cdb.h src/include/skalibs/uint32.h +src/libstddjb/cdb_free.o src/libstddjb/cdb_free.lo: src/libstddjb/cdb_free.c src/include/skalibs/cdb.h src/include/skalibs/posixplz.h +src/libstddjb/cdb_hash.o src/libstddjb/cdb_hash.lo: src/libstddjb/cdb_hash.c src/libstddjb/cdb-internal.h +src/libstddjb/cdb_init.o src/libstddjb/cdb_init.lo: src/libstddjb/cdb_init.c src/include/skalibs/cdb.h src/include/skalibs/djbunix.h +src/libstddjb/cdb_p.o src/libstddjb/cdb_p.lo: src/libstddjb/cdb_p.c src/libstddjb/cdb-internal.h src/include/skalibs/cdb.h +src/libstddjb/cdb_reader_zero.o src/libstddjb/cdb_reader_zero.lo: src/libstddjb/cdb_reader_zero.c src/include/skalibs/cdb.h +src/libstddjb/cdb_traverse_next.o src/libstddjb/cdb_traverse_next.lo: src/libstddjb/cdb_traverse_next.c src/libstddjb/cdb-internal.h src/include/skalibs/cdb.h src/include/skalibs/uint32.h src/libstddjb/cdb_zero.o src/libstddjb/cdb_zero.lo: src/libstddjb/cdb_zero.c src/include/skalibs/cdb.h +src/libstddjb/cdbmake.o src/libstddjb/cdbmake.lo: src/libstddjb/cdbmake.c src/include/skalibs/buffer.h src/include/skalibs/cdbmake.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h src/libstddjb/child_spawn.o src/libstddjb/child_spawn.lo: src/libstddjb/child_spawn.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/libstddjb/child_spawn1_internal.o src/libstddjb/child_spawn1_internal.lo: src/libstddjb/child_spawn1_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h diff --git a/package/info b/package/info index 6eb3a23..2d62d00 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=skalibs -version=2.10.0.3 +version=2.11.0.0 category=prog package_macro_name=SKALIBS diff --git a/src/include/skalibs/cdb.h b/src/include/skalibs/cdb.h index 20d3903..9b05b22 100644 --- a/src/include/skalibs/cdb.h +++ b/src/include/skalibs/cdb.h @@ -1,50 +1,48 @@ /* ISC license. */ -#ifndef CDB_H -#define CDB_H +#ifndef SKALIBS_CDB_H +#define SKALIBS_CDB_H #include <stdint.h> -#include <skalibs/gccattributes.h> -#define CDB_HASHSTART 5381 -extern uint32_t cdb_hashadd (uint32_t, unsigned char) gccattr_const ; -extern uint32_t cdb_hash (char const *, unsigned int) gccattr_pure ; +#include <skalibs/gccattributes.h> -typedef struct cdb cdb_t, *cdb_t_ref ; -struct cdb +typedef struct cdb_s cdb, *cdb_ref ; +struct cdb_s { - char *map ; - uint32_t size ; /* initialized if map is nonzero */ - uint32_t loop ; /* number of hash slots searched under this key */ - uint32_t khash ; /* initialized if loop is nonzero */ - uint32_t kpos ; /* initialized if loop is nonzero */ - uint32_t hpos ; /* initialized if loop is nonzero */ - uint32_t hslots ; /* initialized if loop is nonzero */ - uint32_t dpos ; /* initialized if cdb_findnext() returns 1 */ - uint32_t dlen ; /* initialized if cdb_findnext() returns 1 */ + char const *map ; + uint32_t size ; } ; +#define CDB_ZERO { .map = 0, .size = 0 } +extern cdb const cdb_zero ; -#define CDB_ZERO { .map = 0, .size = 0, .loop = 0, .khash = 0, .kpos = 0, .hpos = 0, .hslots = 0, .dpos = 0, .dlen = 0 } -extern struct cdb const cdb_zero ; +typedef struct cdb_reader_s cdb_reader, *cdb_reader_ref ; +struct cdb_reader_s +{ + uint32_t loop ; + uint32_t khash ; + uint32_t kpos ; + uint32_t hpos ; + uint32_t hslots ; +} ; +#define CDB_READER_ZERO { .loop = 0, .khash = 0, .kpos = 0, .hpos = 0, .hslots = 0 } +extern cdb_reader const cdb_reader_zero ; -extern void cdb_free (struct cdb *) ; +typedef struct cdb_data_s cdb_data, *cdb_data_ref ; +struct cdb_data_s +{ + char const *s ; + uint32_t len ; +} ; -#define cdb_init_map(c, fd, domap) (!cdb_init(c, fd)) -extern int cdb_init (struct cdb *, int fd) ; -extern int cdb_mapfile (struct cdb *, char const *) ; -extern int cdb_read (struct cdb *, char *, unsigned int, uint32_t) ; -#define cdb_findstart(c) ((c)->loop = 0) -extern int cdb_findnext (struct cdb *, char const *, unsigned int) ; -#define cdb_find(c, s, len) (cdb_findstart(c), cdb_findnext(c, s, len)) +extern void cdb_free (cdb *) ; +extern int cdb_init (cdb *, char const *) ; -#define cdb_datapos(c) ((c)->dpos) -#define cdb_datalen(c) ((c)->dlen) -#define cdb_keypos(c) ((c)->kpos) -#define cdb_keylen(c) ((c)->dpos - (c)->kpos) +#define cdb_findstart(d) ((d)->loop = 0) +extern int cdb_find (cdb const *, cdb_reader *, cdb_data *, char const *, uint32_t) ; -#define cdb_traverse_init(c, kpos) (*(kpos) = 2048) -#define cdb_firstkey(c, kpos) (cdb_traverse_init(c, kpos), cdb_nextkey(c, kpos)) -extern int cdb_nextkey (struct cdb *, uint32_t *) ; -extern int cdb_successor (struct cdb *, char const *, unsigned int) ; +#define CDB_TRAVERSE_INIT() 2048 +#define cdb_traverse_init(pos) (*pos = 2048) +extern int cdb_traverse_next (cdb const *, cdb_data *, cdb_data *, uint32_t *) ; #endif diff --git a/src/include/skalibs/cdb_make.h b/src/include/skalibs/cdb_make.h deleted file mode 100644 index 69e1c68..0000000 --- a/src/include/skalibs/cdb_make.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ISC license. */ - -#ifndef CDB_MAKE_H -#define CDB_MAKE_H - -#include <stdint.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 -{ - genalloc hplist ; /* array of diuint32 */ - uint32_t pos ; - buffer b ; - char buf[BUFFER_OUTSIZE] ; -} ; - -#define CDB_MAKE_ZERO { .hplist = GENALLOC_ZERO, .pos = 2048, .b = BUFFER_INIT(&fd_writev, -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) ; -extern int cdb_make_finish (struct cdb_make *) ; - -#endif diff --git a/src/include/skalibs/cdbmake.h b/src/include/skalibs/cdbmake.h new file mode 100644 index 0000000..bf03ad6 --- /dev/null +++ b/src/include/skalibs/cdbmake.h @@ -0,0 +1,27 @@ +/* ISC license. */ + +#ifndef SKALIBS_CDBMAKE_H +#define SKALIBS_CDBMAKE_H + +#include <stdint.h> +#include <skalibs/diuint32.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/genalloc.h> +#include <skalibs/buffer.h> + +typedef struct cdbmaker_s cdbmaker, *cdbmaker_ref ; +struct cdbmaker_s +{ + genalloc hplist ; /* array of diuint32 */ + uint32_t pos ; + buffer b ; + char buf[BUFFER_OUTSIZE] ; +} ; + +#define CDBMAKER_ZERO { .hplist = GENALLOC_ZERO, .pos = 2048, .b = BUFFER_INIT(&fd_writev, -1, 0, 0) } + +extern int cdbmake_start (cdbmaker *, int) ; +extern int cdbmake_add (cdbmaker *, char const *, unsigned int, char const *, unsigned int) ; +extern int cdbmake_finish (cdbmaker *) ; + +#endif diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h index 55e03fc..2c972c8 100644 --- a/src/include/skalibs/posixplz.h +++ b/src/include/skalibs/posixplz.h @@ -34,6 +34,7 @@ extern int getpeereid (int, uid_t *, gid_t *) ; extern void execvep (char const *, char const *const *, char const *const *, char const *) ; extern void execvep_loose (char const *, char const *const *, char const *const *, char const *) ; extern void unlink_void (char const *) ; +extern void munmap_void (void *, size_t) ; extern pid_t doublefork (void) ; extern int touch (char const *) ; diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h index b15bff3..b2b1d32 100644 --- a/src/include/skalibs/stddjb.h +++ b/src/include/skalibs/stddjb.h @@ -19,7 +19,7 @@ #include <skalibs/bytestr.h> #include <skalibs/cbuffer.h> #include <skalibs/cdb.h> -#include <skalibs/cdb_make.h> +#include <skalibs/cdbmake.h> #include <skalibs/direntry.h> #include <skalibs/diuint32.h> #include <skalibs/diuint.h> diff --git a/src/libbiguint/bu_addc.c b/src/libbiguint/bu_addc.c deleted file mode 100644 index b6d1ccb..0000000 --- a/src/libbiguint/bu_addc.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_addc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) -{ - unsigned int i = 0 ; - for (; i < cn ; i++) - { - uint32_t ai = (i < an) ? a[i] : 0 ; - uint32_t bi = (i < bn) ? b[i] : 0 ; - uint32_t ci = ai + bi + carry ; - carry = (carry || bi) && (ci < ai) ; - c[i] = ci ; - } - return carry ? (errno = EOVERFLOW, 0) : 1 ; -} diff --git a/src/libbiguint/bu_addmod.c b/src/libbiguint/bu_addmod.c deleted file mode 100644 index 4ebe2f7..0000000 --- a/src/libbiguint/bu_addmod.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_addmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - if (!bu_add(c, cn, a, an, b, bn)) return 0 ; - if (bu_cmp(c, cn, m, mn) >= 0) bu_sub(c, cn, c, cn, m, mn) ; - return 1 ; -} diff --git a/src/libbiguint/bu_cmp.c b/src/libbiguint/bu_cmp.c deleted file mode 100644 index 0c87e92..0000000 --- a/src/libbiguint/bu_cmp.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_cmp (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - an = bu_len(a, an) ; - bn = bu_len(b, bn) ; - if (an < bn) return -1 ; - if (an > bn) return 1 ; - while (bn--) - { - if (a[bn] < b[bn]) return -1 ; - if (a[bn] > b[bn]) return 1 ; - } - return 0 ; -} diff --git a/src/libbiguint/bu_copy.c b/src/libbiguint/bu_copy.c deleted file mode 100644 index 0c64417..0000000 --- a/src/libbiguint/bu_copy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_copy (uint32_t *b, unsigned int bn, uint32_t const *a, unsigned int an) -{ - unsigned int alen = bu_len(a, an) ; - if (bn < alen) - { - bu_copy_internal(b, a, bn) ; - return (errno = EOVERFLOW, 0) ; - } - bu_copy_internal(b, a, alen) ; - bu_zero(b + alen, bn - alen) ; - return 1 ; -} diff --git a/src/libbiguint/bu_copy_internal.c b/src/libbiguint/bu_copy_internal.c deleted file mode 100644 index 8de4d5e..0000000 --- a/src/libbiguint/bu_copy_internal.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -void bu_copy_internal (uint32_t *b, uint32_t const *a, unsigned int n) -{ - while (n--) b[n] = a[n] ; -} diff --git a/src/libbiguint/bu_div.c b/src/libbiguint/bu_div.c deleted file mode 100644 index a5b6986..0000000 --- a/src/libbiguint/bu_div.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_div (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn, uint32_t *r, unsigned int rn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - if (!blen) return (errno = EDOM, 0) ; - else - { - uint32_t qq[alen] ; - uint32_t rr[alen] ; - int qh, rh ; - bu_copy_internal(rr, a, alen) ; - bu_div_internal(rr, alen, b, blen, qq, alen) ; - qh = bu_copy(q, qn, qq, alen) ; - rh = bu_copy(r, rn, rr, alen) ; - return qh && rh ; - } -} diff --git a/src/libbiguint/bu_div_internal.c b/src/libbiguint/bu_div_internal.c deleted file mode 100644 index 0765a99..0000000 --- a/src/libbiguint/bu_div_internal.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* - q = a/b, a = a mod b. Assumes b != 0 and qn >= alen - blen + 1. -*/ - -void bu_div_internal (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - bu_zero(q, qn) ; - if (alen < blen) return ; - { - uint32_t bb[alen + 1] ; - unsigned int i = 1 + ((alen - blen) << 5) ; - bu_zero(bb, alen - blen) ; - bu_copy_internal(bb + alen - blen, b, blen) ; - bb[alen] = 0 ; - - while (bu_cmp(a, alen, bb, alen+1) >= 0) - { - bu_slb(bb + alen - blen, blen + 1) ; - i++ ; - } - while (i && (bu_cmp(a, alen, bb, alen+1) < 0)) - { - bu_srb(bb, alen + 1) ; - i-- ; - } - - while (i--) - { - bu_slb(q, alen - blen + 1) ; - if (bu_cmp(a, alen, bb, alen) >= 0) - { - bu_sub(a, alen, a, alen, bb, alen) ; - q[0] |= 1 ; - } - bu_srb(bb, alen) ; - } - } -} diff --git a/src/libbiguint/bu_divmod.c b/src/libbiguint/bu_divmod.c deleted file mode 100644 index 17b6b7b..0000000 --- a/src/libbiguint/bu_divmod.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -/* - q = y/x mod m. -*/ - -int bu_divmod (uint32_t *q, unsigned int qn, uint32_t const *y, unsigned int yn, uint32_t const *x, unsigned int xn, uint32_t const *m, unsigned int mn) -{ - unsigned int ylen = bu_len(y, yn) ; - unsigned int xlen = bu_len(x, xn) ; - unsigned int mlen = bu_len(m, mn) ; - unsigned int n = ylen ; - if (n < xlen) n = xlen ; - if (n < mlen) n = mlen ; - if (!n) return (errno = EDOM, 0) ; - { - uint32_t yy[n] ; - uint32_t xx[n] ; - uint32_t mm[n] ; - bu_gcd(xx, n, x, xlen, m, mlen) ; - if ((xx[0] != 1) || (bu_len(xx, n) != 1)) return (errno = EDOM, 0) ; - bu_copy_internal(yy, y, ylen) ; bu_zero(yy+ylen, n-ylen) ; - bu_copy_internal(xx, x, xlen) ; bu_zero(xx+xlen, n-xlen) ; - bu_copy_internal(mm, m, mlen) ; bu_zero(mm+mlen, n-mlen) ; - bu_divmod_internal(yy, xx, mm, n) ; - return bu_copy(q, qn, yy, n) ; - } -} diff --git a/src/libbiguint/bu_divmod_internal.c b/src/libbiguint/bu_divmod_internal.c deleted file mode 100644 index afb8ccc..0000000 --- a/src/libbiguint/bu_divmod_internal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* - u = u/a mod m. a and m must be relatively prime - otherwise, infinite loop. - a is not immutable. - Original idea by Sheueling Chang Shantz of Sun Research. -*/ - -void bu_divmod_internal (uint32_t *u, uint32_t *a, uint32_t const *m, unsigned int n) -{ - uint32_t bb[n] ; uint32_t *b = bb ; - uint32_t vv[n] ; uint32_t *v = vv ; - bu_copy_internal(b, m, n) ; - bu_zero(v, n) ; - - /*** XXX: this iterates like mad, should probably be optimized more */ - for (;;) - { - while (!(a[0] & 1)) - { - bu_srb(a, n) ; - if (u[0] & 1) bu_add(u, n, u, n, m, n) ; - bu_srb(u, n) ; - } - if ((a[0] == 1) && (bu_len(a, n) == 1)) break ; - if (bu_cmp(a, n, b, n) < 0) - { - uint32_t *t = a ; a = b ; b = t ; - t = u ; u = v ; v = t ; - } - bu_add(a, n, a, n, b, n) ; - bu_add(u, n, u, n, v, n) ; - } -} diff --git a/src/libbiguint/bu_fmt.c b/src/libbiguint/bu_fmt.c deleted file mode 100644 index 9402621..0000000 --- a/src/libbiguint/bu_fmt.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -size_t bu_fmt (char *s, uint32_t const *x, unsigned int n) -{ - size_t len = 0 ; - while (n--) - { - char fmt[8] ; - size_t i = uint32_xfmt(fmt, x[n]) ; - memcpy(s+len, "00000000", 8-i) ; - memcpy(s+len+8-i, fmt, i) ; - len += 8 ; - } - return len ; -} diff --git a/src/libbiguint/bu_gcd.c b/src/libbiguint/bu_gcd.c deleted file mode 100644 index 738091e..0000000 --- a/src/libbiguint/bu_gcd.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_gcd (uint32_t *r, unsigned int rn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - if (bu_cmp(a, an, b, bn) < 0) - { - uint32_t const *t = a ; - unsigned int tn = an ; - a = b ; an = bn ; - b = t ; bn = tn ; - } - { - uint32_t trash[an] ; - uint32_t aa[an] ; - uint32_t bb[an] ; - uint32_t *aaa = aa, *bbb = bb ; - bu_copy_internal(aa, a, an) ; - bu_copy_internal(bb, b, bn) ; - bu_zero(bb+bn, an-bn) ; - - while (bu_len(bbb, an)) - { - uint32_t *ttt = aaa ; - bu_div_internal(aaa, an, bbb, an, trash, an) ; - aaa = bbb ; - bbb = ttt ; - } - return bu_copy(r, rn, aaa, an) ; - } -} diff --git a/src/libbiguint/bu_invmod.c b/src/libbiguint/bu_invmod.c deleted file mode 100644 index f9ae9e2..0000000 --- a/src/libbiguint/bu_invmod.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* x^-1 mod m. */ - -int bu_invmod (uint32_t *x, unsigned int xn, uint32_t const *m, unsigned int mn) -{ - uint32_t const one = 1 ; - return bu_divmod(x, xn, &one, 1, x, xn, m, mn) ; -} diff --git a/src/libbiguint/bu_len.c b/src/libbiguint/bu_len.c deleted file mode 100644 index 6e66b17..0000000 --- a/src/libbiguint/bu_len.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -unsigned int bu_len (uint32_t const *a, unsigned int n) -{ - while (n--) if (a[n]) return n+1 ; - return 0 ; -} diff --git a/src/libbiguint/bu_mod.c b/src/libbiguint/bu_mod.c deleted file mode 100644 index ca16af0..0000000 --- a/src/libbiguint/bu_mod.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_mod (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - uint32_t q[an] ; - return bu_div(a, an, b, bn, q, an, a, an) ; -} diff --git a/src/libbiguint/bu_mul.c b/src/libbiguint/bu_mul.c deleted file mode 100644 index 16043fd..0000000 --- a/src/libbiguint/bu_mul.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <skalibs/uint64.h> -#include <skalibs/biguint.h> - - /* No Karatsuba. Keep it simple, stupid. */ - -int bu_mul (uint32_t *x, unsigned int xn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - uint32_t c[alen + blen] ; - unsigned int i = 0 ; - bu_zero(c, alen + blen) ; - for (; i < alen ; i++) - { - uint32_t carry = 0 ; - unsigned int j = 0 ; - for (; j < blen ; j++) - { - uint64_t t = a[i] ; - t *= b[j] ; - t += c[i+j] ; - t += carry ; - c[i+j] = (uint32_t)t ; - carry = (uint32_t)(t >> 32) ; - } - c[i+j] += carry ; - } - return bu_copy(x, xn, c, alen+blen) ; -} diff --git a/src/libbiguint/bu_mulmod.c b/src/libbiguint/bu_mulmod.c deleted file mode 100644 index 59ed3fc..0000000 --- a/src/libbiguint/bu_mulmod.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - - /* Nope, no Montgomery either. */ - -int bu_mulmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - uint32_t x[alen+blen] ; - if (!bu_mul(x, alen+blen, a, alen, b, blen)) return 0 ; - if (!bu_mod(x, alen+blen, m, mn)) return 0 ; - return bu_copy(c, cn, x, mn) ; -} diff --git a/src/libbiguint/bu_pack.c b/src/libbiguint/bu_pack.c deleted file mode 100644 index b43ab04..0000000 --- a/src/libbiguint/bu_pack.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_pack (char *s, uint32_t const *a, unsigned int n) -{ - while (n--) uint32_pack(s + (n<<2), a[n]) ; -} diff --git a/src/libbiguint/bu_pack_big.c b/src/libbiguint/bu_pack_big.c deleted file mode 100644 index caca082..0000000 --- a/src/libbiguint/bu_pack_big.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_pack_big (char *s, uint32_t const *a, unsigned int n) -{ - unsigned int i = 0 ; - for (; i < n ; i++) uint32_pack_big(s + (i<<2), a[n-1-i]) ; -} diff --git a/src/libbiguint/bu_scan.c b/src/libbiguint/bu_scan.c deleted file mode 100644 index 8d4ecd0..0000000 --- a/src/libbiguint/bu_scan.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/bitarray.h> -#include <skalibs/biguint.h> - -int bu_scan (char const *s, size_t len, uint32_t *x, unsigned int xn, size_t zeron) -{ - size_t n = bitarray_div8(zeron) ; - if (xn < n) return (errno = EOVERFLOW, 0) ; - bu_scan_internal(s, len, x) ; - bu_zero(x + n, xn - n) ; - return 1 ; -} diff --git a/src/libbiguint/bu_scan_internal.c b/src/libbiguint/bu_scan_internal.c deleted file mode 100644 index d7a75b6..0000000 --- a/src/libbiguint/bu_scan_internal.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_scan_internal (char const *s, size_t len, uint32_t *x) -{ - char fmt[9] = "\0\0\0\0\0\0\0\0" ; - size_t i = 0 ; - if (len & 7) - { - memcpy(fmt, s, len & 7) ; - uint32_xscan(fmt, x + (len >> 3)) ; - } - for (; i < (len >> 3) ; i++) - { - memcpy(fmt, s + len - 8 - (i << 3), 8) ; - uint32_xscan(fmt, x + i) ; - } -} diff --git a/src/libbiguint/bu_scanlen.c b/src/libbiguint/bu_scanlen.c deleted file mode 100644 index ed93fa3..0000000 --- a/src/libbiguint/bu_scanlen.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <skalibs/fmtscan.h> -#include <skalibs/biguint.h> - -size_t bu_scanlen (char const *s, size_t *zeron) -{ - size_t n = ucharn_findlen(s) ; - *zeron = n ; - while (*s == '0') { s++ ; (*zeron)-- ; } - return n ; -} diff --git a/src/libbiguint/bu_slbc.c b/src/libbiguint/bu_slbc.c deleted file mode 100644 index 13d9b6d..0000000 --- a/src/libbiguint/bu_slbc.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_slbc (uint32_t *a, unsigned int n, int carry) -{ - unsigned int i = 0 ; - carry = !!carry ; - for (; i < n ; i++) - { - int c = a[i] >> 31 ; - a[i] = (a[i] << 1) | carry ; - carry = c ; - } - return carry ; -} diff --git a/src/libbiguint/bu_srbc.c b/src/libbiguint/bu_srbc.c deleted file mode 100644 index b23186b..0000000 --- a/src/libbiguint/bu_srbc.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_srbc (uint32_t *a, unsigned int n, int carry) -{ - while (n--) - { - int c = a[n] & 1 ; - a[n] = (a[n] >> 1) | (carry ? 0x80000000U : 0) ; - carry = c ; - } - return carry ; -} diff --git a/src/libbiguint/bu_subc.c b/src/libbiguint/bu_subc.c deleted file mode 100644 index 63147b0..0000000 --- a/src/libbiguint/bu_subc.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_subc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) -{ - unsigned int i = 0 ; - for (; i < cn ; i++) - { - uint32_t ai = (i < an) ? a[i] : 0 ; - uint32_t bi = (i < bn) ? b[i] : 0 ; - uint32_t ci = ai - bi - carry ; - carry = (carry || bi) && (ci > ai) ; - c[i] = ci ; - } - return carry ? (errno = EOVERFLOW, 0) : 1 ; -} diff --git a/src/libbiguint/bu_submod.c b/src/libbiguint/bu_submod.c deleted file mode 100644 index 98048e1..0000000 --- a/src/libbiguint/bu_submod.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_submod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - if (!bu_sub(c, cn, a, an, b, bn) && bu_add(c, cn, c, cn, m, mn)) - return (errno = EDOM, 0) ; - return 1 ; -} diff --git a/src/libbiguint/bu_unpack.c b/src/libbiguint/bu_unpack.c deleted file mode 100644 index 0c93277..0000000 --- a/src/libbiguint/bu_unpack.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_unpack (char const *s, uint32_t *a, unsigned int n) -{ - while (n--) uint32_unpack(s + (n<<2), a + n) ; -} diff --git a/src/libbiguint/bu_unpack_big.c b/src/libbiguint/bu_unpack_big.c deleted file mode 100644 index 97f37cf..0000000 --- a/src/libbiguint/bu_unpack_big.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_unpack_big (char const *s, uint32_t *a, unsigned int n) -{ - unsigned int i = 0 ; - for (; i < n ; i++) uint32_unpack_big(s + (i<<2), a + n - 1 - i) ; -} diff --git a/src/libbiguint/bu_zero.c b/src/libbiguint/bu_zero.c deleted file mode 100644 index ab87752..0000000 --- a/src/libbiguint/bu_zero.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -void bu_zero (uint32_t *z, unsigned int n) -{ - while (n--) z[n] = 0 ; -} diff --git a/src/libposixplz/munmap_void.c b/src/libposixplz/munmap_void.c new file mode 100644 index 0000000..bbc6e10 --- /dev/null +++ b/src/libposixplz/munmap_void.c @@ -0,0 +1,13 @@ +/* ISC license. */ + +#include <sys/mman.h> +#include <errno.h> + +#include <skalibs/posixplz.h> + +void munmap_void (void *addr, size_t len) +{ + int e = errno ; + munmap(addr, len) ; + errno = e ; +} diff --git a/src/libstddjb/cdb-internal.h b/src/libstddjb/cdb-internal.h new file mode 100644 index 0000000..0db5a5d --- /dev/null +++ b/src/libstddjb/cdb-internal.h @@ -0,0 +1,14 @@ +/* ISC license. */ + +#ifndef SKALIBS_CDB_INTERNAL_H +#define SKALIBS_CDB_INTERNAL_H + +#include <stdint.h> + +#include <skalibs/gccattributes.h> +#include <skalibs/cdb.h> + +extern uint32_t cdb_hash (char const *, uint32_t) gccattr_pure ; +extern char const *cdb_p (cdb const *, uint32_t, uint32_t) gccattr_pure ; + +#endif diff --git a/src/libstddjb/cdb_find.c b/src/libstddjb/cdb_find.c new file mode 100644 index 0000000..a9c66e3 --- /dev/null +++ b/src/libstddjb/cdb_find.c @@ -0,0 +1,57 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> + +#include <skalibs/uint32.h> +#include <skalibs/cdb.h> +#include "cdb-internal.h" + +int cdb_find (cdb const *c, cdb_reader *d, cdb_data *out, char const *key, uint32_t len) +{ + if (!d->loop) + { + uint32_t u = cdb_hash(key, len) ; + char const *p = cdb_p(c, 8, (u << 3) & 2047) ; + if (!p) return -1 ; + uint32_unpack(p + 4, &d->hslots) ; + if (!d->hslots) return 0 ; + uint32_unpack(p, &d->hpos) ; + d->khash = u ; + u >>= 8 ; + u %= d->hslots ; + u <<= 3 ; + d->kpos = d->hpos + u ; + } + + while (d->loop < d->hslots) + { + uint32_t pos, u ; + char const *p = cdb_p(c, 8, d->kpos) ; + if (!p) return -1 ; + uint32_unpack(p + 4, &pos) ; + if (!pos) return 0 ; + d->loop++ ; + d->kpos += 8 ; + if (d->kpos == d->hpos + (d->hslots << 3)) d->kpos = d->hpos ; + uint32_unpack(p, &u) ; + if (u == d->khash) + { + p = cdb_p(c, 8, pos) ; + if (!p) return -1 ; + uint32_unpack(p, &u) ; + if (u == len) + { + char const *k = cdb_p(c, len, pos + 8) ; + if (!k) return -1 ; + if (!memcmp(key, k, len)) + { + uint32_unpack(p + 4, &out->len) ; + out->s = c->map + pos + 8 + len ; + return 1 ; + } + } + } + } + return 0 ; +} diff --git a/src/libstddjb/cdb_findnext.c b/src/libstddjb/cdb_findnext.c deleted file mode 100644 index 536013b..0000000 --- a/src/libstddjb/cdb_findnext.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/cdb.h> - -static int match (struct cdb *c, char const *key, unsigned int len, uint32_t pos) -{ - char buf[1024] ; - while (len > 0) - { - unsigned int n = 1024 ; - if (n > len) n = len ; - if (cdb_read(c, buf, n, pos) < 0) return -1 ; - if (memcmp(buf, key, n)) return 0 ; - pos += n ; key += n ; len -= n ; - } - return 1 ; -} - -int cdb_findnext (struct cdb *c, char const *key, unsigned int len) -{ - char buf[8] ; - uint32_t pos ; - uint32_t u ; - - if (!c->loop) - { - u = cdb_hash(key, len) ; - if (cdb_read(c, buf, 8, (u << 3) & 2047) < 0) return -1 ; - uint32_unpack(buf + 4, &c->hslots) ; - if (!c->hslots) return 0 ; - uint32_unpack(buf, &c->hpos) ; - c->khash = u ; - u >>= 8 ; - u %= c->hslots ; - u <<= 3 ; - c->kpos = c->hpos + u ; - } - - while (c->loop < c->hslots) - { - if (cdb_read(c, buf, 8, c->kpos) < 0) return -1 ; - uint32_unpack(buf + 4, &pos) ; - if (!pos) return 0 ; - c->loop++ ; - c->kpos += 8 ; - if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos ; - uint32_unpack(buf, &u) ; - if (u == c->khash) - { - if (cdb_read(c, buf, 8, pos) < 0) return -1 ; - uint32_unpack(buf, &u) ; - if (u == len) - switch (match(c, key, len, pos + 8)) - { - case -1: - return -1 ; - case 1: - uint32_unpack(buf + 4, &c->dlen) ; - c->dpos = pos + 8 + len ; - return 1 ; - } - } - } - return 0 ; -} diff --git a/src/libstddjb/cdb_free.c b/src/libstddjb/cdb_free.c index d4250ec..a59e961 100644 --- a/src/libstddjb/cdb_free.c +++ b/src/libstddjb/cdb_free.c @@ -1,17 +1,13 @@ /* ISC license. */ -#include <sys/mman.h> -#include <errno.h> - +#include <skalibs/posixplz.h> #include <skalibs/cdb.h> -extern void cdb_free (struct cdb *c) +extern void cdb_free (cdb *c) { if (c->map) { - int e = errno ; - munmap(c->map, c->size) ; - errno = e ; + munmap_void((void *)c->map, c->size) ; + c->map = 0 ; } - *c = cdb_zero ; } diff --git a/src/libstddjb/cdb_hash.c b/src/libstddjb/cdb_hash.c index 82dcfbc..a7b626b 100644 --- a/src/libstddjb/cdb_hash.c +++ b/src/libstddjb/cdb_hash.c @@ -1,14 +1,18 @@ /* ISC license. */ -#include <skalibs/cdb.h> +#include <stdint.h> -uint32_t cdb_hashadd (uint32_t h, unsigned char c) +#include "cdb-internal.h" + +#define CDB_HASHSTART 5381 + +static inline uint32_t cdb_hashadd (uint32_t h, unsigned char c) { h += (h << 5) ; return h ^ c ; } -uint32_t cdb_hash (char const *buf, unsigned int len) +uint32_t cdb_hash (char const *buf, uint32_t len) { uint32_t h = CDB_HASHSTART ; while (len--) h = cdb_hashadd(h, *buf++) ; diff --git a/src/libstddjb/cdb_init.c b/src/libstddjb/cdb_init.c index 8b56c1a..7a6c2f6 100644 --- a/src/libstddjb/cdb_init.c +++ b/src/libstddjb/cdb_init.c @@ -1,23 +1,31 @@ /* ISC license. */ -#include <skalibs/bsdsnowflake.h> - #include <sys/stat.h> #include <sys/mman.h> #include <stdint.h> #include <errno.h> +#include <skalibs/djbunix.h> #include <skalibs/cdb.h> -int cdb_init (struct cdb *c, int fd) +int cdb_init (cdb *c, char const *file) { - struct stat st ; char *map ; - if (fstat(fd, &st) < 0) return -1 ; - if (st.st_size > UINT32_MAX) return (errno = EOVERFLOW, -1) ; + struct stat st ; + int fd = openc_read(file) ; + if (fd < 0) return 0 ; + if (fstat(fd, &st) < 0) goto err ; + if (st.st_size > UINT32_MAX) goto eoverf ; map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0) ; - if (map == MAP_FAILED) return -1 ; + if (map == MAP_FAILED) goto err ; c->map = map ; c->size = st.st_size ; + fd_close(fd) ; + return 1 ; + + eoverf: + errno = EOVERFLOW ; + err: + fd_close(fd) ; return 0 ; } diff --git a/src/libstddjb/cdb_mapfile.c b/src/libstddjb/cdb_mapfile.c deleted file mode 100644 index b31f1e6..0000000 --- a/src/libstddjb/cdb_mapfile.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <skalibs/djbunix.h> -#include <skalibs/cdb.h> - -int cdb_mapfile (struct cdb *c, char const *file) -{ - int fd = openc_read(file) ; - if (fd < 0) return 0 ; - if (cdb_init(c, fd) == -1) - { - fd_close(fd) ; - return 0 ; - } - fd_close(fd) ; - return 1 ; -} diff --git a/src/libstddjb/cdb_nextkey.c b/src/libstddjb/cdb_nextkey.c deleted file mode 100644 index 6de3b24..0000000 --- a/src/libstddjb/cdb_nextkey.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/cdb.h> - -int cdb_nextkey (struct cdb *c, uint32_t *kpos) -{ - char buf[8] ; - uint32_t eod, klen ; - if (cdb_read(c, buf, 4, 0) < 0) return -1 ; - uint32_unpack(buf, &eod) ; - if (eod < 8 || eod - 8 < *kpos) return 0 ; - c->kpos = *kpos + 8 ; - if (c->kpos < *kpos) return -1 ; /* wraparound */ - cdb_findstart(c) ; - c->hslots = 1 ; - if (cdb_read(c, buf, 8, *kpos) < 0) return -1 ; - uint32_unpack(buf, &klen) ; - uint32_unpack(buf + 4, &c->dlen) ; - c->dpos = c->kpos + klen ; - *kpos += 8 + klen + c->dlen ; - return 1 ; -} diff --git a/src/libstddjb/cdb_p.c b/src/libstddjb/cdb_p.c new file mode 100644 index 0000000..9e46292 --- /dev/null +++ b/src/libstddjb/cdb_p.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include <skalibs/cdb.h> +#include "cdb-internal.h" + +char const *cdb_p (cdb const *c, uint32_t len, uint32_t pos) +{ + return pos <= c->size && len <= c->size - pos ? c->map + pos : 0 ; +} diff --git a/src/libstddjb/cdb_read.c b/src/libstddjb/cdb_read.c deleted file mode 100644 index 1fb15da..0000000 --- a/src/libstddjb/cdb_read.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> - -#include <skalibs/cdb.h> -#include <skalibs/posixishard.h> - -int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32_t pos) -{ - if ((pos > c->size) || (c->size - pos < len)) return (errno = EPROTO, -1) ; - memcpy(buf, c->map + pos, len) ; - return 0 ; -} diff --git a/src/libstddjb/cdb_reader_zero.c b/src/libstddjb/cdb_reader_zero.c new file mode 100644 index 0000000..1dbb275 --- /dev/null +++ b/src/libstddjb/cdb_reader_zero.c @@ -0,0 +1,5 @@ +/* ISC license. */ + +#include <skalibs/cdb.h> + +cdb_reader const cdb_reader_zero = CDB_READER_ZERO ; diff --git a/src/libstddjb/cdb_successor.c b/src/libstddjb/cdb_successor.c deleted file mode 100644 index 51956bf..0000000 --- a/src/libstddjb/cdb_successor.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <skalibs/cdb.h> - -int cdb_successor (struct cdb *c, char const *key, unsigned int klen) -{ - uint32_t kpos ; - if (key) - { - int r = cdb_find(c, key, klen) ; - if (r < 1) return r ; - kpos = c->dpos + c->dlen ; - } - else cdb_traverse_init(c, &kpos) ; - return cdb_nextkey(c, &kpos) ; -} diff --git a/src/libstddjb/cdb_traverse_next.c b/src/libstddjb/cdb_traverse_next.c new file mode 100644 index 0000000..887574b --- /dev/null +++ b/src/libstddjb/cdb_traverse_next.c @@ -0,0 +1,25 @@ +/* ISC license. */ + +#include <stdint.h> + +#include <skalibs/uint32.h> +#include <skalibs/cdb.h> +#include "cdb-internal.h" + +int cdb_traverse_next (cdb const *c, cdb_data *key, cdb_data *data, uint32_t *pos) +{ + uint32_t eod ; + char const *p = cdb_p(c, 4, 0) ; + if (!p) return -1 ; + uint32_unpack(p, &eod) ; + if (eod < 8 || eod - 8 < *pos) return 0 ; + if (*pos + 8 < *pos) return -1 ; + p = cdb_p(c, 8, *pos) ; + if (!p) return -1 ; + uint32_unpack(p, &key->len) ; + uint32_unpack(p + 4, &data->len) ; + key->s = c->map + *pos + 8 ; + data->s = key->s + key->len ; + *pos += 8 + key->len + data->len ; + return 1 ; +} diff --git a/src/libstddjb/cdb_zero.c b/src/libstddjb/cdb_zero.c index ce70444..164a192 100644 --- a/src/libstddjb/cdb_zero.c +++ b/src/libstddjb/cdb_zero.c @@ -2,4 +2,4 @@ #include <skalibs/cdb.h> -struct cdb const cdb_zero = CDB_ZERO ; +cdb const cdb_zero = CDB_ZERO ; diff --git a/src/libstddjb/cdb_make.c b/src/libstddjb/cdbmake.c index 53e64b1..4cc4fc8 100644 --- a/src/libstddjb/cdb_make.c +++ b/src/libstddjb/cdbmake.c @@ -3,23 +3,23 @@ #include <unistd.h> #include <stdint.h> #include <errno.h> + #include <skalibs/uint32.h> #include <skalibs/diuint32.h> #include <skalibs/buffer.h> #include <skalibs/genalloc.h> -#include <skalibs/cdb.h> -#include <skalibs/cdb_make.h> +#include <skalibs/cdbmake.h> +#include "cdb-internal.h" -int cdb_make_start (struct cdb_make *c, int fd) +int cdbmake_start (cdbmaker *c, int fd) { c->hplist = genalloc_zero ; c->pos = 2048 ; buffer_init(&c->b, &buffer_write, fd, c->buf, BUFFER_OUTSIZE) ; - if (lseek(fd, c->pos, SEEK_SET) < 0) return -1 ; - return 0 ; + return lseek(fd, c->pos, SEEK_SET) >= 0 ; } -static int posplus (struct cdb_make *c, uint32_t len) +static int posplus (cdbmaker *c, uint32_t len) { uint32_t newpos = c->pos + len ; if (newpos < len) return (errno = ENOMEM, 0) ; @@ -27,34 +27,34 @@ static int posplus (struct cdb_make *c, uint32_t len) return 1 ; } -static inline int cdb_make_addend (struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32_t h) +static inline int cdbmake_addend (cdbmaker *c, uint32_t keylen, uint32_t datalen, uint32_t h) { diuint32 blah = { .left = h, .right = c->pos } ; return genalloc_append(diuint32, &c->hplist, &blah) && posplus(c, 8) && posplus(c, keylen) && posplus(c, datalen) ; } -static inline ssize_t cdb_make_addbegin (struct cdb_make *c, unsigned int keylen, unsigned int datalen) +static inline ssize_t cdbmake_addbegin (cdbmaker *c, uint32_t keylen, uint32_t datalen) { char buf[8] ; - uint32_pack(buf, (uint32_t)keylen) ; - uint32_pack(buf + 4, (uint32_t)datalen) ; - return buffer_put(&c->b, buf, 8) ; + uint32_pack(buf, keylen) ; + uint32_pack(buf + 4, datalen) ; + return buffer_put(&c->b, buf, 8) == 8 ; } -int cdb_make_add (struct cdb_make *c, char const *key, unsigned int keylen, char const *data, unsigned int datalen) +int cdbmake_add (cdbmaker *c, char const *key, uint32_t keylen, char const *data, uint32_t datalen) { - if (cdb_make_addbegin(c, keylen, datalen) < 0 + if (!cdbmake_addbegin(c, keylen, datalen) || buffer_put(&c->b, key, keylen) < 0 || buffer_put(&c->b, data, datalen) < 0 - || !cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen))) + || !cdbmake_addend(c, keylen, datalen, cdb_hash(key, keylen))) { genalloc_free(diuint32, &c->hplist) ; - return -1 ; + return 0 ; } - return 0 ; + return 1 ; } -int cdb_make_finish (struct cdb_make *c) +int cdbmake_finish (cdbmaker *c) { uint32_t count[256] ; uint32_t start[256] ; @@ -77,7 +77,7 @@ int cdb_make_finish (struct cdb_make *c) } size += n ; /* no overflow possible up to now */ u = 0xffffffffUL ; u /= sizeof(diuint32) ; - if (size > u) return (errno = ENOMEM, -1) ; + if (size > u) return (errno = ENOMEM, 0) ; } i = n ; { @@ -90,33 +90,32 @@ int cdb_make_finish (struct cdb_make *c) { char buf[8] ; uint32_t k = count[i] ; - uint32_t len = k << 1 ; /* no overflow possible */ + uint32_t len = k << 1 ; /* no overflow possible */ diuint32 *p = split + start[i] ; - unsigned int j = 0 ; 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 = 0 ; j < k ; j++) + for (uint32_t j = 0 ; j < len ; j++) hp[j].left = hp[j].right = 0 ; + for (uint32_t j = 0 ; j < k ; j++) { uint32_t where = (p->left >> 8) % len ; while (hp[where].right) if (++where == len) where = 0 ; hp[where] = *p++ ; } - for (j = 0 ; j < len ; j++) + for (uint32_t j = 0 ; j < len ; j++) { uint32_pack(buf, hp[j].left) ; uint32_pack(buf + 4, hp[j].right) ; - if (buffer_put(&c->b, buf, 8) < 0) return -1 ; - if (!posplus(c, 8)) return -1 ; + if (buffer_put(&c->b, buf, 8) < 0) return 0 ; + if (!posplus(c, 8)) return 0 ; } } } - 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 ; + if (!buffer_flush(&c->b) + || lseek(buffer_fd(&c->b), 0, SEEK_SET) < 0 + || buffer_putflush(&c->b, final, 2048) < 0) return 0 ; + return 1 ; } |