bytestring: Add bytestring_byte() function

Add a bytestring_byte() function to get a single byte / character
from a bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Add bytestring_slice function

Add a bytestring_slice() function to take a sub(byte)string of a
bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: bytestring_starts() and bytestring_ends() functions

This implements bytestring_starts() and bytestring_ends() which
will test if a given bytestring starts or ends with another given
bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Add bytestring_index and bytestring_rindex() functions

Add bytestring equivalents of the index() and rindex() standard functions
which search for characters/bytes within a bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Implement bytestring_bytestring()

Add a bytestring_bytestring() function which, in analogy with strstr() and
memmem() finds one bytestring within another.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Implement bytestring_spn() and bytestring_cspn()

Add bytestring_spn() and bytestring_cspn() functions which, in analogy to
strspn() and strcspn() return the lengths of initial sub-bytestrings which
either contain only a given set of bytes, or anything except a given set
of bytes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Split bytestrings by a character delimiter

This introduces the functions bytestring_splitchr_first() and
bytestring_splitchr_next() which can be used to iterate through substrings
of a bytestring separated by a single, specified delimiter character.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Split bytestrings by a set of character delimiters

This introduces the functions bytestring_splitchrs_first() and
bytestring_splitchrs_next() which can be used to iterate through substrings
of a bytestring separated by any of a given set of delimiter characters.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Split bytestrings by a string delimiter

This introduces the functions bytestring_splitstr_first() and
bytestring_splitstr_next() which can be used to iterate through substrings
of a bytestring separated by a specified substring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Use CONST_FUNCTION

The bytestring() constructor function satisfies the constraints of
CONST_FUNCTION, so mark it as such.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
bytestring: Add initializer macro

The BYTESTRING macro is constant, since it's designed to take a string
literal, but it doesn't count as constant since it involves an (inlined)
function call.  That means it can't be used in a static storage duration
initializer.

Unfortunately, I can't see a portable way to make something which can be
used as an initializer, but which can also be used in other contexts where
BYTESTRING() can be used, so this patch introduces BYTESTRING_INIT() which
is similar to BYTESTRING() but produces an initializer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
timer: change timers_expire() to return a single timer.

The linked list method was problematic, especially if timers delete
other expired timers (eg. the next one in the expired list: the timer_del
will delete it from expired, but that's a bit unexpected).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
timer: make timer_del() idempotent, add timer_init().

This catches duplicate timer_add() calls, as well as meaning we don't
need to track if the timer is active before calling timer_del().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
io: update for new timer API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Makefile-ccan: bytestring now has source.

Reported-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>