list_del_init/list_node_init: for multiple list_del() calls.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
io: use normal linked lists.

There seems to be a bug with the overloaded single-linked list.
Rewrite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
container_of: Add container_of_or_null()

It's quite common to have a pointer which could be either a pointer to a
structure member, or NULL.  This needs special casing with container_of(),
or it will convert NULL into something strange.

This patch adds container_of_or_null(), which will return NULL if passed
(an appropriately typed) NULL, or the containining structure as
container_of() otherwise.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lqueue: Linked list queue implementation

This new module provides a simple queue implementation as a singly
linked (circular) list.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lstack: Linked list stack implementation

This new module provides a simple stack implementation as a singly
linked list.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bitmap: Switch bit indices to unsigned long

Currently all bit indices used in the bitmap module are represented as
'int'.  These conceptually should be unsigned.  In additional limiting
these to ints potentially prevents use of very large bitmaps.  So, change
these all to unsigned long.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bitmap: Add functions to set/clear ranges of bits

Add bitmap_zero_range() and bitmap_fill_range() functions which will set
a contiguous range of bits in the bitmap to 0 or 1.

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

The bitmap module already has a simple allocation helper, which returns
an uninitialized, dynamically allocated bitmap of a given size.

This extends this with bitmap_alloc[01]() which allocate bitmaps and
initialize them to all zero or all one.

It also adds bitmap_realloc[01]() which reallocate an existing bitmap,
preserving existing bits, and setting any new bits to all zero or all one.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bitmap: Implement bitmap_ffs()

This adds a bitmap_ffs() function to find the first (by the usual bitmap
bit ordering) 1 bit in a bitmap between two given bits.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
eratosthenes: Implementation of the Sieve of Eratosthenes

This adds a new "eratosthenes" module which implements the standard
Sieve of Eratosthenes algorithm for locating small prime numbers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add eratosthenes to Makefile-ccan list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
configurator: Fix CTZ detection

The literal "1" in "1 << (sizeof(long{, long})*8 - 1)" should be 1L or
1LL, so that the expression has the right type. Otherwise, the shift
is only by 31 bits on x86 (other platforms may behave differently). To
avoid language lawyers shouting UB at me, and since
__builtin_ctz{,l,ll} formally takes unsigned parameters, use UL and
ULL suffixes.

Also, fix a typo (missing parenthesis) in the code for CTZLL causing
the detection of __builtin_ctzll to always fail for the wrong reason.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changed the look of the website. Added a new logo design (source SVG included). Fixed an issue with junkcode prefix not being set (broken links and images on current site). Removed /tmp/ccan in clean as it was preventing 'make webpages' running twice. Brought the HTML closer to standards compliance (doctype, encoding). Added meta tag for mobile device browsers to render nicely.
Fix for broken links/images on website 'junkcode' pages.
When building webpages, skip clean-tree check if WEBDEV flag is set.
Standards compliance - XML html doctype, charset meta tag.
New page layout, font, background image. Replaced table tags with headers and paragraph tags as appropriate. Redesigned logo. Added stylesheet to specify layout more easily. Meta tag for mobile device friendliness.
Removed more tables where they aren't required. Improved table layout.
Syntax highlighting for module example code using prettify. Note: prettify is introduced with an svn checkout into the web directoy.
mem: Rename memmem module to mem

Currently the 'memmem' module does nothing but provide an implementation of
the memmem() function if it is missing from the standard C library.

However there are other functions (e.g. memrchr()) also missing from some
C library implementations, so rename the module to mem to allow future
inclusion of other functions.

This also updates the rfc822 module - the only existing user of the
memmem module - to use the new name.

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