Redo lots of stuff

This commit is contained in:
Kent Overstreet 2016-03-11 21:18:42 -09:00
parent 074caf716a
commit 009d6db7b0
65 changed files with 6227 additions and 1810 deletions

18
.gitignore vendored
View File

@ -1,21 +1,7 @@
bcacheadm
bcache
probe-bcache
.*
*.o
*.a
tags
cscope*
Makefile.in
aclocal.m4
autom4te.cache
compile
config.guess
config.h.in
config.sub
config.type
configure
depcomp
install-sh
ltmain.sh
m4
missing
include

View File

@ -3,13 +3,13 @@ PREFIX=/usr
UDEVLIBDIR=/lib/udev
DRACUTLIBDIR=/lib/dracut
INSTALL=install
CFLAGS+=-std=gnu99 -O2 -Wall -Werror -g -Iinclude
CFLAGS+=-std=gnu99 -O2 -Wall -g -D_FILE_OFFSET_BITS=64 -I.
LDFLAGS+=-static
all: bcacheadm probe-bcache
all: bcache probe-bcache
install: bcacheadm probe-bcache
$(INSTALL) -m0755 bcacheadm $(DESTDIR)${PREFIX}/sbin/
install: bcache probe-bcache
$(INSTALL) -m0755 bcache $(DESTDIR)${PREFIX}/sbin/
#$(INSTALL) -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/
#$(INSTALL) -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/
#-$(INSTALL) -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
@ -19,14 +19,25 @@ install: bcacheadm probe-bcache
$(INSTALL) -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/
clean:
$(RM) -f probe-bcache bcacheadm bcache-test *.o
$(RM) -f probe-bcache bcache bcache-test *.o *.a
bcache.o: CFLAGS += `pkg-config --cflags uuid blkid`
CCANSRCS=$(wildcard ccan/*/*.c)
CCANOBJS=$(patsubst %.c,%.o,$(CCANSRCS))
bcacheadm.o: CFLAGS += `pkg-config --cflags uuid blkid libnih`
bcacheadm: LDLIBS += `pkg-config --libs uuid blkid libnih`
bcacheadm: bcacheadm.o bcacheadm-format.o bcacheadm-assemble.o bcacheadm-run.o\
bcacheadm-query.o bcache.o
libccan.a: $(CCANOBJS)
$(AR) r $@ $(CCANOBJS)
util.o: CFLAGS += `pkg-config --cflags blkid uuid`
bcache.o: CFLAGS += `pkg-config --cflags libnih`
bcache-objs = bcache.o bcache-assemble.o bcache-device.o bcache-format.o\
bcache-fs.o bcache-run.o
# have to build ccan first, as headers require config.h to be generated:
#$(bcache-objs): ccan/libccan.a
bcache: LDLIBS += `pkg-config --libs uuid blkid libnih`
bcache: $(bcache-objs) util.o libccan.a
probe-bcache.o: CFLAGS += `pkg-config --cflags uuid blkid`
probe-bcache: LDLIBS += `pkg-config --libs uuid blkid`

View File

@ -12,7 +12,7 @@
#include <nih/option.h>
#include "bcache.h"
#include "bcacheadm-assemble.h"
#include "bcache-assemble.h"
NihOption opts_assemble[] = {
NIH_OPTION_LAST

View File

@ -1,5 +1,5 @@
#ifndef _BCACHEADM_ASSEMBLE_H
#define _BCACHEADM_ASSEMBLE_H
#ifndef _BCACHE_ASSEMBLE_H
#define _BCACHE_ASSEMBLE_H
extern NihOption opts_assemble[];
int cmd_assemble(NihCommand *, char * const *);
@ -7,4 +7,4 @@ int cmd_assemble(NihCommand *, char * const *);
extern NihOption opts_incremental[];
int cmd_incremental(NihCommand *, char * const *);
#endif /* _BCACHEADM_ASSEMBLE_H */
#endif /* _BCACHE_ASSEMBLE_H */

229
bcache-device.c Normal file
View File

@ -0,0 +1,229 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <nih/command.h>
#include <nih/option.h>
#include "bcache.h"
#include "bcache-device.h"
struct bcache_dev {
unsigned nr;
const char *name;
unsigned has_metadata;
unsigned has_data;
const char *state;
unsigned tier;
u64 bucket_size;
u64 first_bucket;
u64 nbuckets;
/* XXX: dirty != used, it doesn't count metadata */
u64 bytes_dirty;
};
static struct bcache_dev fill_dev(const char *dev_name, unsigned nr, int dir)
{
return (struct bcache_dev) {
.nr = nr,
.name = dev_name,
.has_metadata = read_file_u64(dir, "has_metadata"),
.has_data = read_file_u64(dir, "has_data"),
.state = read_file_str(dir, "state"),
.tier = read_file_u64(dir, "tier"),
.bucket_size = read_file_u64(dir, "bucket_size_bytes"),
.first_bucket = read_file_u64(dir, "first_bucket"),
.nbuckets = read_file_u64(dir, "nbuckets"),
.bytes_dirty = read_file_u64(dir, "dirty_bytes"),
};
}
static void show_dev(struct bcache_dev *dev)
{
u64 capacity = (dev->nbuckets - dev->first_bucket) *
dev->bucket_size;
/*
* XXX: show fragmentation information, cached/dirty information
*/
printf("Device %u (/dev/%s):\n"
" Has metadata:\t%u\n"
" Has dirty data:\t%u\n"
" State:\t\t%s\n"
" Tier:\t\t%u\n"
" Size:\t\t%llu\n"
" Used:\t\t%llu\n"
" Free:\t\t%llu\n"
" Use%%:\t\t%llu\n",
dev->nr, dev->name,
dev->has_metadata,
dev->has_data,
dev->state,
dev->tier,
capacity,
dev->bytes_dirty,
capacity - dev->bytes_dirty,
(dev->bytes_dirty * 100) / capacity);
}
static int human_readable;
NihOption opts_device_show[] = {
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
{ 'h', "human-readable", N_("print sizes in powers of 1024 (e.g., 1023M)"),
NULL, NULL, &human_readable, NULL},
NIH_OPTION_LAST
};
int cmd_device_show(NihCommand *command, char * const *args)
{
if (!args[0])
die("Please supply a filesystem");
if (args[1])
die("Please supply a single filesystem");
struct bcache_handle fs = bcache_fs_open(args[0]);
struct dirent *entry;
struct bcache_dev devices[256];
unsigned i, j, nr_devices = 0, nr_active_tiers = 0;
unsigned tiers[CACHE_TIERS]; /* number of devices in each tier */
memset(tiers, 0, sizeof(tiers));
while ((entry = readdir(fs.sysfs))) {
unsigned nr;
int pos = 0;
sscanf(entry->d_name, "cache%u%n", &nr, &pos);
if (pos != strlen(entry->d_name))
continue;
char link[PATH_MAX];
if (readlinkat(dirfd(fs.sysfs), entry->d_name,
link, sizeof(link)) < 0)
die("readlink error: %s\n", strerror(errno));
char *dev_name = basename(dirname(link));
int fd = openat(dirfd(fs.sysfs), entry->d_name, O_RDONLY);
if (fd < 0)
die("couldn't open device %s: %s\n",
entry->d_name, strerror(errno));
devices[nr_devices] = fill_dev(strdup(dev_name), nr, fd);
tiers[devices[nr_devices].tier]++;
nr_devices++;
close(fd);
}
for (i = 0; i < CACHE_TIERS; i++)
if (tiers[i])
nr_active_tiers++;
/* Print out devices sorted by tier: */
bool first = true;
for (i = 0; i < CACHE_TIERS; i++) {
if (!tiers[i])
continue;
if (nr_active_tiers > 1) {
if (!first)
printf("\n");
first = false;
printf("Tier %u:\n\n", i);
}
for (j = 0; j < nr_devices; j++) {
if (devices[j].tier != i)
continue;
if (!first)
printf("\n");
first = false;
show_dev(&devices[j]);
}
}
return 0;
}
NihOption opts_device_add[] = {
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
NIH_OPTION_LAST
};
int cmd_device_add(NihCommand *command, char * const *args)
{
if (nr_args(args) < 2)
die("Please supply a filesystem and at least one device to add");
struct bcache_handle fs = bcache_fs_open(args[0]);
for (unsigned i = 1; args[i]; i++) {
struct bch_ioctl_disk_add ia = {
.dev = (__u64) args[i],
};
if (ioctl(fs.fd, BCH_IOCTL_DISK_ADD, &ia))
die("BCH_IOCTL_DISK_ADD error: %s", strerror(errno));
}
return 0;
}
static int force_data, force_metadata;
NihOption opts_device_remove[] = {
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
{ 'f', "force", N_("force if data present"),
NULL, NULL, &force_data, NULL },
{ '\0', "force-metadata", N_("force if metadata present"),
NULL, NULL, &force_metadata, NULL},
NIH_OPTION_LAST
};
int cmd_device_remove(NihCommand *command, char *const *args)
{
if (nr_args(args) < 2)
die("Please supply a filesystem and at least one device to add");
struct bcache_handle fs = bcache_fs_open(args[0]);
for (unsigned i = 1; args[i]; i++) {
struct bch_ioctl_disk_remove ir = {
.dev = (__u64) args[0],
};
if (force_data)
ir.flags |= BCH_FORCE_IF_DATA_MISSING;
if (force_metadata)
ir.flags |= BCH_FORCE_IF_METADATA_MISSING;
if (ioctl(fs.fd, BCH_IOCTL_DISK_REMOVE, &ir))
die("BCH_IOCTL_DISK_REMOVE error: %s\n", strerror(errno));
}
return 0;
}

14
bcache-device.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef _BCACHE_DEVICE_H
#define _BCACHE_DEVICE_H
extern NihOption opts_device_show[];
int cmd_device_show(NihCommand *, char * const *);
extern NihOption opts_device_add[];
int cmd_device_add(NihCommand *, char * const *);
extern NihOption opts_device_remove[];
int cmd_device_remove(NihCommand *, char * const *);
#endif /* _BCACHE_FORMAT_H */

View File

@ -1,26 +1,11 @@
/*
* Authors: Kent Overstreet <kmo@daterainc.com>
* Authors: Kent Overstreet <kent.overstreet@gmail.com>
* Gabriel de Perthuis <g2p.code@gmail.com>
* Jacob Malevich <jam@datera.io>
*
* GPLv2
*/
#if 0
#include <nih/main.h>
#include <nih/logging.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <blkid.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <dirent.h>
#endif
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
@ -35,29 +20,33 @@
#include <nih/command.h>
#include <nih/option.h>
#include "bcache.h"
#include "bcacheadm-format.h"
#include "ccan/ilog/ilog.h"
#include "ccan/darray/darray.h"
static struct cache_opts {
#include "bcache.h"
#include "bcache-format.h"
struct cache_opts {
int fd;
const char *dev;
unsigned bucket_size;
unsigned tier;
unsigned replacement_policy;
unsigned replication_set;
u64 filesystem_size;
u64 size; /* 512 byte sectors */
u64 first_bucket;
u64 nbuckets;
} cache_devices[MAX_DEVS];
};
static struct backingdev_opts {
struct backingdev_opts {
int fd;
const char *dev;
const char *label;
} backing_devices[MAX_DEVS];
};
static size_t nr_backing_devices = 0, nr_cache_devices = 0;
static darray(struct cache_opts) cache_devices;
static darray(struct backingdev_opts) backing_devices;
static char *label = NULL;
@ -81,25 +70,25 @@ static unsigned cache_mode = CACHE_MODE_WRITEBACK;
static int set_cache(NihOption *option, const char *arg)
{
cache_devices[nr_cache_devices++] = (struct cache_opts) {
darray_append(cache_devices, (struct cache_opts) {
.fd = dev_open(arg),
.dev = strdup(arg),
.bucket_size = bucket_size,
.tier = tier,
.replacement_policy = replacement_policy,
.replication_set = replication_set,
.filesystem_size = filesystem_size,
};
.size = filesystem_size,
});
return 0;
}
static int set_bdev(NihOption *option, const char *arg)
{
backing_devices[nr_backing_devices++] = (struct backingdev_opts) {
darray_append(backing_devices, (struct backingdev_opts) {
.fd = dev_open(arg),
.dev = strdup(arg),
.label = label ? strdup(label) : NULL,
};
});
return 0;
}
@ -267,41 +256,17 @@ NihOption opts_format[] = {
NIH_OPTION_LAST
};
static unsigned rounddown_pow_of_two(unsigned n)
{
unsigned ret;
do {
ret = n;
n &= n - 1;
} while (n);
return ret;
}
static unsigned ilog2(u64 n)
{
unsigned ret = 0;
while (n) {
ret++;
n >>= 1;
}
return ret;
}
void __do_write_sb(int fd, void *sb, size_t bytes)
{
char zeroes[SB_START] = {0};
char zeroes[SB_SECTOR << 9] = {0};
/* Zero start of disk */
if (pwrite(fd, zeroes, SB_START, 0) != SB_START) {
if (pwrite(fd, zeroes, SB_SECTOR << 9, 0) != SB_SECTOR << 9) {
perror("write error trying to zero start of disk\n");
exit(EXIT_FAILURE);
}
/* Write superblock */
if (pwrite(fd, sb, bytes, SB_START) != bytes) {
if (pwrite(fd, sb, bytes, SB_SECTOR << 9) != bytes) {
perror("write error trying to write superblock\n");
exit(EXIT_FAILURE);
}
@ -354,11 +319,11 @@ void write_backingdev_sb(int fd, unsigned block_size, unsigned mode,
static void format_v0(void)
{
struct cache_opts *i;
set_uuid = user_uuid;
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++)
darray_foreach(i, cache_devices)
bucket_size = min(bucket_size, i->bucket_size);
struct cache_sb_v0 *sb = calloc(1, sizeof(*sb));
@ -369,20 +334,18 @@ static void format_v0(void)
sb->block_size = block_size;
sb->bucket_size = bucket_size;
sb->set_uuid = set_uuid;
sb->nr_in_set = nr_cache_devices;
sb->nr_in_set = darray_size(cache_devices);
if (label)
memcpy(sb->label, label, sizeof(sb->label));
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++) {
darray_foreach(i, cache_devices) {
char uuid_str[40], set_uuid_str[40];
uuid_generate(sb->uuid.b);
sb->nbuckets = i->nbuckets;
sb->first_bucket = i->first_bucket;
sb->nr_this_dev = i - cache_devices;
sb->nr_this_dev = i - cache_devices.item;
sb->csum = csum_set(sb, BCH_CSUM_CRC64);
uuid_unparse(sb->uuid.b, uuid_str);
@ -412,16 +375,18 @@ static void format_v0(void)
static void format_v1(void)
{
struct cache_sb *sb;
struct cache_opts *i;
sb = calloc(1, sizeof(*sb) + sizeof(struct cache_member) *
nr_cache_devices);
darray_size(cache_devices));
sb->offset = SB_SECTOR;
sb->version = BCACHE_SB_VERSION_CDEV_V3;
sb->magic = BCACHE_MAGIC;
sb->offset = SB_SECTOR;
sb->version = BCACHE_SB_VERSION_CDEV_V3;
sb->magic = BCACHE_MAGIC;
sb->block_size = block_size;
sb->set_uuid = set_uuid;
sb->user_uuid = user_uuid;
sb->set_uuid = set_uuid;
sb->user_uuid = user_uuid;
sb->nr_in_set = darray_size(cache_devices);
if (label)
memcpy(sb->label, label, sizeof(sb->label));
@ -442,10 +407,9 @@ static void format_v1(void)
SET_CACHE_SET_DATA_REPLICAS_HAVE(sb, data_replicas);
SET_CACHE_ERROR_ACTION(sb, on_error_action);
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++) {
struct cache_member *m = sb->members + sb->nr_in_set++;
darray_foreach(i, cache_devices) {
struct cache_member *m = sb->members +
(i - cache_devices.item);
uuid_generate(m->uuid.b);
m->nbuckets = i->nbuckets;
@ -464,14 +428,14 @@ static void format_v1(void)
sb->u64s = bch_journal_buckets_offset(sb);
for (unsigned i = 0; i < sb->nr_in_set; i++) {
darray_foreach(i, cache_devices) {
char uuid_str[40], set_uuid_str[40];
struct cache_member *m = sb->members + i;
struct cache_member *m = sb->members +
(i - cache_devices.item);
sb->disk_uuid = m->uuid;
sb->nr_this_dev = i;
sb->csum = csum_set(sb,
CACHE_SB_CSUM_TYPE(sb));
sb->disk_uuid = m->uuid;
sb->nr_this_dev = i - cache_devices.item;
sb->csum = csum_set(sb, CACHE_SB_CSUM_TYPE(sb));
uuid_unparse(sb->disk_uuid.b, uuid_str);
uuid_unparse(sb->user_uuid.b, set_uuid_str);
@ -493,13 +457,17 @@ static void format_v1(void)
sb->nr_this_dev,
m->first_bucket);
do_write_sb(cache_devices[i].fd, sb);
do_write_sb(i->fd, sb);
}
}
int cmd_format(NihCommand *command, char *const *args)
int cmd_format(NihCommand *command, char * const *args)
{
if (!nr_cache_devices && !nr_backing_devices)
struct cache_opts *i;
struct backingdev_opts *ib;
if (!darray_size(cache_devices) &&
!darray_size(backing_devices))
die("Please supply a device");
if (uuid_is_null(user_uuid.b))
@ -508,36 +476,33 @@ int cmd_format(NihCommand *command, char *const *args)
uuid_generate(set_uuid.b);
if (!block_size) {
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++)
block_size = max(block_size, get_blocksize(i->dev, i->fd));
darray_foreach(i, cache_devices)
block_size = max(block_size,
get_blocksize(i->dev, i->fd));
for (struct backingdev_opts *i = backing_devices;
i < backing_devices + nr_backing_devices;
i++)
block_size = max(block_size, get_blocksize(i->dev, i->fd));
darray_foreach(ib, backing_devices)
block_size = max(block_size,
get_blocksize(ib->dev, ib->fd));
}
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++) {
if (!i->bucket_size) {
u64 size = (i->filesystem_size ?:
getblocks(i->fd)) << 9;
darray_foreach(i, cache_devices) {
if (!i->size)
i->size = get_size(i->dev, i->fd);
if (size < 1 << 20) /* 1M device - 256 4k buckets*/
i->bucket_size = rounddown_pow_of_two(size >> 17);
if (!i->bucket_size) {
u64 bytes = i->size << 9;
if (bytes < 1 << 20) /* 1M device - 256 4k buckets*/
i->bucket_size = rounddown_pow_of_two(bytes >> 17);
else
/* Max 1M bucket at around 256G */
i->bucket_size = 8 << min((ilog2(size >> 20) / 2), 9U);
i->bucket_size = 8 << min((ilog2(bytes >> 20) / 2), 9U);
}
if (i->bucket_size < block_size)
die("Bucket size cannot be smaller than block size");
i->nbuckets = (i->filesystem_size ?:
getblocks(i->fd)) / i->bucket_size;
i->nbuckets = i->size / i->bucket_size;
i->first_bucket = (23 / i->bucket_size) + 3;
if (i->nbuckets < 1 << 7)
@ -549,9 +514,7 @@ int cmd_format(NihCommand *command, char *const *args)
/* 256k default btree node size */
btree_node_size = 512;
for (struct cache_opts *i = cache_devices;
i < cache_devices + nr_cache_devices;
i++)
darray_foreach(i, cache_devices)
btree_node_size = min(btree_node_size, i->bucket_size);
}
@ -564,11 +527,9 @@ int cmd_format(NihCommand *command, char *const *args)
break;
}
for (struct backingdev_opts *i = backing_devices;
i < backing_devices + nr_backing_devices;
i++)
write_backingdev_sb(i->fd, block_size, cache_mode,
data_offset, i->label,
darray_foreach(ib, backing_devices)
write_backingdev_sb(ib->fd, block_size, cache_mode,
data_offset, ib->label,
set_uuid);
return 0;

7
bcache-format.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _BCACHE_FORMAT_H
#define _BCACHE_FORMAT_H
extern NihOption opts_format[];
int cmd_format(NihCommand *, char * const *);
#endif /* _BCACHE_FORMAT_H */

51
bcache-fs.c Normal file
View File

@ -0,0 +1,51 @@
#include <nih/command.h>
#include <nih/option.h>
#include "bcache.h"
#include "bcache-fs.h"
struct bcache_fs {
/* options... */
u64 capacity;
/* XXX: dirty != used, it doesn't count metadata */
u64 bytes_dirty;
};
static struct bcache_fs fill_fs(struct bcache_handle fs)
{
return (struct bcache_fs) {
};
}
NihOption opts_fs_show[] = {
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
NIH_OPTION_LAST
};
int cmd_fs_show(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply a filesystem");
struct bcache_handle fs = bcache_fs_open(args[0]);
return 0;
}
NihOption opts_fs_set[] = {
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
NIH_OPTION_LAST
};
int cmd_fs_set(NihCommand *command, char *const *args)
{
if (nr_args(args) < 1)
die("Please supply a filesystem");
struct bcache_handle fs = bcache_fs_open(args[0]);
return 0;
}

10
bcache-fs.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _BCACHE_FS_H
#define _BCACHE_FS_H
extern NihOption opts_fs_show[];
int cmd_fs_show(NihCommand *, char * const *);
extern NihOption opts_fs_set[];
int cmd_fs_set(NihCommand *, char * const *);
#endif /* _BCACHE_FS_H */

View File

@ -1,5 +1,5 @@
#ifndef _BCACHE_TOOLS_IOCTL_H
#define _BCACHE_TOOLS_IOCTL_H
#ifndef _LINUX_BCACHE_IOCTL_H
#define _LINUX_BCACHE_IOCTL_H
#include <linux/uuid.h>
@ -29,6 +29,8 @@ extern "C" {
#define BCH_IOCTL_DISK_FAIL_BY_UUID \
_IOW('r', 6, struct bch_ioctl_disk_fail_by_uuid)
#define BCH_IOCTL_QUERY_UUID _IOR('r', 6, struct bch_ioctl_query_uuid)
struct bch_ioctl_assemble {
__u32 flags;
__u32 nr_devs;
@ -72,8 +74,12 @@ struct bch_ioctl_disk_fail_by_uuid {
uuid_le dev;
};
struct bch_ioctl_query_uuid {
uuid_le uuid;
};
#ifdef __cplusplus
}
#endif
#endif /* _BCACHE_TOOLS_IOCTL_H */
#endif /* _LINUX_BCACHE_IOCTL_H */

View File

@ -459,7 +459,7 @@ struct bch_inode_blockdev {
uuid_le i_uuid;
__u8 i_label[32];
} __packed;
} __attribute__((packed));
BKEY_VAL_TYPE(inode_blockdev, BCH_INODE_BLOCKDEV);
/* Dirents */
@ -493,7 +493,7 @@ struct bch_dirent {
__u8 d_type;
__u8 d_name[];
} __packed;
} __attribute__((packed));
BKEY_VAL_TYPE(dirent, BCH_DIRENT);
/* Xattrs */
@ -515,7 +515,7 @@ struct bch_xattr {
__u8 x_name_len;
__u16 x_val_len;
__u8 x_name[];
} __packed;
} __attribute__((packed));
BKEY_VAL_TYPE(xattr, BCH_XATTR);
/* Superblock */

44
bcache-run.c Normal file
View File

@ -0,0 +1,44 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <nih/command.h>
#include <nih/option.h>
#include <uuid/uuid.h>
#include "bcache.h"
#include "bcache-run.h"
NihOption opts_run[] = {
NIH_OPTION_LAST
};
int cmd_run(NihCommand *command, char *const *args)
{
return 0;
}
NihOption opts_stop[] = {
NIH_OPTION_LAST
};
int cmd_stop(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply a filesystem");
struct bcache_handle fs = bcache_fs_open(args[0]);
if (ioctl(fs.fd, BCH_IOCTL_STOP))
die("BCH_IOCTL_STOP error: %s", strerror(errno));
return 0;
}

10
bcache-run.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _BCACHE_RUN_H
#define _BCACHE_RUN_H
extern NihOption opts_run[];
int cmd_run(NihCommand *, char * const *);
extern NihOption opts_stop[];
int cmd_stop(NihCommand *, char * const *);
#endif /* _BCACHE_RUN_H */

View File

@ -1,5 +1,5 @@
/*
* Author: Kent Overstreet <kmo@daterainc.com>
* Author: Kent Overstreet <kent.overstreet@gmail.com>
*
* GPLv2
*/

895
bcache.c
View File

@ -1,26 +1,40 @@
#define _GNU_SOURCE
/*
* Authors: Kent Overstreet <kent.overstreet@gmail.com>
* Gabriel de Perthuis <g2p.code@gmail.com>
* Jacob Malevich <jam@datera.io>
*
* GPLv2
*/
#include <nih/option.h>
#include <nih/command.h>
#include <nih/main.h>
#include <nih/logging.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <inttypes.h>
#include <getopt.h>
#include <limits.h>
#include <linux/fs.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <uuid/uuid.h>
#include <blkid.h>
#include "bcache.h"
#include "bcache-assemble.h"
#include "bcache-device.h"
#include "bcache-format.h"
#include "bcache-fs.h"
#include "bcache-run.h"
#define PACKAGE_NAME "bcache"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_BUGREPORT "linux-bcache@vger.kernel.org"
const char * const cache_state[] = {
"active",
@ -75,810 +89,77 @@ const char * const bdev_state[] = {
NULL
};
const char * const set_attrs[] = {
"btree_flush_delay",
"btree_scan_ratelimit",
"bucket_reserve_percent",
"cache_reserve_percent",
"checksum_type",
"congested_read_threshold_us",
"congested_write_threshold_us",
"data_replicas",
"errors",
"foreground_target_percent",
"gc_sector_percent",
"journal_delay_ms",
"meta_replicas",
"sector_reserve_percent",
"tiering_percent",
NULL
#define CMD(_command, _usage, _synopsis) \
{ \
.command = #_command, \
.usage = _usage, \
.synopsis = _synopsis, \
.help = NULL, \
.group = NULL, \
.options = opts_##_command, \
.action = cmd_##_command, \
}
static NihCommand commands[] = {
CMD(format, N_("<list of devices>"),
"Create a new bcache volume from one or more devices"),
/* Bringup, shutdown */
CMD(assemble, N_("<devices>"),
"Assembles one or more devices into a bcache volume"),
CMD(incremental, N_("<device"),
"Incrementally assemble a bcache filesystem"),
CMD(run, N_("<volume>"),
"Start a partially assembled volume"),
CMD(stop, N_("<volume>"),
"Stops a running bcache volume"),
/* Filesystem commands: */
CMD(fs_show, N_("<fs>"),
"Show information about a filesystem"),
CMD(fs_set, N_("<fs>"),
"Change various filesystem options"),
/* Device commands: */
CMD(device_show, N_("<fs>"),
"Show information about component devices of a filesystem"),
CMD(device_add, N_("<volume> <devices>"),
"Adds a list of devices to a volume"),
CMD(device_remove, N_("<volume> <devices>"),
"Removes a device from its volume"),
#if 0
CMD(modify, N_("<options>"),
"Modifies attributes related to the volume",
N_("Modifies attributes related to the volume")),
CMD(list, N_("list-cachesets"),
"Lists cachesets in /sys/fs/bcache"),
CMD(query, N_("query <list of devices>"),
"Gives info about the superblock of a list of devices"),
CMD(status, N_("status <list of devices>"),
"Finds the status of the most up to date superblock"),
#endif
NIH_COMMAND_LAST
};
const char * const cache_attrs[] = {
"cache_replacement_policy",
"discard",
"state",
"tier",
NULL
static NihOption options[] = {
NIH_OPTION_LAST
};
const char * const internal_attrs[] = {
"btree_shrinker_disabled",
"copy_gc_enabled",
"foreground_write_rate",
"tiering_enabled",
"tiering_rate",
NULL
};
char *skip_spaces(const char *str)
int main(int argc, char *argv[])
{
while (isspace(*str))
++str;
return (char *)str;
}
nih_main_init(argv[0]);
nih_option_set_synopsis(_("Manage bcache devices"));
nih_option_set_help( _("Helps you manage bcache devices"));
char *strim(char *s)
{
size_t size;
char *end;
s = skip_spaces(s);
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';
return s;
}
ssize_t read_string_list(const char *buf, const char * const list[])
{
size_t i;
char *s, *d = strdup(buf);
if (!d)
return -ENOMEM;
s = strim(d);
for (i = 0; list[i]; i++)
if (!strcmp(list[i], s))
break;
free(d);
if (!list[i])
return -EINVAL;
return i;
}
ssize_t read_string_list_or_die(const char *opt, const char * const list[],
const char *msg)
{
ssize_t v = read_string_list(opt, list);
if (v < 0)
die("Bad %s %s", msg, opt);
return v;
}
void print_string_list(const char * const list[], size_t selected)
{
size_t i;
for (i = 0; list[i]; i++) {
if (i)
putchar(' ');
printf(i == selected ? "[%s] ": "%s", list[i]);
}
}
/*
* This is the CRC-32C table
* Generated with:
* width = 32 bits
* poly = 0x1EDC6F41
* reflect input bytes = true
* reflect output bytes = true
*/
static const u32 crc32c_table[256] = {
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL,
0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL,
0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L,
0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L,
0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL,
0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL,
0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L,
0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL,
0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L,
0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL,
0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL,
0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L,
0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L,
0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L,
0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L,
0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L,
0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L,
0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L,
0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L,
0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L,
0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L,
0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L,
0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L,
0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L,
0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L,
0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L,
0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL,
0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L,
0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L,
0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL,
0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L,
0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL,
0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL,
0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L,
0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL,
0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL,
0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L,
0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL,
0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L,
0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L,
0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL,
0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L,
0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL,
0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L,
0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL,
0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L,
0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L,
0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL,
0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL,
0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L,
0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L,
0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L,
0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL,
0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL,
0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L
};
/*
* Steps through buffer one byte at at time, calculates reflected
* crc using table.
*/
static u32 crc32c(u32 crc, unsigned char const *data, size_t length)
{
while (length--)
crc =
crc32c_table[(crc ^ *data++) & 0xFFL] ^ (crc >> 8);
return crc;
}
/*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group (Any
* use permitted, subject to terms of PostgreSQL license; see.)
* If we have a 64-bit integer type, then a 64-bit CRC looks just like the
* usual sort of implementation. (See Ross Williams' excellent introduction
* A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from
* ftp://ftp.rocksoft.com/papers/crc_v3.txt or several other net sites.)
* If we have no working 64-bit type, then fake it with two 32-bit registers.
*
* The present implementation is a normal (not "reflected", in Williams'
* terms) 64-bit CRC, using initial all-ones register contents and a final
* bit inversion. The chosen polynomial is borrowed from the DLT1 spec
* (ECMA-182, available from http://www.ecma.ch/ecma1/STAND/ECMA-182.HTM):
*
* x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 +
* x^40 + x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 +
* x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 +
* x^7 + x^4 + x + 1
*/
static const uint64_t crc_table[256] = {
0x0000000000000000ULL, 0x42F0E1EBA9EA3693ULL, 0x85E1C3D753D46D26ULL,
0xC711223CFA3E5BB5ULL, 0x493366450E42ECDFULL, 0x0BC387AEA7A8DA4CULL,
0xCCD2A5925D9681F9ULL, 0x8E224479F47CB76AULL, 0x9266CC8A1C85D9BEULL,
0xD0962D61B56FEF2DULL, 0x17870F5D4F51B498ULL, 0x5577EEB6E6BB820BULL,
0xDB55AACF12C73561ULL, 0x99A54B24BB2D03F2ULL, 0x5EB4691841135847ULL,
0x1C4488F3E8F96ED4ULL, 0x663D78FF90E185EFULL, 0x24CD9914390BB37CULL,
0xE3DCBB28C335E8C9ULL, 0xA12C5AC36ADFDE5AULL, 0x2F0E1EBA9EA36930ULL,
0x6DFEFF5137495FA3ULL, 0xAAEFDD6DCD770416ULL, 0xE81F3C86649D3285ULL,
0xF45BB4758C645C51ULL, 0xB6AB559E258E6AC2ULL, 0x71BA77A2DFB03177ULL,
0x334A9649765A07E4ULL, 0xBD68D2308226B08EULL, 0xFF9833DB2BCC861DULL,
0x388911E7D1F2DDA8ULL, 0x7A79F00C7818EB3BULL, 0xCC7AF1FF21C30BDEULL,
0x8E8A101488293D4DULL, 0x499B3228721766F8ULL, 0x0B6BD3C3DBFD506BULL,
0x854997BA2F81E701ULL, 0xC7B97651866BD192ULL, 0x00A8546D7C558A27ULL,
0x4258B586D5BFBCB4ULL, 0x5E1C3D753D46D260ULL, 0x1CECDC9E94ACE4F3ULL,
0xDBFDFEA26E92BF46ULL, 0x990D1F49C77889D5ULL, 0x172F5B3033043EBFULL,
0x55DFBADB9AEE082CULL, 0x92CE98E760D05399ULL, 0xD03E790CC93A650AULL,
0xAA478900B1228E31ULL, 0xE8B768EB18C8B8A2ULL, 0x2FA64AD7E2F6E317ULL,
0x6D56AB3C4B1CD584ULL, 0xE374EF45BF6062EEULL, 0xA1840EAE168A547DULL,
0x66952C92ECB40FC8ULL, 0x2465CD79455E395BULL, 0x3821458AADA7578FULL,
0x7AD1A461044D611CULL, 0xBDC0865DFE733AA9ULL, 0xFF3067B657990C3AULL,
0x711223CFA3E5BB50ULL, 0x33E2C2240A0F8DC3ULL, 0xF4F3E018F031D676ULL,
0xB60301F359DBE0E5ULL, 0xDA050215EA6C212FULL, 0x98F5E3FE438617BCULL,
0x5FE4C1C2B9B84C09ULL, 0x1D14202910527A9AULL, 0x93366450E42ECDF0ULL,
0xD1C685BB4DC4FB63ULL, 0x16D7A787B7FAA0D6ULL, 0x5427466C1E109645ULL,
0x4863CE9FF6E9F891ULL, 0x0A932F745F03CE02ULL, 0xCD820D48A53D95B7ULL,
0x8F72ECA30CD7A324ULL, 0x0150A8DAF8AB144EULL, 0x43A04931514122DDULL,
0x84B16B0DAB7F7968ULL, 0xC6418AE602954FFBULL, 0xBC387AEA7A8DA4C0ULL,
0xFEC89B01D3679253ULL, 0x39D9B93D2959C9E6ULL, 0x7B2958D680B3FF75ULL,
0xF50B1CAF74CF481FULL, 0xB7FBFD44DD257E8CULL, 0x70EADF78271B2539ULL,
0x321A3E938EF113AAULL, 0x2E5EB66066087D7EULL, 0x6CAE578BCFE24BEDULL,
0xABBF75B735DC1058ULL, 0xE94F945C9C3626CBULL, 0x676DD025684A91A1ULL,
0x259D31CEC1A0A732ULL, 0xE28C13F23B9EFC87ULL, 0xA07CF2199274CA14ULL,
0x167FF3EACBAF2AF1ULL, 0x548F120162451C62ULL, 0x939E303D987B47D7ULL,
0xD16ED1D631917144ULL, 0x5F4C95AFC5EDC62EULL, 0x1DBC74446C07F0BDULL,
0xDAAD56789639AB08ULL, 0x985DB7933FD39D9BULL, 0x84193F60D72AF34FULL,
0xC6E9DE8B7EC0C5DCULL, 0x01F8FCB784FE9E69ULL, 0x43081D5C2D14A8FAULL,
0xCD2A5925D9681F90ULL, 0x8FDAB8CE70822903ULL, 0x48CB9AF28ABC72B6ULL,
0x0A3B7B1923564425ULL, 0x70428B155B4EAF1EULL, 0x32B26AFEF2A4998DULL,
0xF5A348C2089AC238ULL, 0xB753A929A170F4ABULL, 0x3971ED50550C43C1ULL,
0x7B810CBBFCE67552ULL, 0xBC902E8706D82EE7ULL, 0xFE60CF6CAF321874ULL,
0xE224479F47CB76A0ULL, 0xA0D4A674EE214033ULL, 0x67C58448141F1B86ULL,
0x253565A3BDF52D15ULL, 0xAB1721DA49899A7FULL, 0xE9E7C031E063ACECULL,
0x2EF6E20D1A5DF759ULL, 0x6C0603E6B3B7C1CAULL, 0xF6FAE5C07D3274CDULL,
0xB40A042BD4D8425EULL, 0x731B26172EE619EBULL, 0x31EBC7FC870C2F78ULL,
0xBFC9838573709812ULL, 0xFD39626EDA9AAE81ULL, 0x3A28405220A4F534ULL,
0x78D8A1B9894EC3A7ULL, 0x649C294A61B7AD73ULL, 0x266CC8A1C85D9BE0ULL,
0xE17DEA9D3263C055ULL, 0xA38D0B769B89F6C6ULL, 0x2DAF4F0F6FF541ACULL,
0x6F5FAEE4C61F773FULL, 0xA84E8CD83C212C8AULL, 0xEABE6D3395CB1A19ULL,
0x90C79D3FEDD3F122ULL, 0xD2377CD44439C7B1ULL, 0x15265EE8BE079C04ULL,
0x57D6BF0317EDAA97ULL, 0xD9F4FB7AE3911DFDULL, 0x9B041A914A7B2B6EULL,
0x5C1538ADB04570DBULL, 0x1EE5D94619AF4648ULL, 0x02A151B5F156289CULL,
0x4051B05E58BC1E0FULL, 0x87409262A28245BAULL, 0xC5B073890B687329ULL,
0x4B9237F0FF14C443ULL, 0x0962D61B56FEF2D0ULL, 0xCE73F427ACC0A965ULL,
0x8C8315CC052A9FF6ULL, 0x3A80143F5CF17F13ULL, 0x7870F5D4F51B4980ULL,
0xBF61D7E80F251235ULL, 0xFD913603A6CF24A6ULL, 0x73B3727A52B393CCULL,
0x31439391FB59A55FULL, 0xF652B1AD0167FEEAULL, 0xB4A25046A88DC879ULL,
0xA8E6D8B54074A6ADULL, 0xEA16395EE99E903EULL, 0x2D071B6213A0CB8BULL,
0x6FF7FA89BA4AFD18ULL, 0xE1D5BEF04E364A72ULL, 0xA3255F1BE7DC7CE1ULL,
0x64347D271DE22754ULL, 0x26C49CCCB40811C7ULL, 0x5CBD6CC0CC10FAFCULL,
0x1E4D8D2B65FACC6FULL, 0xD95CAF179FC497DAULL, 0x9BAC4EFC362EA149ULL,
0x158E0A85C2521623ULL, 0x577EEB6E6BB820B0ULL, 0x906FC95291867B05ULL,
0xD29F28B9386C4D96ULL, 0xCEDBA04AD0952342ULL, 0x8C2B41A1797F15D1ULL,
0x4B3A639D83414E64ULL, 0x09CA82762AAB78F7ULL, 0x87E8C60FDED7CF9DULL,
0xC51827E4773DF90EULL, 0x020905D88D03A2BBULL, 0x40F9E43324E99428ULL,
0x2CFFE7D5975E55E2ULL, 0x6E0F063E3EB46371ULL, 0xA91E2402C48A38C4ULL,
0xEBEEC5E96D600E57ULL, 0x65CC8190991CB93DULL, 0x273C607B30F68FAEULL,
0xE02D4247CAC8D41BULL, 0xA2DDA3AC6322E288ULL, 0xBE992B5F8BDB8C5CULL,
0xFC69CAB42231BACFULL, 0x3B78E888D80FE17AULL, 0x7988096371E5D7E9ULL,
0xF7AA4D1A85996083ULL, 0xB55AACF12C735610ULL, 0x724B8ECDD64D0DA5ULL,
0x30BB6F267FA73B36ULL, 0x4AC29F2A07BFD00DULL, 0x08327EC1AE55E69EULL,
0xCF235CFD546BBD2BULL, 0x8DD3BD16FD818BB8ULL, 0x03F1F96F09FD3CD2ULL,
0x41011884A0170A41ULL, 0x86103AB85A2951F4ULL, 0xC4E0DB53F3C36767ULL,
0xD8A453A01B3A09B3ULL, 0x9A54B24BB2D03F20ULL, 0x5D45907748EE6495ULL,
0x1FB5719CE1045206ULL, 0x919735E51578E56CULL, 0xD367D40EBC92D3FFULL,
0x1476F63246AC884AULL, 0x568617D9EF46BED9ULL, 0xE085162AB69D5E3CULL,
0xA275F7C11F7768AFULL, 0x6564D5FDE549331AULL, 0x279434164CA30589ULL,
0xA9B6706FB8DFB2E3ULL, 0xEB46918411358470ULL, 0x2C57B3B8EB0BDFC5ULL,
0x6EA7525342E1E956ULL, 0x72E3DAA0AA188782ULL, 0x30133B4B03F2B111ULL,
0xF7021977F9CCEAA4ULL, 0xB5F2F89C5026DC37ULL, 0x3BD0BCE5A45A6B5DULL,
0x79205D0E0DB05DCEULL, 0xBE317F32F78E067BULL, 0xFCC19ED95E6430E8ULL,
0x86B86ED5267CDBD3ULL, 0xC4488F3E8F96ED40ULL, 0x0359AD0275A8B6F5ULL,
0x41A94CE9DC428066ULL, 0xCF8B0890283E370CULL, 0x8D7BE97B81D4019FULL,
0x4A6ACB477BEA5A2AULL, 0x089A2AACD2006CB9ULL, 0x14DEA25F3AF9026DULL,
0x562E43B4931334FEULL, 0x913F6188692D6F4BULL, 0xD3CF8063C0C759D8ULL,
0x5DEDC41A34BBEEB2ULL, 0x1F1D25F19D51D821ULL, 0xD80C07CD676F8394ULL,
0x9AFCE626CE85B507ULL
};
static uint64_t bch_crc64_update(uint64_t crc, const void *_data, size_t len)
{
const unsigned char *data = _data;
while (len--) {
int i = ((int) (crc >> 56) ^ *data++) & 0xFF;
crc = crc_table[i] ^ (crc << 8);
}
return crc;
}
static uint64_t bch_checksum_update(unsigned type, uint64_t crc, const void *data, size_t len)
{
switch (type) {
case BCH_CSUM_NONE:
return 0;
case BCH_CSUM_CRC32C:
return crc32c(crc, data, len);
case BCH_CSUM_CRC64:
return bch_crc64_update(crc, data, len);
default:
die("Unknown checksum type %u", type);
}
}
uint64_t bch_checksum(unsigned type, const void *data, size_t len)
{
uint64_t crc = 0xffffffffffffffffULL;
crc = bch_checksum_update(type, crc, data, len);
return crc ^ 0xffffffffffffffffULL;
}
uint64_t getblocks(int fd)
{
uint64_t ret;
struct stat statbuf;
if (fstat(fd, &statbuf)) {
perror("getblocks: stat error\n");
int ret = nih_command_parser(NULL, argc, argv, options, commands);
if (ret < 0)
exit(EXIT_FAILURE);
}
ret = statbuf.st_size / 512;
if (S_ISBLK(statbuf.st_mode))
if (ioctl(fd, BLKGETSIZE, &ret)) {
perror("ioctl error getting blksize");
exit(EXIT_FAILURE);
}
return ret;
}
uint64_t hatoi(const char *s)
{
char *e;
long long i = strtoll(s, &e, 10);
switch (*e) {
case 't':
case 'T':
i *= 1024;
case 'g':
case 'G':
i *= 1024;
case 'm':
case 'M':
i *= 1024;
case 'k':
case 'K':
i *= 1024;
}
return i;
}
nih_signal_reset();
unsigned hatoi_validate(const char *s, const char *msg)
{
uint64_t v = hatoi(s);
if (v & (v - 1))
die("%s must be a power of two", msg);
v /= 512;
if (v > USHRT_MAX)
die("%s too large\n", msg);
if (!v)
die("%s too small\n", msg);
return v;
}
int dev_open(const char *dev)
{
blkid_probe pr;
int fd;
if ((fd = open(dev, O_RDWR|O_EXCL)) == -1)
die("Can't open dev %s: %s\n", dev, strerror(errno));
if (!(pr = blkid_new_probe()))
die("Failed to create a new probe");
if (blkid_probe_set_device(pr, fd, 0, 0))
die("failed to set probe to device");
/* enable ptable probing; superblock probing is enabled by default */
if (blkid_probe_enable_partitions(pr, true))
die("Failed to enable partitions on probe");
if (!blkid_do_probe(pr))
/* XXX wipefs doesn't know how to remove partition tables */
die("Device %s already has a non-bcache superblock, "
"remove it using wipefs and wipefs -a\n", dev);
return fd;
}
unsigned get_blocksize(const char *path, int fd)
{
struct stat statbuf;
if (fstat(fd, &statbuf))
die("Error statting %s: %s", path, strerror(errno));
if (S_ISBLK(statbuf.st_mode)) {
/* check IO limits:
* BLKALIGNOFF: alignment_offset
* BLKPBSZGET: physical_block_size
* BLKSSZGET: logical_block_size
* BLKIOMIN: minimum_io_size
* BLKIOOPT: optimal_io_size
*
* It may be tempting to use physical_block_size,
* or even minimum_io_size.
* But to be as transparent as possible,
* we want to use logical_block_size.
*/
unsigned int logical_block_size;
if (ioctl(fd, BLKSSZGET, &logical_block_size))
die("ioctl(%s, BLKSSZGET) failed: %m", path);
return logical_block_size / 512;
}
/* else: not a block device.
* Why would we even want to write a bcache super block there? */
return statbuf.st_blksize / 512;
}
long strtoul_or_die(const char *p, size_t max, const char *msg)
{
errno = 0;
long v = strtol(p, NULL, 10);
if (errno || v < 0 || v >= max)
die("Invalid %s %zi", msg, v);
return v;
}
static void print_encode(char *in)
{
char *pos;
for (pos = in; *pos; pos++)
if (isalnum(*pos) || strchr(".-_", *pos))
putchar(*pos);
else
printf("%%%x", *pos);
}
static void show_uuid_only(struct cache_sb *sb, char *dev_uuid) {
uuid_unparse(sb->disk_uuid.b, dev_uuid);
}
static void show_super_common(struct cache_sb *sb, bool force_csum)
{
char uuid[40];
char label[SB_LABEL_SIZE + 1];
uint64_t expected_csum;
printf("sb.magic\t\t");
if (!memcmp(&sb->magic, &BCACHE_MAGIC, sizeof(sb->magic))) {
printf("ok\n");
} else {
printf("bad magic\n");
die("Invalid superblock (bad magic)");
}
printf("sb.first_sector\t\t%ju", (uint64_t) sb->offset);
if (sb->offset == SB_SECTOR) {
printf(" [match]\n");
} else {
printf(" [expected %ds]\n", SB_SECTOR);
die("Invalid superblock (bad sector)");
}
printf("sb.csum\t\t\t%ju", (uint64_t) sb->csum);
expected_csum = csum_set(sb,
sb->version < BCACHE_SB_VERSION_CDEV_V3
? BCH_CSUM_CRC64
: CACHE_SB_CSUM_TYPE(sb));
if (sb->csum == expected_csum) {
printf(" [match]\n");
} else {
printf(" [expected %" PRIX64 "]\n", expected_csum);
if (force_csum)
die("Corrupt superblock (bad csum)");
}
printf("sb.version\t\t%ju", (uint64_t) sb->version);
switch (sb->version) {
// These are handled the same by the kernel
case BCACHE_SB_VERSION_CDEV:
case BCACHE_SB_VERSION_CDEV_WITH_UUID:
printf(" [cache device]\n");
break;
// The second adds data offset support
case BCACHE_SB_VERSION_BDEV:
case BCACHE_SB_VERSION_BDEV_WITH_OFFSET:
printf(" [backing device]\n");
break;
default:
printf(" [unknown]\n");
// exit code?
exit(EXIT_SUCCESS);
}
putchar('\n');
strncpy(label, (char *) sb->label, SB_LABEL_SIZE);
label[SB_LABEL_SIZE] = '\0';
printf("dev.label\t\t");
if (*label)
print_encode(label);
else
printf("(empty)");
putchar('\n');
uuid_unparse(sb->disk_uuid.b, uuid);
printf("dev.uuid\t\t%s\n", uuid);
uuid_unparse(sb->user_uuid.b, uuid);
printf("cset.uuid\t\t%s\n", uuid);
uuid_unparse(sb->set_uuid.b, uuid);
printf("internal.uuid\t%s\n", uuid);
}
void show_super_backingdev(struct cache_sb *sb, bool force_csum)
{
uint64_t first_sector;
show_super_common(sb, force_csum);
if (sb->version == BCACHE_SB_VERSION_BDEV) {
first_sector = BDEV_DATA_START_DEFAULT;
} else {
first_sector = sb->bdev_data_offset;
}
printf("dev.data.first_sector\t%ju\n"
"dev.data.cache_mode\t%s"
"dev.data.cache_state\t%s\n",
first_sector,
bdev_cache_mode[BDEV_CACHE_MODE(sb)],
bdev_state[BDEV_STATE(sb)]);
}
void show_super_cache(struct cache_sb *sb, bool force_csum)
{
struct cache_member *m = sb->members + sb->nr_this_dev;
char uuid[16];
show_super_common(sb, force_csum);
uuid_unparse(m->uuid.b, uuid);
printf("dev.cache.uuid\t%s\n", uuid);
printf("dev.sectors_per_block\t%u\n"
"dev.sectors_per_bucket\t%u\n",
sb->block_size,
m->bucket_size);
// total_sectors includes the superblock;
printf("dev.cache.first_sector\t%u\n"
"dev.cache.cache_sectors\t%llu\n"
"dev.cache.total_sectors\t%llu\n"
"dev.cache.ordered\t%s\n"
"dev.cache.pos\t\t%u\n"
"dev.cache.setsize\t\t%u\n",
m->bucket_size * m->first_bucket,
m->bucket_size * (m->nbuckets - m->first_bucket),
m->bucket_size * m->nbuckets,
CACHE_SYNC(sb) ? "yes" : "no",
sb->nr_this_dev,
sb->nr_in_set);
printf("cache.state\t%s\n", cache_state[CACHE_STATE(m)]);
printf("cache.tier\t%llu\n", CACHE_TIER(m));
printf("cache.replication_set\t%llu\n", CACHE_REPLICATION_SET(m));
printf("cache.has_metadata\t%llu\n", CACHE_HAS_METADATA(m));
printf("cache.has_data\t%llu\n", CACHE_HAS_DATA(m));
printf("cache.replacement\t%s\n", replacement_policies[CACHE_REPLACEMENT(m)]);
printf("cache.discard\t%llu\n", CACHE_DISCARD(m));
}
static int __sysfs_attr_type(const char *attr, const char * const *attr_arr)
{
for (unsigned i = 0; attr_arr[i] != NULL; i++)
if(!strcmp(attr, attr_arr[i]))
return 1;
return 0;
}
enum sysfs_attr sysfs_attr_type(const char *attr)
{
if(__sysfs_attr_type(attr, set_attrs))
return SET_ATTR;
if(__sysfs_attr_type(attr, cache_attrs))
return CACHE_ATTR;
if(__sysfs_attr_type(attr, internal_attrs))
return INTERNAL_ATTR;
printf("No attribute called %s, try --list to see options\n", attr);
return -1;
}
static void __sysfs_attr_list(const char * const *attr_arr)
{
for (unsigned i = 0; attr_arr[i] != NULL; i++)
printf("%s\n", attr_arr[i]);
}
void sysfs_attr_list()
{
__sysfs_attr_list(set_attrs);
__sysfs_attr_list(cache_attrs);
__sysfs_attr_list(internal_attrs);
}
struct cache_sb *query_dev(char *dev, bool force_csum,
bool print_sb, bool uuid_only, char *dev_uuid)
{
size_t bytes = 4096;
struct cache_sb *sb = aligned_alloc(bytes, bytes);
int fd = open(dev, O_RDONLY|O_DIRECT);
if (fd < 0) {
printf("Can't open dev %s: %s\n", dev, strerror(errno));
return NULL;
}
while (true) {
int ret = pread(fd, sb, bytes, SB_START);
if (ret < 0) {
fprintf(stderr, "Couldn't read superblock: %s\n",
strerror(errno));
close(fd);
free(sb);
return NULL;
} else if (bytes > sizeof(sb) + sb->u64s * sizeof(u64)) {
/* We read the whole superblock */
break;
}
/*
* otherwise double the size of our dest
* and read again
*/
free(sb);
bytes *= 2;
sb = aligned_alloc(4096, bytes);
}
close(fd);
if(uuid_only) {
show_uuid_only(sb, dev_uuid);
return sb;
}
if(print_sb) {
if (!SB_IS_BDEV(sb))
show_super_cache(sb, force_csum);
else
show_super_backingdev(sb, force_csum);
}
return sb;
}
char *dev_name(const char *ugly_path) {
char buf[32];
int i, end = strlen(ugly_path);
//Chop off "/bcache", then look for the next '/' from the end
for (i = end - 8; ; i--)
if(ugly_path[i] == '/')
break;
strcpy(buf, ugly_path + i);
buf[end - i - 7] = 0;
// Is the dev guaranteed to be in /dev?
// This is needed for finding the superblock with a query-dev
return strdup(buf);
}
char *find_matching_uuid(char *stats_dir, char *subdir, const char *stats_dev_uuid)
{
/* Do a query-dev --uuid only to get the uuid
* repeat on each dev until we find a matching one
* append that cache# to subdir and return
*/
int i = 0;
DIR *cachedir;
struct stat cache_stat;
char intbuf[4];
char entry[MAX_PATH];
char *err = NULL;
snprintf(entry, MAX_PATH, "%s%s", stats_dir, subdir);
snprintf(intbuf, 4, "%d", i);
strcat(entry, intbuf);
while(true) {
char buf[MAX_PATH];
int len;
if((cachedir = opendir(entry)) == NULL)
break;
if(stat(entry, &cache_stat))
break;
if((len = readlink(entry, buf, sizeof(buf) - 1)) != -1) {
char dev_uuid[40];
buf[len] = '\0';
int i, end = strlen(buf);
char tmp[32], devname[32];
struct cache_sb *sb;
/* Chop off "/bcache", then look for the
* next '/' from the end
*/
for (i = end - 8; ; i--)
if(buf[i] == '/')
break;
strcpy(tmp, buf + i);
tmp[end - i - 7] = 0;
strcpy(devname, "/dev");
strcat(devname, tmp);
err = "Unable to open superblock";
sb = query_dev(devname, false, false, true, dev_uuid);
if(!sb)
return err;
else
free(sb);
if(!strcmp(stats_dev_uuid, dev_uuid)) {
strcat(subdir, intbuf);
return NULL;
}
}
/* remove i from end and append i++ */
entry[strlen(entry)-strlen(intbuf)] = 0;
i++;
snprintf(intbuf, 4, "%d", i);
strcat(entry, intbuf);
}
err = "dev uuid doesn't exist in cache_set";
return err;
}
int bcachectl_open(void)
{
int fd = open("/dev/bcache-ctl", O_RDWR);
if (fd < 0)
die("Can't open bcache device: %s", strerror(errno));
return fd;
}
unsigned nr_args(char *const *args)
{
unsigned i;
for (i = 0; args[i]; i++)
;
return i;
}

101
bcache.h
View File

@ -1,5 +1,5 @@
/*
* Author: Kent Overstreet <kmo@daterainc.com>
* Author: Kent Overstreet <kent.overstreet@gmail.com>
*
* GPLv2
*/
@ -7,54 +7,7 @@
#ifndef _BCACHE_H
#define _BCACHE_H
#include <stdint.h>
#include <dirent.h>
#define __packed __attribute__((__packed__))
#include "bcache-ondisk.h"
#include "bcache-ioctl.h"
typedef __u8 u8;
typedef __u16 u16;
typedef __u32 u32;
typedef __u64 u64;
typedef __s8 s8;
typedef __s16 s16;
typedef __s32 s32;
typedef __s64 s64;
#define SB_START (SB_SECTOR * 512)
#define MAX_PATH 256
#define MAX_DEVS MAX_CACHES_PER_SET
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#define __bkey_idx(_set, _offset) \
((_set)->_data + (_offset))
#define bkey_idx(_set, _offset) \
((typeof(&(_set)->start[0])) __bkey_idx((_set), (_offset)))
#define bkey_next(_k) \
((typeof(_k)) __bkey_idx(_k, (_k)->u64s))
#define __bset_bkey_last(_set) \
__bkey_idx((_set), (_set)->u64s)
#define bset_bkey_last(_set) \
bkey_idx((_set), (_set)->u64s)
#include "util.h"
extern const char * const cache_state[];
extern const char * const replacement_policies[];
@ -63,53 +16,5 @@ extern const char * const compression_types[];
extern const char * const error_actions[];
extern const char * const bdev_cache_mode[];
extern const char * const bdev_state[];
extern const char * const set_attr[];
extern const char * const cache_attrs[];
extern const char * const internal_attrs[];
ssize_t read_string_list(const char *, const char * const[]);
ssize_t read_string_list_or_die(const char *, const char * const[],
const char *);
void print_string_list(const char * const[], size_t);
uint64_t bch_checksum(unsigned, const void *, size_t);
uint64_t getblocks(int);
uint64_t hatoi(const char *);
unsigned hatoi_validate(const char *, const char *);
int dev_open(const char *);
unsigned get_blocksize(const char *, int);
long strtoul_or_die(const char *, size_t, const char *);
void show_super_backingdev(struct cache_sb *, bool);
void show_super_cache(struct cache_sb *, bool);
enum sysfs_attr {SET_ATTR, CACHE_ATTR, INTERNAL_ATTR};
enum sysfs_attr sysfs_attr_type(const char *attr);
void sysfs_attr_list();
struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
char *parse_array_to_list(char *const *);
char *register_bcache(char *const *);
char *find_matching_uuid(char *, char *, const char*);
char *dev_name(const char *);
int bcachectl_open(void);
unsigned nr_args(char * const *);
#define csum_set(i, type) \
({ \
void *start = ((void *) (i)) + sizeof(uint64_t); \
void *end = __bset_bkey_last(i); \
\
bch_checksum(type, start, end - start); \
})
#define die(arg, ...) \
do { \
fprintf(stderr, arg "\n", ##__VA_ARGS__); \
exit(EXIT_FAILURE); \
} while (0)
#endif
#endif /* _BCACHE_H */

View File

@ -1,7 +0,0 @@
#ifndef _BCACHEADM_FORMAT_H
#define _BCACHEADM_FORMAT_H
extern NihOption opts_format[];
int cmd_format(NihCommand *, char * const *);
#endif /* _BCACHEADM_FORMAT_H */

View File

@ -1,359 +0,0 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <nih/command.h>
#include <nih/option.h>
#include <uuid/uuid.h>
#include "bcache.h"
#include "bcacheadm-query.h"
static char *cset_dir = "/sys/fs/bcache";
static bool list_devs = false;
static const char *internal_uuid = NULL;
NihOption opts_list[] = {
{'d', "dir", N_("directory"), NULL, NULL, &cset_dir, NULL},
{0, "list-devs", N_("list all devices in the cache sets as well"), NULL, NULL, &list_devs, NULL},
{0, "internal_uuid", N_("Show the internal UUID for the given cacheset UUID"), NULL, "UUID", &internal_uuid, NULL},
NIH_OPTION_LAST
};
static void list_cacheset_devs(char *cset_dir, char *cset_name, bool parse_dev_name)
{
DIR *cachedir, *dir;
struct stat cache_stat;
char entry[MAX_PATH];
struct dirent *ent;
snprintf(entry, MAX_PATH, "%s/%s", cset_dir, cset_name);
if((dir = opendir(entry)) != NULL) {
while((ent = readdir(dir)) != NULL) {
char buf[MAX_PATH];
int len;
char *tmp;
/*
* We are looking for all cache# directories
* do a strlen < 9 to skip over other entries
* that also start with "cache"
*/
if(strncmp(ent->d_name, "cache", 5) ||
!(strlen(ent->d_name) < 9))
continue;
snprintf(entry, MAX_PATH, "%s/%s/%s",
cset_dir,
cset_name,
ent->d_name);
if((cachedir = opendir(entry)) == NULL)
continue;
if(stat(entry, &cache_stat))
continue;
if((len = readlink(entry, buf, sizeof(buf) - 1)) !=
-1) {
buf[len] = '\0';
if(parse_dev_name) {
tmp = dev_name(buf);
printf("/dev%s\n", tmp);
free(tmp);
} else {
printf("\t%s\n", buf);
}
}
}
}
}
static char *list_cachesets(char *cset_dir, bool list_devs)
{
struct dirent *ent;
DIR *dir;
char *err = NULL;
dir = opendir(cset_dir);
if (!dir) {
err = "Failed to open cacheset dir";
goto err;
}
while ((ent = readdir(dir)) != NULL) {
struct stat statbuf;
char entry[MAX_PATH];
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
snprintf(entry, MAX_PATH, "%s/%s", cset_dir, ent->d_name);
if(stat(entry, &statbuf) == -1) {
err = "Failed to stat cacheset subdir";
goto err;
}
if (S_ISDIR(statbuf.st_mode)) {
printf("%s\n", ent->d_name);
if(list_devs) {
list_cacheset_devs(cset_dir, ent->d_name, true);
}
}
}
err:
closedir(dir);
return err;
}
static char *read_stat_dir(DIR *dir, char *stats_dir, char *stat_name, char *ret)
{
struct stat statbuf;
char entry[MAX_PATH];
char *err = NULL;
snprintf(entry, MAX_PATH, "%s/%s", stats_dir, stat_name);
if(stat(entry, &statbuf) == -1) {
char tmp[MAX_PATH];
snprintf(tmp, MAX_PATH, "Failed to stat %s\n", entry);
err = strdup(tmp);
goto err;
}
if (S_ISREG(statbuf.st_mode)) {
FILE *fp = NULL;
fp = fopen(entry, "r");
if(!fp) {
/* If we can't open the file, this is probably because
* of permissions, just move to the next file */
return NULL;
}
while(fgets(ret, MAX_PATH, fp));
fclose(fp);
}
err:
return err;
}
int cmd_list(NihCommand *command, char *const *args)
{
char *err = NULL;
if (internal_uuid) {
char uuid_path[MAX_PATH];
DIR *uuid_dir;
char buf[MAX_PATH];
snprintf(uuid_path, MAX_PATH, "%s/%s", cset_dir, internal_uuid);
err = "uuid does not exist";
if((uuid_dir = opendir(uuid_path)) == NULL)
goto err;
err = read_stat_dir(uuid_dir, uuid_path, "/internal/internal_uuid", buf);
if (err)
goto err;
printf("%s", buf);
return 0;
}
err = list_cachesets(cset_dir, list_devs);
if (err)
goto err;
return 0;
err:
printf("bcache_list_cachesets error :%s\n", err);
return -1;
}
static bool force_csum = false;
static bool uuid_only = false;
static bool query_brief = false;
NihOption opts_query[] = {
{'f', "force_csum", N_("force_csum"), NULL, NULL, &force_csum, NULL},
{'u', "uuid-only", N_("only print out the uuid for the devices, not the whole superblock"), NULL, NULL, &uuid_only, NULL},
{'b', "brief", N_("only print out the cluster,server,and disk uuids"), NULL, NULL, &query_brief, NULL},
NIH_OPTION_LAST
};
int cmd_query(NihCommand *command, char *const *args)
{
int i;
if (query_brief)
printf("%-10s%-40s%-40s%-40s\n", "dev name", "disk uuid",
"server uuid", "cluster uuid");
for (i = 0; args[i] != NULL; i++) {
char dev_uuid[40];
struct cache_sb *sb = query_dev(args[i], force_csum,
!query_brief, uuid_only, dev_uuid);
if (!sb) {
printf("error opening the superblock for %s\n",
args[i]);
return -1;
}
if (uuid_only) {
printf("%s\n", dev_uuid);
} else if (query_brief) {
char set_uuid_str[40], dev_uuid_str[40];
char *clus_uuid = (char *)sb->label;
uuid_unparse(sb->user_uuid.b, set_uuid_str);
uuid_unparse(sb->disk_uuid.b, dev_uuid_str);
if (!strcmp(clus_uuid, ""))
clus_uuid = "None";
printf("%-10s%-40s%-40s%-40s\n", args[i],
dev_uuid_str,
set_uuid_str,
clus_uuid);
}
free(sb);
}
return 0;
}
static bool status_all = false;
NihOption opts_status[] = {
{'a', "all", N_("all"), NULL, NULL, &status_all, NULL},
NIH_OPTION_LAST
};
int cmd_status(NihCommand *command, char *const *args)
{
int i, dev_count = 0, seq, cache_count = 0;
struct cache_sb *seq_sb = NULL;
char cache_path[MAX_PATH];
char *dev_names[MAX_DEVS];
char *dev_uuids[MAX_DEVS];
char intbuf[4];
char set_uuid[40];
for (i = 0; args[i] != NULL; i++) {
struct cache_sb *sb = query_dev(args[i], false, false,
false, NULL);
if (!sb) {
printf("Unable to open superblock, bad path\n");
return -1;
}
if (!seq_sb || sb->seq > seq) {
seq = sb->seq;
seq_sb = sb;
} else
free(sb);
}
if (!seq_sb) {
printf("Unable to find a superblock\n");
return -1;
} else {
uuid_unparse(seq_sb->user_uuid.b, set_uuid);
printf("%-50s%-15s%-4s\n", "uuid", "state", "tier");
}
snprintf(intbuf, 4, "%d", i);
snprintf(cache_path, MAX_PATH, "%s/%s/%s", cset_dir, set_uuid,
"cache0");
/*
* Get a list of all the devices from sysfs first, then
* compare it to the list we get back from the most up
* to date superblock. If there are any devices in the superblock
* that are not in sysfs, print out 'missing'
*/
while (true) {
char buf[MAX_PATH];
int len;
DIR *cache_dir;
if(((cache_dir = opendir(cache_path)) == NULL) &&
cache_count > MAX_DEVS)
break;
if (cache_dir)
closedir(cache_dir);
if((len = readlink(cache_path, buf, sizeof(buf) - 1)) != -1) {
struct cache_sb *sb;
char dev_uuid[40];
char dev_path[32];
buf[len] = '\0';
dev_names[dev_count] = dev_name(buf);
snprintf(dev_path, sizeof(dev_path), "%s/%s", "/dev",
dev_names[dev_count]);
sb = query_dev(dev_path, false, false,
true, dev_uuid);
if (!sb) {
printf("error reading %s\n", dev_path);
return -1;
} else
free(sb);
dev_uuids[dev_count] = strdup(dev_uuid);
dev_count++;
}
cache_path[strlen(cache_path) - strlen(intbuf)] = 0;
cache_count++;
snprintf(intbuf, 4, "%d", cache_count);
strcat(cache_path, intbuf);
}
for (i = 0; i < seq_sb->nr_in_set; i++) {
char uuid_str[40];
struct cache_member *m = seq_sb->members + i;
char dev_state[32];
int j;
uuid_unparse(m->uuid.b, uuid_str);
snprintf(dev_state, sizeof(dev_state), "%s",
cache_state[CACHE_STATE(m)]);
for (j = 0; j < dev_count; j++) {
if (!strcmp(uuid_str, dev_uuids[j])) {
break;
} else if (j == dev_count - 1) {
if (!strcmp(cache_state[CACHE_STATE(m)], "active"))
snprintf(dev_state, sizeof(dev_state), "%s", "missing");
break;
}
}
printf("%-50s%-15s%-4llu\n", uuid_str, dev_state,
CACHE_TIER(m));
}
if (seq_sb)
free(seq_sb);
for (i = 0; i < dev_count; i++) {
free(dev_names[i]);
free(dev_uuids[i]);
}
return 0;
}

View File

@ -1,13 +0,0 @@
#ifndef _BCACHEADM_QUERY_H
#define _BCACHEADM_QUERY_H
extern NihOption opts_list[];
int cmd_list(NihCommand *, char * const *);
extern NihOption opts_query[];
int cmd_query(NihCommand *, char * const *);
extern NihOption opts_status[];
int cmd_status(NihCommand *, char * const *);
#endif /* _BCACHEADM_QUERY_H */

View File

@ -1,151 +0,0 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <nih/command.h>
#include <nih/option.h>
#include <uuid/uuid.h>
#include "bcache.h"
#include "bcacheadm-run.h"
static bool force_data = false;
static bool force_metadata = false;
NihOption opts_run[] = {
NIH_OPTION_LAST
};
int cmd_run(NihCommand *command, char *const *args)
{
return 0;
}
NihOption opts_stop[] = {
NIH_OPTION_LAST
};
int cmd_stop(NihCommand *command, char *const *args)
{
int bcachefd = open("/dev/bcache_extent0", O_RDWR);
if (bcachefd < 0)
die("Can't open bcache device");
int ret = ioctl(bcachefd, BCH_IOCTL_STOP);
if (ret < 0)
die("BCH_IOCTL_STOP error: %s", strerror(errno));
close(bcachefd);
return 0;
}
NihOption opts_add[] = {
NIH_OPTION_LAST
};
int cmd_add(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply exactly one device");
int ret, bcachefd;
bcachefd = open("/dev/bcache_extent0", O_RDWR);
if (bcachefd < 0)
die("Can't open bcache device: %s", strerror(errno));
struct bch_ioctl_disk_add ia = {
.dev = (__u64) args[0],
};
ret = ioctl(bcachefd, BCH_IOCTL_DISK_ADD, &ia);
if (ret < 0)
die("BCH_IOCTL_DISK_ADD error: %s", strerror(ret));
close(bcachefd);
return 0;
}
NihOption opts_readd[] = {
NIH_OPTION_LAST
};
int cmd_readd(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply exactly one device");
return 0;
}
NihOption opts_remove[] = {
{
'f', "force", N_("force if data present"),
NULL, NULL, &force_data, NULL
},
{
'\0', "force-metadata", N_("force if metadata present"),
NULL, NULL, &force_metadata, NULL},
NIH_OPTION_LAST
};
int cmd_remove(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply exactly one device");
int bcachefd = open("/dev/bcache_extent0", O_RDWR);
if (bcachefd < 0)
die("Can't open bcache device");
struct bch_ioctl_disk_remove ir = {
.dev = (__u64) args[0],
};
if (force_data)
ir.flags |= BCH_FORCE_IF_DATA_MISSING;
if (force_metadata)
ir.flags |= BCH_FORCE_IF_METADATA_MISSING;
int ret = ioctl(bcachefd, BCH_IOCTL_DISK_REMOVE, &ir);
if (ret < 0)
die("BCH_IOCTL_DISK_REMOVE error: %s\n", strerror(errno));
close(bcachefd);
return 0;
}
static const char *dev_failed_uuid = NULL;
NihOption opts_fail[] = {
{'d', "dev", N_("dev UUID"), NULL, "UUID", &dev_failed_uuid, NULL},
NIH_OPTION_LAST
};
int cmd_fail(NihCommand *command, char *const *args)
{
if (nr_args(args) != 1)
die("Please supply exactly one device");
int bcachefd = open("/dev/bcache_extent0", O_RDWR);
if (bcachefd < 0)
die("Can't open bcache device");
struct bch_ioctl_disk_fail df = {
.dev = (__u64) args[0],
};
int ret = ioctl(bcachefd, BCH_IOCTL_DISK_FAIL, &df);
if (ret < 0)
die("BCH_IOCTL_DISK_FAIL error: %s\n", strerror(errno));
return 0;
}

View File

@ -1,22 +0,0 @@
#ifndef _BCACHEADM_RUN_H
#define _BCACHEADM_RUN_H
extern NihOption opts_run[];
int cmd_run(NihCommand *, char * const *);
extern NihOption opts_stop[];
int cmd_stop(NihCommand *, char * const *);
extern NihOption opts_add[];
int cmd_add(NihCommand *, char * const *);
extern NihOption opts_readd[];
int cmd_readd(NihCommand *, char * const *);
extern NihOption opts_remove[];
int cmd_remove(NihCommand *, char * const *);
extern NihOption opts_fail[];
int cmd_fail(NihCommand *, char * const *);
#endif /* _BCACHEADM_RUN_H */

View File

@ -1,204 +0,0 @@
/*
* Authors: Kent Overstreet <kmo@daterainc.com>
* Gabriel de Perthuis <g2p.code@gmail.com>
* Jacob Malevich <jam@datera.io>
*
* GPLv2
*/
#include <nih/option.h>
#include <nih/command.h>
#include <nih/main.h>
#include <nih/logging.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#include <blkid.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <uuid/uuid.h>
#include <dirent.h>
#include "bcache.h"
#include "bcacheadm-format.h"
#include "bcacheadm-assemble.h"
#include "bcacheadm-run.h"
#include "bcacheadm-query.h"
#define PACKAGE_NAME "bcacheadm"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_BUGREPORT "linux-bcache@vger.kernel.org"
#if 0
static bool modify_list_attrs = false;
static const char *modify_set_uuid = NULL;
static const char *modify_dev_uuid = NULL;
static NihOption bcache_modify_options[] = {
{'l', "list", N_("list attributes"), NULL, NULL, &modify_list_attrs, NULL},
{'u', "set", N_("cacheset uuid"), NULL, "UUID", &modify_set_uuid, NULL},
{'d', "dev", N_("device uuid"), NULL, "UUID", &modify_dev_uuid, NULL},
NIH_OPTION_LAST
};
int bcache_modify(NihCommand *command, char *const *args)
{
char *err;
char path[MAX_PATH];
char *attr = args[0];
char *val = NULL;
int fd = -1;
if (modify_list_attrs) {
sysfs_attr_list();
return 0;
}
if (!modify_set_uuid) {
printf("Must provide a cacheset uuid\n");
return -1;
}
snprintf(path, MAX_PATH, "%s/%s", cset_dir, modify_set_uuid);
if(!attr) {
printf("Must provide the name of an attribute to modify\n");
goto err;
}
enum sysfs_attr type = sysfs_attr_type(attr);
if (type == -1)
goto err;
else if(type == INTERNAL_ATTR)
strcat(path, "/internal");
else if(type == CACHE_ATTR) {
if(modify_dev_uuid) {
/* searches all cache# for a matching uuid,
* path gets modified to the correct cache path */
char subdir[10] = "/cache";
err = find_matching_uuid(path, subdir,
modify_dev_uuid);
if (err) {
printf("Failed to find "
"matching dev %s\n", err);
goto err;
} else {
strcat(path, subdir);
}
} else {
printf("Must provide a device uuid\n");
}
}
/* SET_ATTRs are just in the current dir */
strcat(path, "/");
strcat(path, attr);
val = args[1];
if (!val) {
printf("Must provide a value to change the attribute to\n");
goto err;
}
fd = open(path, O_WRONLY);
if (fd < 0) {
printf("Unable to open modify attr with path %s\n", path);
goto err;
}
write(fd, val, strlen(val));
err:
if(fd)
close(fd);
return 0;
}
#endif
#define CMD(_command, _usage, _synopsis, _help) \
{ \
.command = #_command, \
.usage = _usage, \
.synopsis = _synopsis, \
.help = _help, \
.group = NULL, \
.options = opts_##_command, \
.action = cmd_##_command, \
}
static NihCommand commands[] = {
CMD(format, N_("<list of devices>"),
"Create a new bcache volume from one or more devices",
N_("format drive[s] for bcache")),
CMD(assemble, N_("<devices>"),
"Assembles one or more devices into a bcache volume",
N_("Registers a list of devices")),
CMD(incremental, N_("<device"),
"Incremental assemble bcache volumes",
N_("Incrementally registers a single device")),
CMD(run, N_("<volume>"),
"Start a partially assembled volume",
N_("Registers a list of devices")),
CMD(stop, N_("<volume>"),
"Stops a running bcache volume",
N_("Unregisters a list of devices")),
CMD(add, N_("<volume> <devices>"),
"Adds a list of devices to a volume",
N_("Adds a list of devices to a volume")),
CMD(readd, N_("<volume> <devices>"),
"Adds previously used members of a volume",
N_("Adds a list of devices to a volume")),
CMD(remove, N_("<volume> <devices>"),
"Removes a device from its volume",
N_("Removes a device from its volume")),
CMD(fail, N_("<volume> <devices>"),
"Sets a device to the FAILED state",
N_("Sets a device to the FAILED state")),
#if 0
CMD(modify, N_("<options>"),
"Modifies attributes related to the volume",
N_("Modifies attributes related to the volume")),
#endif
CMD(list, N_("list-cachesets"),
"Lists cachesets in /sys/fs/bcache",
N_("Lists cachesets in /sys/fs/bcache")),
CMD(query, N_("query <list of devices>"),
"Gives info about the superblock of a list of devices",
N_("show superblock on each of the listed drive")),
CMD(status, N_("status <list of devices>"),
"Finds the status of the most up to date superblock",
N_("Finds the status of the most up to date superblock")),
NIH_COMMAND_LAST
};
static NihOption options[] = {
NIH_OPTION_LAST
};
int main(int argc, char *argv[])
{
nih_main_init(argv[0]);
nih_option_set_synopsis(_("Manage bcache devices"));
nih_option_set_help( _("Helps you manage bcache devices"));
int ret = nih_command_parser(NULL, argc, argv, options, commands);
if (ret < 0)
exit(EXIT_FAILURE);
nih_signal_reset();
return 0;
}

28
ccan/array_size/LICENSE Normal file
View File

@ -0,0 +1,28 @@
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
moral rights retained by the original author(s) and/or performer(s);
publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
rights protecting the extraction, dissemination, use and reuse of data in a Work;
database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

46
ccan/array_size/_info Normal file
View File

@ -0,0 +1,46 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* array_size - routine for safely deriving the size of a visible array.
*
* This provides a simple ARRAY_SIZE() macro, which (given a good compiler)
* will also break compile if you try to use it on a pointer.
*
* This can ensure your code is robust to changes, without needing a gratuitous
* macro or constant.
*
* Example:
* // Outputs "Initialized 32 values\n"
* #include <ccan/array_size/array_size.h>
* #include <stdlib.h>
* #include <stdio.h>
*
* // We currently use 32 random values.
* static unsigned int vals[32];
*
* int main(void)
* {
* unsigned int i;
* for (i = 0; i < ARRAY_SIZE(vals); i++)
* vals[i] = random();
* printf("Initialized %u values\n", i);
* return 0;
* }
*
* License: CC0 (Public domain)
* Author: Rusty Russell <rusty@rustcorp.com.au>
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/build_assert\n");
return 0;
}
return 1;
}

View File

@ -0,0 +1,26 @@
/* CC0 (Public domain) - see LICENSE file for details */
#ifndef CCAN_ARRAY_SIZE_H
#define CCAN_ARRAY_SIZE_H
#include "config.h"
#include <ccan/build_assert/build_assert.h>
/**
* ARRAY_SIZE - get the number of elements in a visible array
* @arr: the array whose size you want.
*
* This does not work on pointers, or arrays declared as [], or
* function parameters. With correct compiler support, such usage
* will cause a build error (see build_assert).
*/
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
#if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF
/* Two gcc extensions.
* &a[0] degrades to a pointer: a different type from an array */
#define _array_size_chk(arr) \
BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
typeof(&(arr)[0])))
#else
#define _array_size_chk(arr) 0
#endif
#endif /* CCAN_ALIGNOF_H */

View File

@ -0,0 +1,24 @@
#include <ccan/array_size/array_size.h>
#include <stdlib.h>
struct foo {
unsigned int a, b;
};
int check_parameter(const struct foo *array);
int check_parameter(const struct foo *array)
{
#ifdef FAIL
return (ARRAY_SIZE(array) == 4);
#if !HAVE_TYPEOF || !HAVE_BUILTIN_TYPES_COMPATIBLE_P
#error "Unfortunately we don't fail if _array_size_chk is a noop."
#endif
#else
return sizeof(array) == 4 * sizeof(struct foo);
#endif
}
int main(int argc, char *argv[])
{
return check_parameter(NULL);
}

View File

@ -0,0 +1,14 @@
#include <ccan/array_size/array_size.h>
int main(int argc, char *argv[8])
{
char array[100];
#ifdef FAIL
return ARRAY_SIZE(argv) + ARRAY_SIZE(array);
#if !HAVE_TYPEOF || !HAVE_BUILTIN_TYPES_COMPATIBLE_P
#error "Unfortunately we don't fail if _array_size_chk is a noop."
#endif
#else
return ARRAY_SIZE(array);
#endif
}

View File

@ -0,0 +1,33 @@
#include <ccan/array_size/array_size.h>
#include <ccan/tap/tap.h>
static char array1[1];
static int array2[2];
static unsigned long array3[3][5];
struct foo {
unsigned int a, b;
char string[100];
};
static struct foo array4[4];
/* Make sure they can be used in initializers. */
static int array1_size = ARRAY_SIZE(array1);
static int array2_size = ARRAY_SIZE(array2);
static int array3_size = ARRAY_SIZE(array3);
static int array4_size = ARRAY_SIZE(array4);
int main(int argc, char *argv[])
{
plan_tests(8);
ok1(array1_size == 1);
ok1(array2_size == 2);
ok1(array3_size == 3);
ok1(array4_size == 4);
ok1(ARRAY_SIZE(array1) == 1);
ok1(ARRAY_SIZE(array2) == 2);
ok1(ARRAY_SIZE(array3) == 3);
ok1(ARRAY_SIZE(array4) == 4);
return exit_status();
}

28
ccan/build_assert/LICENSE Normal file
View File

@ -0,0 +1,28 @@
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
moral rights retained by the original author(s) and/or performer(s);
publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
rights protecting the extraction, dissemination, use and reuse of data in a Work;
database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

49
ccan/build_assert/_info Normal file
View File

@ -0,0 +1,49 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* build_assert - routines for build-time assertions
*
* This code provides routines which will cause compilation to fail should some
* assertion be untrue: such failures are preferable to run-time assertions,
* but much more limited since they can only depends on compile-time constants.
*
* These assertions are most useful when two parts of the code must be kept in
* sync: it is better to avoid such cases if possible, but seconds best is to
* detect invalid changes at build time.
*
* For example, a tricky piece of code might rely on a certain element being at
* the start of the structure. To ensure that future changes don't break it,
* you would catch such changes in your code like so:
*
* Example:
* #include <stddef.h>
* #include <ccan/build_assert/build_assert.h>
*
* struct foo {
* char string[5];
* int x;
* };
*
* static char *foo_string(struct foo *foo)
* {
* // This trick requires that the string be first in the structure
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
* return (char *)foo;
* }
*
* License: CC0 (Public domain)
* Author: Rusty Russell <rusty@rustcorp.com.au>
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0)
/* Nothing. */
return 0;
return 1;
}

View File

@ -0,0 +1,40 @@
/* CC0 (Public domain) - see LICENSE file for details */
#ifndef CCAN_BUILD_ASSERT_H
#define CCAN_BUILD_ASSERT_H
/**
* BUILD_ASSERT - assert a build-time dependency.
* @cond: the compile-time condition which must be true.
*
* Your compile will fail if the condition isn't true, or can't be evaluated
* by the compiler. This can only be used within a function.
*
* Example:
* #include <stddef.h>
* ...
* static char *foo_to_char(struct foo *foo)
* {
* // This code needs string to be at start of foo.
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
* return (char *)foo;
* }
*/
#define BUILD_ASSERT(cond) \
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
/**
* BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
* @cond: the compile-time condition which must be true.
*
* Your compile will fail if the condition isn't true, or can't be evaluated
* by the compiler. This can be used in an expression: its value is "0".
*
* Example:
* #define foo_to_char(foo) \
* ((char *)(foo) \
* + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
*/
#define BUILD_ASSERT_OR_ZERO(cond) \
(sizeof(char [1 - 2*!(cond)]) - 1)
#endif /* CCAN_BUILD_ASSERT_H */

View File

@ -0,0 +1,10 @@
#include <ccan/build_assert/build_assert.h>
int main(int argc, char *argv[])
{
#ifdef FAIL
return BUILD_ASSERT_OR_ZERO(1 == 0);
#else
return 0;
#endif
}

View File

@ -0,0 +1,9 @@
#include <ccan/build_assert/build_assert.h>
int main(int argc, char *argv[])
{
#ifdef FAIL
BUILD_ASSERT(1 == 0);
#endif
return 0;
}

View File

@ -0,0 +1,7 @@
#include <ccan/build_assert/build_assert.h>
int main(int argc, char *argv[])
{
BUILD_ASSERT(1 == 1);
return 0;
}

View File

@ -0,0 +1,9 @@
#include <ccan/build_assert/build_assert.h>
#include <ccan/tap/tap.h>
int main(int argc, char *argv[])
{
plan_tests(1);
ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
return exit_status();
}

28
ccan/compiler/LICENSE Normal file
View File

@ -0,0 +1,28 @@
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
moral rights retained by the original author(s) and/or performer(s);
publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
rights protecting the extraction, dissemination, use and reuse of data in a Work;
database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

64
ccan/compiler/_info Normal file
View File

@ -0,0 +1,64 @@
#include "config.h"
#include <string.h>
#include <stdio.h>
/**
* compiler - macros for common compiler extensions
*
* Abstracts away some compiler hints. Currently these include:
* - COLD
* For functions not called in fast paths (aka. cold functions)
* - PRINTF_FMT
* For functions which take printf-style parameters.
* - CONST_FUNCTION
* For functions which return the same value for same parameters.
* - NEEDED
* For functions and variables which must be emitted even if unused.
* - UNNEEDED
* For functions and variables which need not be emitted if unused.
* - UNUSED
* For parameters which are not used.
* - IS_COMPILE_CONSTANT()
* For using different tradeoffs for compiletime vs runtime evaluation.
*
* License: CC0 (Public domain)
* Author: Rusty Russell <rusty@rustcorp.com.au>
*
* Example:
* #include <ccan/compiler/compiler.h>
* #include <stdio.h>
* #include <stdarg.h>
*
* // Example of a (slow-path) logging function.
* static int log_threshold = 2;
* static void COLD PRINTF_FMT(2,3)
* logger(int level, const char *fmt, ...)
* {
* va_list ap;
* va_start(ap, fmt);
* if (level >= log_threshold)
* vfprintf(stderr, fmt, ap);
* va_end(ap);
* }
*
* int main(int argc, char *argv[])
* {
* if (argc != 1) {
* logger(3, "Don't want %i arguments!\n", argc-1);
* return 1;
* }
* return 0;
* }
*/
int main(int argc, char *argv[])
{
/* Expect exactly one argument */
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
return 0;
}
return 1;
}

231
ccan/compiler/compiler.h Normal file
View File

@ -0,0 +1,231 @@
/* CC0 (Public domain) - see LICENSE file for details */
#ifndef CCAN_COMPILER_H
#define CCAN_COMPILER_H
#include "config.h"
#ifndef COLD
#if HAVE_ATTRIBUTE_COLD
/**
* COLD - a function is unlikely to be called.
*
* Used to mark an unlikely code path and optimize appropriately.
* It is usually used on logging or error routines.
*
* Example:
* static void COLD moan(const char *reason)
* {
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
* }
*/
#define COLD __attribute__((__cold__))
#else
#define COLD
#endif
#endif
#ifndef NORETURN
#if HAVE_ATTRIBUTE_NORETURN
/**
* NORETURN - a function does not return
*
* Used to mark a function which exits; useful for suppressing warnings.
*
* Example:
* static void NORETURN fail(const char *reason)
* {
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
* exit(1);
* }
*/
#define NORETURN __attribute__((__noreturn__))
#else
#define NORETURN
#endif
#endif
#ifndef PRINTF_FMT
#if HAVE_ATTRIBUTE_PRINTF
/**
* PRINTF_FMT - a function takes printf-style arguments
* @nfmt: the 1-based number of the function's format argument.
* @narg: the 1-based number of the function's first variable argument.
*
* This allows the compiler to check your parameters as it does for printf().
*
* Example:
* void PRINTF_FMT(2,3) my_printf(const char *prefix, const char *fmt, ...);
*/
#define PRINTF_FMT(nfmt, narg) \
__attribute__((format(__printf__, nfmt, narg)))
#else
#define PRINTF_FMT(nfmt, narg)
#endif
#endif
#ifndef CONST_FUNCTION
#if HAVE_ATTRIBUTE_CONST
/**
* CONST_FUNCTION - a function's return depends only on its argument
*
* This allows the compiler to assume that the function will return the exact
* same value for the exact same arguments. This implies that the function
* must not use global variables, or dereference pointer arguments.
*/
#define CONST_FUNCTION __attribute__((__const__))
#else
#define CONST_FUNCTION
#endif
#ifndef PURE_FUNCTION
#if HAVE_ATTRIBUTE_PURE
/**
* PURE_FUNCTION - a function is pure
*
* A pure function is one that has no side effects other than it's return value
* and uses no inputs other than it's arguments and global variables.
*/
#define PURE_FUNCTION __attribute__((__pure__))
#else
#define PURE_FUNCTION
#endif
#endif
#endif
#if HAVE_ATTRIBUTE_UNUSED
#ifndef UNNEEDED
/**
* UNNEEDED - a variable/function may not be needed
*
* This suppresses warnings about unused variables or functions, but tells
* the compiler that if it is unused it need not emit it into the source code.
*
* Example:
* // With some preprocessor options, this is unnecessary.
* static UNNEEDED int counter;
*
* // With some preprocessor options, this is unnecessary.
* static UNNEEDED void add_to_counter(int add)
* {
* counter += add;
* }
*/
#define UNNEEDED __attribute__((__unused__))
#endif
#ifndef NEEDED
#if HAVE_ATTRIBUTE_USED
/**
* NEEDED - a variable/function is needed
*
* This suppresses warnings about unused variables or functions, but tells
* the compiler that it must exist even if it (seems) unused.
*
* Example:
* // Even if this is unused, these are vital for debugging.
* static NEEDED int counter;
* static NEEDED void dump_counter(void)
* {
* printf("Counter is %i\n", counter);
* }
*/
#define NEEDED __attribute__((__used__))
#else
/* Before used, unused functions and vars were always emitted. */
#define NEEDED __attribute__((__unused__))
#endif
#endif
#ifndef UNUSED
/**
* UNUSED - a parameter is unused
*
* Some compilers (eg. gcc with -W or -Wunused) warn about unused
* function parameters. This suppresses such warnings and indicates
* to the reader that it's deliberate.
*
* Example:
* // This is used as a callback, so needs to have this prototype.
* static int some_callback(void *unused UNUSED)
* {
* return 0;
* }
*/
#define UNUSED __attribute__((__unused__))
#endif
#else
#ifndef UNNEEDED
#define UNNEEDED
#endif
#ifndef NEEDED
#define NEEDED
#endif
#ifndef UNUSED
#define UNUSED
#endif
#endif
#ifndef IS_COMPILE_CONSTANT
#if HAVE_BUILTIN_CONSTANT_P
/**
* IS_COMPILE_CONSTANT - does the compiler know the value of this expression?
* @expr: the expression to evaluate
*
* When an expression manipulation is complicated, it is usually better to
* implement it in a function. However, if the expression being manipulated is
* known at compile time, it is better to have the compiler see the entire
* expression so it can simply substitute the result.
*
* This can be done using the IS_COMPILE_CONSTANT() macro.
*
* Example:
* enum greek { ALPHA, BETA, GAMMA, DELTA, EPSILON };
*
* // Out-of-line version.
* const char *greek_name(enum greek greek);
*
* // Inline version.
* static inline const char *_greek_name(enum greek greek)
* {
* switch (greek) {
* case ALPHA: return "alpha";
* case BETA: return "beta";
* case GAMMA: return "gamma";
* case DELTA: return "delta";
* case EPSILON: return "epsilon";
* default: return "**INVALID**";
* }
* }
*
* // Use inline if compiler knows answer. Otherwise call function
* // to avoid copies of the same code everywhere.
* #define greek_name(g) \
* (IS_COMPILE_CONSTANT(greek) ? _greek_name(g) : greek_name(g))
*/
#define IS_COMPILE_CONSTANT(expr) __builtin_constant_p(expr)
#else
/* If we don't know, assume it's not. */
#define IS_COMPILE_CONSTANT(expr) 0
#endif
#endif
#ifndef WARN_UNUSED_RESULT
#if HAVE_WARN_UNUSED_RESULT
/**
* WARN_UNUSED_RESULT - warn if a function return value is unused.
*
* Used to mark a function where it is extremely unlikely that the caller
* can ignore the result, eg realloc().
*
* Example:
* // buf param may be freed by this; need return value!
* static char *WARN_UNUSED_RESULT enlarge(char *buf, unsigned *size)
* {
* return realloc(buf, (*size) *= 2);
* }
*/
#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
#define WARN_UNUSED_RESULT
#endif
#endif
#endif /* CCAN_COMPILER_H */

View File

@ -0,0 +1,22 @@
#include <ccan/compiler/compiler.h>
static void PRINTF_FMT(2,3) my_printf(int x, const char *fmt, ...)
{
}
int main(int argc, char *argv[])
{
unsigned int i = 0;
my_printf(1, "Not a pointer "
#ifdef FAIL
"%p",
#if !HAVE_ATTRIBUTE_PRINTF
#error "Unfortunately we don't fail if !HAVE_ATTRIBUTE_PRINTF."
#endif
#else
"%i",
#endif
i);
return 0;
}

View File

@ -0,0 +1,15 @@
#include <ccan/compiler/compiler.h>
#include <ccan/tap/tap.h>
int main(int argc, char *argv[])
{
plan_tests(2);
ok1(!IS_COMPILE_CONSTANT(argc));
#if HAVE_BUILTIN_CONSTANT_P
ok1(IS_COMPILE_CONSTANT(7));
#else
pass("If !HAVE_BUILTIN_CONSTANT_P, IS_COMPILE_CONSTANT always false");
#endif
return exit_status();
}

339
ccan/crc/LICENSE Normal file
View File

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

46
ccan/crc/_info Normal file
View File

@ -0,0 +1,46 @@
#include "config.h"
#include <string.h>
#include <stdio.h>
/**
* crc - routines for crc of bytes
*
* Cyclic Redundancy Check routines. These are reasonably fast
* checksum routines, but not suitable for cryptographic use.
*
* They are useful for simple error detection, eg. a 32-bit CRC will
* detect a single error burst of up to 32 bits.
*
* Example:
* #include <ccan/crc/crc.h>
* #include <stdio.h>
* #include <stdlib.h>
*
* // Given "IHATEMATH" outputs 0x98a3b8df
* int main(int argc, char *argv[])
* {
* if (argc != 2) {
* fprintf(stderr, "Usage: %s <string>\n"
* "Prints 32 bit CRC of the string\n", argv[0]);
* exit(1);
* }
* printf("0x%08x\n", crc32c(0, argv[1], strlen(argv[1])));
* exit(0);
* }
*
* License: GPL (v2 or any later version)
* Author: Gary S. Brown, Clay Haapala
* Maintainer: Rusty Russell <rusty@rustcorp.com.au>
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/array_size\n");
return 0;
}
return 1;
}

307
ccan/crc/crc.c Normal file
View File

@ -0,0 +1,307 @@
/* crc32_ieee code:
* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
* code or tables extracted from it, as desired without restriction.
*/
/* crc32c code taken from 2.6.29 Linux kernel crypto/crc32c.c:
* Copyright (c) 2004 Cisco Systems, Inc.
* Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version. */
/* crc64 code taken from Jacksum version 1.7.0 - checksum utility in Java
* E-mail: jonelo@jonelo.de
* Copyright (C) 2001-2006 Dipl.-Inf. (FH) Johann Nepomuk Loefflmann,
* All Rights Reserved, http://www.jonelo.de
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*/
#include "crc.h"
#include <ccan/array_size/array_size.h>
#include <stdbool.h>
#include <stdlib.h>
/*
* This is the CRC-32C table
* Generated with:
* width = 32 bits
* poly = 0x1EDC6F41
* reflect input bytes = true
* reflect output bytes = true
*/
static const uint32_t crc32c_tab[] = {
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4,
0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B,
0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B,
0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,
0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54,
0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B,
0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A,
0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35,
0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5,
0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA,
0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45,
0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A,
0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A,
0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595,
0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48,
0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957,
0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687,
0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198,
0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927,
0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38,
0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8,
0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7,
0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096,
0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789,
0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859,
0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46,
0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9,
0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6,
0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36,
0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829,
0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C,
0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93,
0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043,
0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C,
0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3,
0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC,
0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C,
0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033,
0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652,
0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D,
0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D,
0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982,
0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D,
0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622,
0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2,
0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED,
0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530,
0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F,
0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF,
0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0,
0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F,
0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540,
0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90,
0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F,
0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE,
0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1,
0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321,
0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E,
0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81,
0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E,
0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351
};
/*
* Steps through buffer one byte at at time, calculates reflected
* crc using table.
*/
uint32_t crc32c(uint32_t crc, const void *buf, size_t size)
{
const uint8_t *p = buf;
while (size--)
crc = crc32c_tab[(crc ^ *p++) & 0xFFL] ^ (crc >> 8);
return crc;
}
const uint32_t *crc32c_table(void)
{
return crc32c_tab;
}
static const uint32_t crc32_ieee_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t crc32_ieee(uint32_t crc, const void *buf, size_t size)
{
const uint8_t *p;
p = buf;
crc ^= ~0U;
while (size--)
crc = crc32_ieee_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
return crc ^ ~0U;
}
const uint32_t *crc32_ieee_table(void)
{
return crc32_ieee_tab;
}
/* We only keep the upper 16 bits of the table: the lower 48 are always 0 */
static uint16_t crc64_tab[] = {
0x0000, 0x01b0, 0x0360,
0x02d0, 0x06c0, 0x0770,
0x05a0, 0x0410, 0x0d80,
0x0c30, 0x0ee0, 0x0f50,
0x0b40, 0x0af0, 0x0820,
0x0990, 0x1b00, 0x1ab0,
0x1860, 0x19d0, 0x1dc0,
0x1c70, 0x1ea0, 0x1f10,
0x1680, 0x1730, 0x15e0,
0x1450, 0x1040, 0x11f0,
0x1320, 0x1290, 0x3600,
0x37b0, 0x3560, 0x34d0,
0x30c0, 0x3170, 0x33a0,
0x3210, 0x3b80, 0x3a30,
0x38e0, 0x3950, 0x3d40,
0x3cf0, 0x3e20, 0x3f90,
0x2d00, 0x2cb0, 0x2e60,
0x2fd0, 0x2bc0, 0x2a70,
0x28a0, 0x2910, 0x2080,
0x2130, 0x23e0, 0x2250,
0x2640, 0x27f0, 0x2520,
0x2490, 0x6c00, 0x6db0,
0x6f60, 0x6ed0, 0x6ac0,
0x6b70, 0x69a0, 0x6810,
0x6180, 0x6030, 0x62e0,
0x6350, 0x6740, 0x66f0,
0x6420, 0x6590, 0x7700,
0x76b0, 0x7460, 0x75d0,
0x71c0, 0x7070, 0x72a0,
0x7310, 0x7a80, 0x7b30,
0x79e0, 0x7850, 0x7c40,
0x7df0, 0x7f20, 0x7e90,
0x5a00, 0x5bb0, 0x5960,
0x58d0, 0x5cc0, 0x5d70,
0x5fa0, 0x5e10, 0x5780,
0x5630, 0x54e0, 0x5550,
0x5140, 0x50f0, 0x5220,
0x5390, 0x4100, 0x40b0,
0x4260, 0x43d0, 0x47c0,
0x4670, 0x44a0, 0x4510,
0x4c80, 0x4d30, 0x4fe0,
0x4e50, 0x4a40, 0x4bf0,
0x4920, 0x4890, 0xd800,
0xd9b0, 0xdb60, 0xdad0,
0xdec0, 0xdf70, 0xdda0,
0xdc10, 0xd580, 0xd430,
0xd6e0, 0xd750, 0xd340,
0xd2f0, 0xd020, 0xd190,
0xc300, 0xc2b0, 0xc060,
0xc1d0, 0xc5c0, 0xc470,
0xc6a0, 0xc710, 0xce80,
0xcf30, 0xcde0, 0xcc50,
0xc840, 0xc9f0, 0xcb20,
0xca90, 0xee00, 0xefb0,
0xed60, 0xecd0, 0xe8c0,
0xe970, 0xeba0, 0xea10,
0xe380, 0xe230, 0xe0e0,
0xe150, 0xe540, 0xe4f0,
0xe620, 0xe790, 0xf500,
0xf4b0, 0xf660, 0xf7d0,
0xf3c0, 0xf270, 0xf0a0,
0xf110, 0xf880, 0xf930,
0xfbe0, 0xfa50, 0xfe40,
0xfff0, 0xfd20, 0xfc90,
0xb400, 0xb5b0, 0xb760,
0xb6d0, 0xb2c0, 0xb370,
0xb1a0, 0xb010, 0xb980,
0xb830, 0xbae0, 0xbb50,
0xbf40, 0xbef0, 0xbc20,
0xbd90, 0xaf00, 0xaeb0,
0xac60, 0xadd0, 0xa9c0,
0xa870, 0xaaa0, 0xab10,
0xa280, 0xa330, 0xa1e0,
0xa050, 0xa440, 0xa5f0,
0xa720, 0xa690, 0x8200,
0x83b0, 0x8160, 0x80d0,
0x84c0, 0x8570, 0x87a0,
0x8610, 0x8f80, 0x8e30,
0x8ce0, 0x8d50, 0x8940,
0x88f0, 0x8a20, 0x8b90,
0x9900, 0x98b0, 0x9a60,
0x9bd0, 0x9fc0, 0x9e70,
0x9ca0, 0x9d10, 0x9480,
0x9530, 0x97e0, 0x9650,
0x9240, 0x93f0, 0x9120,
0x9090
};
uint64_t crc64_iso(uint64_t crc, const void *buf, size_t size)
{
const uint8_t *p = buf;
while (size--) {
uint64_t tabval = crc64_tab[(crc ^ *p++) & 0xFFL];
tabval <<= 48;
crc = tabval ^ (crc >> 8);
}
return crc;
}
const uint64_t *crc64_iso_table(void)
{
static uint64_t *fulltab = NULL;
unsigned int i;
if (fulltab)
return fulltab;
fulltab = malloc(sizeof(uint64_t)*ARRAY_SIZE(crc64_tab));
if (!fulltab)
return NULL;
for (i = 0; i < ARRAY_SIZE(crc64_tab); i++)
fulltab[i] = (uint64_t)crc64_tab[i] << 48;
return fulltab;
}

107
ccan/crc/crc.h Normal file
View File

@ -0,0 +1,107 @@
/* Licensed under GPLv2+ - see LICENSE file for details */
#ifndef CCAN_CRC_H
#define CCAN_CRC_H
#include <stdint.h>
#include <stdlib.h>
/**
* crc32c - Castagnoli 32 bit crc of string of bytes
* @start_crc: the initial crc (usually 0)
* @buf: pointer to bytes
* @size: length of buffer
*
* If you don't know what crc32 to use, use this one: it's the best.
*
* @Article{castagnoli-crc,
* author = { Guy Castagnoli and Stefan Braeuer and Martin Herrman},
* title = {{Optimization of Cyclic Redundancy-Check Codes with 24
* and 32 Parity Bits}},
* journal = IEEE Transactions on Communication,
* year = {1993},
* volume = {41},
* number = {6},
* pages = {},
* month = {June},
*}
* 32 bit CRC checksum using polynomial
* X^32+X^28+X^27+X^26+X^25+X^23+X^22+X^20+X^19+X^18+X^14+X^13+X^11+X^10+X^9+X^8+X^6+X^0.
*
* You can calculate the CRC of non-contiguous arrays by passing @start_crc
* as 0 the first time, and the current crc result from then on.
*
* Example:
* #include <sys/uio.h>
* ...
* // Check that iovec has the crc we expect (Castagnoli version)
* static bool check_crc(uint32_t expected, const struct iovec *iov, int l)
* {
* uint32_t crc = 0;
* while (l >= 0) {
* crc = crc32c(crc, iov->iov_base, iov->iov_len);
* iov++;
* }
* return crc == expected;
* }
*/
uint32_t crc32c(uint32_t start_crc, const void *buf, size_t size);
/**
* crc32c_table - Get the Castagnoli CRC table
*
* For special effects, you might want direct access to the table; this is
* the standard 256-entry table for this algorithm.
*
* In theory, this might need to malloc(), and thus return NULL.
*
* Example:
* // This dumb code only handles Castagnoli, so assert that here.
* static void check_user_crc_table(const uint32_t *usertab)
* {
* const uint32_t *ctab = crc32c_table();
* if (!ctab || memcmp(ctab, usertab, 1024) != 0)
* abort();
* }
*/
const uint32_t *crc32c_table(void);
/**
* crc32_ieee - IEEE 802.3 32 bit crc of string of bytes
* @start_crc: the initial crc (usually 0)
* @buf: pointer to bytes
* @size: length of buffer
*
* 32 bit CRC checksum using polynomial
* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0.
*
* See crc32c() for details.
*/
uint32_t crc32_ieee(uint32_t start_crc, const void *buf, size_t size);
/**
* crc32_ieee_table - Get the IEEE 802.3 CRC table
*
* See crc32c_table() for details.
*/
const uint32_t *crc32_ieee_table(void);
/**
* crc64_iso - ISO 3309
* @start_crc: the initial crc (usually 0)
* @buf: pointer to bytes
* @size: length of buffer
*
* 64 bit CRC checksum using polynomial
* X^64 + X^4 + X^3 + X^1 + X^0
*
* See crc32c() for details.
*/
uint64_t crc64_iso(uint64_t start_crc, const void *buf, size_t size);
/**
* crc64_iso_table - Get the ISO 3309 CRC table
*
* See crc32c_table() for details.
*/
const uint64_t *crc64_iso_table(void);
#endif /* CCAN_CRC_H */

261
ccan/crc/test/api.c Normal file
View File

@ -0,0 +1,261 @@
#include <ccan/crc/crc.h>
#include <ccan/tap/tap.h>
#include <string.h>
static const uint32_t crc32c_tab[] = {
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4,
0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B,
0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B,
0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,
0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54,
0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B,
0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A,
0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35,
0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5,
0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA,
0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45,
0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A,
0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A,
0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595,
0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48,
0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957,
0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687,
0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198,
0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927,
0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38,
0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8,
0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7,
0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096,
0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789,
0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859,
0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46,
0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9,
0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6,
0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36,
0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829,
0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C,
0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93,
0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043,
0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C,
0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3,
0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC,
0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C,
0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033,
0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652,
0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D,
0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D,
0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982,
0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D,
0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622,
0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2,
0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED,
0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530,
0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F,
0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF,
0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0,
0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F,
0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540,
0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90,
0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F,
0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE,
0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1,
0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321,
0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E,
0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81,
0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E,
0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351
};
static const uint32_t crc32_ieee_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
/* Expected CRCs of 4 of each char. */
static uint32_t crcc_expect[] = {
0x00000000, 0x99cd23b2, 0x36763195, 0xafbb1227, 0x6cec632a, 0xf5214098,
0x5a9a52bf, 0xc357710d, 0xd9d8c654, 0x4015e5e6, 0xefaef7c1, 0x7663d473,
0xb534a57e, 0x2cf986cc, 0x834294eb, 0x1a8fb759, 0xb65dfa59, 0x2f90d9eb,
0x802bcbcc, 0x19e6e87e, 0xdab19973, 0x437cbac1, 0xecc7a8e6, 0x750a8b54,
0x6f853c0d, 0xf6481fbf, 0x59f30d98, 0xc03e2e2a, 0x03695f27, 0x9aa47c95,
0x351f6eb2, 0xacd24d00, 0x69578243, 0xf09aa1f1, 0x5f21b3d6, 0xc6ec9064,
0x05bbe169, 0x9c76c2db, 0x33cdd0fc, 0xaa00f34e, 0xb08f4417, 0x294267a5,
0x86f97582, 0x1f345630, 0xdc63273d, 0x45ae048f, 0xea1516a8, 0x73d8351a,
0xdf0a781a, 0x46c75ba8, 0xe97c498f, 0x70b16a3d, 0xb3e61b30, 0x2a2b3882,
0x85902aa5, 0x1c5d0917, 0x06d2be4e, 0x9f1f9dfc, 0x30a48fdb, 0xa969ac69,
0x6a3edd64, 0xf3f3fed6, 0x5c48ecf1, 0xc585cf43, 0xd2af0486, 0x4b622734,
0xe4d93513, 0x7d1416a1, 0xbe4367ac, 0x278e441e, 0x88355639, 0x11f8758b,
0x0b77c2d2, 0x92bae160, 0x3d01f347, 0xa4ccd0f5, 0x679ba1f8, 0xfe56824a,
0x51ed906d, 0xc820b3df, 0x64f2fedf, 0xfd3fdd6d, 0x5284cf4a, 0xcb49ecf8,
0x081e9df5, 0x91d3be47, 0x3e68ac60, 0xa7a58fd2, 0xbd2a388b, 0x24e71b39,
0x8b5c091e, 0x12912aac, 0xd1c65ba1, 0x480b7813, 0xe7b06a34, 0x7e7d4986,
0xbbf886c5, 0x2235a577, 0x8d8eb750, 0x144394e2, 0xd714e5ef, 0x4ed9c65d,
0xe162d47a, 0x78aff7c8, 0x62204091, 0xfbed6323, 0x54567104, 0xcd9b52b6,
0x0ecc23bb, 0x97010009, 0x38ba122e, 0xa177319c, 0x0da57c9c, 0x94685f2e,
0x3bd34d09, 0xa21e6ebb, 0x61491fb6, 0xf8843c04, 0x573f2e23, 0xcef20d91,
0xd47dbac8, 0x4db0997a, 0xe20b8b5d, 0x7bc6a8ef, 0xb891d9e2, 0x215cfa50,
0x8ee7e877, 0x172acbc5, 0xa0b27ffd, 0x397f5c4f, 0x96c44e68, 0x0f096dda,
0xcc5e1cd7, 0x55933f65, 0xfa282d42, 0x63e50ef0, 0x796ab9a9, 0xe0a79a1b,
0x4f1c883c, 0xd6d1ab8e, 0x1586da83, 0x8c4bf931, 0x23f0eb16, 0xba3dc8a4,
0x16ef85a4, 0x8f22a616, 0x2099b431, 0xb9549783, 0x7a03e68e, 0xe3cec53c,
0x4c75d71b, 0xd5b8f4a9, 0xcf3743f0, 0x56fa6042, 0xf9417265, 0x608c51d7,
0xa3db20da, 0x3a160368, 0x95ad114f, 0x0c6032fd, 0xc9e5fdbe, 0x5028de0c,
0xff93cc2b, 0x665eef99, 0xa5099e94, 0x3cc4bd26, 0x937faf01, 0x0ab28cb3,
0x103d3bea, 0x89f01858, 0x264b0a7f, 0xbf8629cd, 0x7cd158c0, 0xe51c7b72,
0x4aa76955, 0xd36a4ae7, 0x7fb807e7, 0xe6752455, 0x49ce3672, 0xd00315c0,
0x135464cd, 0x8a99477f, 0x25225558, 0xbcef76ea, 0xa660c1b3, 0x3fade201,
0x9016f026, 0x09dbd394, 0xca8ca299, 0x5341812b, 0xfcfa930c, 0x6537b0be,
0x721d7b7b, 0xebd058c9, 0x446b4aee, 0xdda6695c, 0x1ef11851, 0x873c3be3,
0x288729c4, 0xb14a0a76, 0xabc5bd2f, 0x32089e9d, 0x9db38cba, 0x047eaf08,
0xc729de05, 0x5ee4fdb7, 0xf15fef90, 0x6892cc22, 0xc4408122, 0x5d8da290,
0xf236b0b7, 0x6bfb9305, 0xa8ace208, 0x3161c1ba, 0x9edad39d, 0x0717f02f,
0x1d984776, 0x845564c4, 0x2bee76e3, 0xb2235551, 0x7174245c, 0xe8b907ee,
0x470215c9, 0xdecf367b, 0x1b4af938, 0x8287da8a, 0x2d3cc8ad, 0xb4f1eb1f,
0x77a69a12, 0xee6bb9a0, 0x41d0ab87, 0xd81d8835, 0xc2923f6c, 0x5b5f1cde,
0xf4e40ef9, 0x6d292d4b, 0xae7e5c46, 0x37b37ff4, 0x98086dd3, 0x01c54e61,
0xad170361, 0x34da20d3, 0x9b6132f4, 0x02ac1146, 0xc1fb604b, 0x583643f9,
0xf78d51de, 0x6e40726c, 0x74cfc535, 0xed02e687, 0x42b9f4a0, 0xdb74d712,
0x1823a61f, 0x81ee85ad, 0x2e55978a, 0xb798b438
};
static uint32_t crcc_zero_expect[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
static uint32_t crc_ieee_expect[] = {
0x2144df1c, 0xf626d399, 0x54f1c057, 0x8393ccd2, 0xca2ee18a, 0x1d4ced0f,
0xbf9bfec1, 0x68f9f244, 0x2ce1a471, 0xfb83a8f4, 0x5954bb3a, 0x8e36b7bf,
0xc78b9ae7, 0x10e99662, 0xb23e85ac, 0x655c8929, 0x3a0e29c6, 0xed6c2543,
0x4fbb368d, 0x98d93a08, 0xd1641750, 0x06061bd5, 0xa4d1081b, 0x73b3049e,
0x37ab52ab, 0xe0c95e2e, 0x421e4de0, 0x957c4165, 0xdcc16c3d, 0x0ba360b8,
0xa9747376, 0x7e167ff3, 0x17d132a8, 0xc0b33e2d, 0x62642de3, 0xb5062166,
0xfcbb0c3e, 0x2bd900bb, 0x890e1375, 0x5e6c1ff0, 0x1a7449c5, 0xcd164540,
0x6fc1568e, 0xb8a35a0b, 0xf11e7753, 0x267c7bd6, 0x84ab6818, 0x53c9649d,
0x0c9bc472, 0xdbf9c8f7, 0x792edb39, 0xae4cd7bc, 0xe7f1fae4, 0x3093f661,
0x9244e5af, 0x4526e92a, 0x013ebf1f, 0xd65cb39a, 0x748ba054, 0xa3e9acd1,
0xea548189, 0x3d368d0c, 0x9fe19ec2, 0x48839247, 0x4c6f0474, 0x9b0d08f1,
0x39da1b3f, 0xeeb817ba, 0xa7053ae2, 0x70673667, 0xd2b025a9, 0x05d2292c,
0x41ca7f19, 0x96a8739c, 0x347f6052, 0xe31d6cd7, 0xaaa0418f, 0x7dc24d0a,
0xdf155ec4, 0x08775241, 0x5725f2ae, 0x8047fe2b, 0x2290ede5, 0xf5f2e160,
0xbc4fcc38, 0x6b2dc0bd, 0xc9fad373, 0x1e98dff6, 0x5a8089c3, 0x8de28546,
0x2f359688, 0xf8579a0d, 0xb1eab755, 0x6688bbd0, 0xc45fa81e, 0x133da49b,
0x7afae9c0, 0xad98e545, 0x0f4ff68b, 0xd82dfa0e, 0x9190d756, 0x46f2dbd3,
0xe425c81d, 0x3347c498, 0x775f92ad, 0xa03d9e28, 0x02ea8de6, 0xd5888163,
0x9c35ac3b, 0x4b57a0be, 0xe980b370, 0x3ee2bff5, 0x61b01f1a, 0xb6d2139f,
0x14050051, 0xc3670cd4, 0x8ada218c, 0x5db82d09, 0xff6f3ec7, 0x280d3242,
0x6c156477, 0xbb7768f2, 0x19a07b3c, 0xcec277b9, 0x877f5ae1, 0x501d5664,
0xf2ca45aa, 0x25a8492f, 0xfb1369cc, 0x2c716549, 0x8ea67687, 0x59c47a02,
0x1079575a, 0xc71b5bdf, 0x65cc4811, 0xb2ae4494, 0xf6b612a1, 0x21d41e24,
0x83030dea, 0x5461016f, 0x1ddc2c37, 0xcabe20b2, 0x6869337c, 0xbf0b3ff9,
0xe0599f16, 0x373b9393, 0x95ec805d, 0x428e8cd8, 0x0b33a180, 0xdc51ad05,
0x7e86becb, 0xa9e4b24e, 0xedfce47b, 0x3a9ee8fe, 0x9849fb30, 0x4f2bf7b5,
0x0696daed, 0xd1f4d668, 0x7323c5a6, 0xa441c923, 0xcd868478, 0x1ae488fd,
0xb8339b33, 0x6f5197b6, 0x26ecbaee, 0xf18eb66b, 0x5359a5a5, 0x843ba920,
0xc023ff15, 0x1741f390, 0xb596e05e, 0x62f4ecdb, 0x2b49c183, 0xfc2bcd06,
0x5efcdec8, 0x899ed24d, 0xd6cc72a2, 0x01ae7e27, 0xa3796de9, 0x741b616c,
0x3da64c34, 0xeac440b1, 0x4813537f, 0x9f715ffa, 0xdb6909cf, 0x0c0b054a,
0xaedc1684, 0x79be1a01, 0x30033759, 0xe7613bdc, 0x45b62812, 0x92d42497,
0x9638b2a4, 0x415abe21, 0xe38dadef, 0x34efa16a, 0x7d528c32, 0xaa3080b7,
0x08e79379, 0xdf859ffc, 0x9b9dc9c9, 0x4cffc54c, 0xee28d682, 0x394ada07,
0x70f7f75f, 0xa795fbda, 0x0542e814, 0xd220e491, 0x8d72447e, 0x5a1048fb,
0xf8c75b35, 0x2fa557b0, 0x66187ae8, 0xb17a766d, 0x13ad65a3, 0xc4cf6926,
0x80d73f13, 0x57b53396, 0xf5622058, 0x22002cdd, 0x6bbd0185, 0xbcdf0d00,
0x1e081ece, 0xc96a124b, 0xa0ad5f10, 0x77cf5395, 0xd518405b, 0x027a4cde,
0x4bc76186, 0x9ca56d03, 0x3e727ecd, 0xe9107248, 0xad08247d, 0x7a6a28f8,
0xd8bd3b36, 0x0fdf37b3, 0x46621aeb, 0x9100166e, 0x33d705a0, 0xe4b50925,
0xbbe7a9ca, 0x6c85a54f, 0xce52b681, 0x1930ba04, 0x508d975c, 0x87ef9bd9,
0x25388817, 0xf25a8492, 0xb642d2a7, 0x6120de22, 0xc3f7cdec, 0x1495c169,
0x5d28ec31, 0x8a4ae0b4, 0x289df37a, 0xffffffff,
};
static uint32_t crc_ieee_zero_expect[] = {
0x00000000, 0xd202ef8d, 0x41d912ff, 0xff41d912
};
/* Runs 517 tests. */
static void test_crc32(uint32_t (*crc)(uint32_t, const void *, size_t),
const uint32_t *(*crc_table)(void),
const uint32_t zero_expect[4],
const uint32_t four_char_expect[256],
const uint32_t *table_expect)
{
unsigned int i;
char c[4] = { 0 };
for (i = 0; i < 4; i++)
ok1(crc(0, c, i) == zero_expect[i]);
for (i = 0; i < 256; i++) {
memset(c, i, sizeof(c));
ok1(crc(0, c, sizeof(c)) == four_char_expect[i]);
/* CRC in two parts should give same answer. */
ok1(crc(crc(0, c, i%5), c+i%5, 4 - (i%5))
== four_char_expect[i]);
}
ok1(memcmp(crc_table(), table_expect, 1024) == 0);
}
static void test_crc64(void)
{
/* according to http://swissknife.sourceforge.net/CRC64.html */
ok1(crc64_iso(0, "IHATEMATH", strlen("IHATEMATH"))
== 0xE3DCADD69B01ADD1ULL);
/* according to the CRC64 poly, http://sf.net/projects/jcrcgen */
ok1(crc64_iso(0, "123456789", strlen("123456789"))
== 0x46A5A9388A5BEFFEULL);
}
int main(int argc, char *argv[])
{
plan_tests(517 * 2 + 2);
test_crc32(crc32c, crc32c_table,
crcc_zero_expect, crcc_expect, crc32c_tab);
test_crc32(crc32_ieee, crc32_ieee_table,
crc_ieee_zero_expect, crc_ieee_expect, crc32_ieee_tab);
test_crc64();
return exit_status();
}

17
ccan/darray/LICENSE Normal file
View File

@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

57
ccan/darray/_info Normal file
View File

@ -0,0 +1,57 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
#include "ccan/darray/darray.h"
/**
* darray - Generic resizable arrays
*
* darray is a set of macros for managing dynamically-allocated arrays.
* It removes the tedium of managing realloc'd arrays with pointer, size, and
* allocated size.
*
* Example:
* #include <ccan/darray/darray.h>
* #include <stdio.h>
*
* int main(void) {
* darray(int) numbers = darray_new();
* char buffer[32];
*
* for (;;) {
* int *i;
* darray_foreach(i, numbers)
* printf("%d ", *i);
* if (darray_size(numbers) > 0)
* puts("");
*
* printf("darray> ");
* fgets(buffer, sizeof(buffer), stdin);
* if (*buffer == '\0' || *buffer == '\n')
* break;
*
* darray_append(numbers, atoi(buffer));
* }
*
* darray_free(numbers);
*
* return 0;
* }
*
* Author: Joey Adams <joeyadams3.14159@gmail.com>
* License: MIT
* Version: 0.2
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
/* Nothing. */
return 0;
}
return 1;
}

355
ccan/darray/darray.h Normal file
View File

@ -0,0 +1,355 @@
/*
* Copyright (C) 2011 Joseph Adams <joeyadams3.14159@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CCAN_DARRAY_H
#define CCAN_DARRAY_H
#include <stdlib.h>
#include <string.h>
#include "config.h"
/*
* SYNOPSIS
*
* Life cycle of a darray (dynamically-allocated array):
*
* darray(int) a = darray_new();
* darray_free(a);
*
* struct {darray(int) a;} foo;
* darray_init(foo.a);
* darray_free(foo.a);
*
* Typedefs for darrays of common types:
*
* darray_char, darray_schar, darray_uchar
* darray_short, darray_int, darray_long
* darray_ushort, darray_uint, darray_ulong
*
* Access:
*
* T darray_item(darray(T) arr, size_t index);
* size_t darray_size(darray(T) arr);
* size_t darray_alloc(darray(T) arr);
* bool darray_empty(darray(T) arr);
*
* Insertion (single item):
*
* void darray_append(darray(T) arr, T item);
* void darray_prepend(darray(T) arr, T item);
* void darray_push(darray(T) arr, T item); // same as darray_append
*
* Insertion (multiple items):
*
* void darray_append_items(darray(T) arr, T *items, size_t count);
* void darray_prepend_items(darray(T) arr, T *items, size_t count);
*
* void darray_appends(darray(T) arr, [T item, [...]]);
* void darray_prepends(darray(T) arr, [T item, [...]]);
*
* // Same functionality as above, but does not require typeof.
* void darray_appends_t(darray(T) arr, #T, [T item, [...]]);
* void darray_prepends_t(darray(T) arr, #T, [T item, [...]]);
*
* Removal:
*
* T darray_pop(darray(T) arr | darray_size(arr) != 0);
* T* darray_pop_check(darray(T*) arr);
* void darray_remove(darray(T) arr, size_t index);
*
* Replacement:
*
* void darray_from_items(darray(T) arr, T *items, size_t count);
* void darray_from_c(darray(T) arr, T c_array[N]);
*
* String buffer:
*
* void darray_append_string(darray(char) arr, const char *str);
* void darray_append_lit(darray(char) arr, char stringLiteral[N+1]);
*
* void darray_prepend_string(darray(char) arr, const char *str);
* void darray_prepend_lit(darray(char) arr, char stringLiteral[N+1]);
*
* void darray_from_string(darray(T) arr, const char *str);
* void darray_from_lit(darray(char) arr, char stringLiteral[N+1]);
*
* Size management:
*
* void darray_resize(darray(T) arr, size_t newSize);
* void darray_resize0(darray(T) arr, size_t newSize);
*
* void darray_realloc(darray(T) arr, size_t newAlloc);
* void darray_growalloc(darray(T) arr, size_t newAlloc);
*
* void darray_make_room(darray(T) arr, size_t room);
*
* Traversal:
*
* darray_foreach(T *&i, darray(T) arr) {...}
* darray_foreach_reverse(T *&i, darray(T) arr) {...}
*
* Except for darray_foreach, darray_foreach_reverse, and darray_remove,
* all macros evaluate their non-darray arguments only once.
*/
/*** Life cycle ***/
#define darray(type) struct {type *item; size_t size; size_t alloc;}
#define darray_new() {0,0,0}
#define darray_init(arr) do {(arr).item=0; (arr).size=0; (arr).alloc=0;} while(0)
#define darray_free(arr) do {free((arr).item);} while(0)
/*
* Typedefs for darrays of common types. These are useful
* when you want to pass a pointer to an darray(T) around.
*
* The following will produce an incompatible pointer warning:
*
* void foo(darray(int) *arr);
* darray(int) arr = darray_new();
* foo(&arr);
*
* The workaround:
*
* void foo(darray_int *arr);
* darray_int arr = darray_new();
* foo(&arr);
*/
typedef darray(char) darray_char;
typedef darray(signed char) darray_schar;
typedef darray(unsigned char) darray_uchar;
typedef darray(short) darray_short;
typedef darray(int) darray_int;
typedef darray(long) darray_long;
typedef darray(unsigned short) darray_ushort;
typedef darray(unsigned int) darray_uint;
typedef darray(unsigned long) darray_ulong;
/*** Access ***/
#define darray_item(arr, i) ((arr).item[i])
#define darray_size(arr) ((arr).size)
#define darray_alloc(arr) ((arr).alloc)
#define darray_empty(arr) ((arr).size == 0)
/*** Insertion (single item) ***/
#define darray_append(arr, ...) do { \
darray_resize(arr, (arr).size+1); \
(arr).item[(arr).size-1] = (__VA_ARGS__); \
} while(0)
#define darray_prepend(arr, ...) do { \
darray_resize(arr, (arr).size+1); \
memmove((arr).item+1, (arr).item, ((arr).size-1)*sizeof(*(arr).item)); \
(arr).item[0] = (__VA_ARGS__); \
} while(0)
#define darray_push(arr, ...) darray_append(arr, __VA_ARGS__)
/*** Insertion (multiple items) ***/
#define darray_append_items(arr, items, count) do { \
size_t __count = (count), __oldSize = (arr).size; \
darray_resize(arr, __oldSize + __count); \
memcpy((arr).item + __oldSize, items, __count * sizeof(*(arr).item)); \
} while(0)
#define darray_prepend_items(arr, items, count) do { \
size_t __count = (count), __oldSize = (arr).size; \
darray_resize(arr, __count + __oldSize); \
memmove((arr).item + __count, (arr).item, __oldSize * sizeof(*(arr).item)); \
memcpy((arr).item, items, __count * sizeof(*(arr).item)); \
} while(0)
#define darray_append_items_nullterminate(arr, items, count) do { \
size_t __count = (count), __oldSize = (arr).size; \
darray_resize(arr, __oldSize + __count + 1); \
memcpy((arr).item + __oldSize, items, __count * sizeof(*(arr).item)); \
(arr).item[--(arr).size] = 0; \
} while(0)
#define darray_prepend_items_nullterminate(arr, items, count) do { \
size_t __count = (count), __oldSize = (arr).size; \
darray_resize(arr, __count + __oldSize + 1); \
memmove((arr).item + __count, (arr).item, __oldSize * sizeof(*(arr).item)); \
memcpy((arr).item, items, __count * sizeof(*(arr).item)); \
(arr).item[--(arr).size] = 0; \
} while(0)
#if HAVE_TYPEOF
#define darray_appends(arr, ...) darray_appends_t(arr, typeof((*(arr).item)), __VA_ARGS__)
#define darray_prepends(arr, ...) darray_prepends_t(arr, typeof((*(arr).item)), __VA_ARGS__)
#endif
#define darray_appends_t(arr, type, ...) do { \
type __src[] = {__VA_ARGS__}; \
darray_append_items(arr, __src, sizeof(__src)/sizeof(*__src)); \
} while(0)
#define darray_prepends_t(arr, type, ...) do { \
type __src[] = {__VA_ARGS__}; \
darray_prepend_items(arr, __src, sizeof(__src)/sizeof(*__src)); \
} while(0)
/*** Removal ***/
/* Warning: Do not call darray_pop on an empty darray. */
#define darray_pop(arr) ((arr).item[--(arr).size])
#define darray_pop_check(arr) ((arr).size ? darray_pop(arr) : NULL)
/* Warning, slow: Requires copying all elements after removed item. */
#define darray_remove(arr, index) do { \
if (index < arr.size-1) \
memmove(&(arr).item[index], &(arr).item[index+1], ((arr).size-1-i)*sizeof(*(arr).item)); \
(arr).size--; \
} while(0)
/*** Replacement ***/
#define darray_from_items(arr, items, count) do {size_t __count = (count); darray_resize(arr, __count); memcpy((arr).item, items, __count*sizeof(*(arr).item));} while(0)
#define darray_from_c(arr, c_array) darray_from_items(arr, c_array, sizeof(c_array)/sizeof(*(c_array)))
/*** String buffer ***/
#define darray_append_string(arr, str) do {const char *__str = (str); darray_append_items(arr, __str, strlen(__str)+1); (arr).size--;} while(0)
#define darray_append_lit(arr, stringLiteral) do {darray_append_items(arr, stringLiteral, sizeof(stringLiteral)); (arr).size--;} while(0)
#define darray_prepend_string(arr, str) do { \
const char *__str = (str); \
darray_prepend_items_nullterminate(arr, __str, strlen(__str)); \
} while(0)
#define darray_prepend_lit(arr, stringLiteral) \
darray_prepend_items_nullterminate(arr, stringLiteral, sizeof(stringLiteral) - 1)
#define darray_from_string(arr, str) do {const char *__str = (str); darray_from_items(arr, __str, strlen(__str)+1); (arr).size--;} while(0)
#define darray_from_lit(arr, stringLiteral) do {darray_from_items(arr, stringLiteral, sizeof(stringLiteral)); (arr).size--;} while(0)
/*** Size management ***/
#define darray_resize(arr, newSize) darray_growalloc(arr, (arr).size = (newSize))
#define darray_resize0(arr, newSize) do { \
size_t __oldSize = (arr).size, __newSize = (newSize); \
(arr).size = __newSize; \
if (__newSize > __oldSize) { \
darray_growalloc(arr, __newSize); \
memset(&(arr).item[__oldSize], 0, (__newSize - __oldSize) * sizeof(*(arr).item)); \
} \
} while(0)
#define darray_realloc(arr, newAlloc) do { \
(arr).item = realloc((arr).item, ((arr).alloc = (newAlloc)) * sizeof(*(arr).item)); \
} while(0)
#define darray_growalloc(arr, need) do { \
size_t __need = (need); \
if (__need > (arr).alloc) \
darray_realloc(arr, darray_next_alloc((arr).alloc, __need)); \
} while(0)
#if HAVE_STATEMENT_EXPR==1
#define darray_make_room(arr, room) ({size_t newAlloc = (arr).size+(room); if ((arr).alloc<newAlloc) darray_realloc(arr, newAlloc); (arr).item+(arr).size; })
#endif
static inline size_t darray_next_alloc(size_t alloc, size_t need)
{
if (alloc == 0)
alloc = 1;
while (alloc < need)
alloc *= 2;
return alloc;
}
/*** Traversal ***/
/*
* darray_foreach(T *&i, darray(T) arr) {...}
*
* Traverse a darray. `i` must be declared in advance as a pointer to an item.
*/
#define darray_foreach(i, arr) \
for ((i) = &(arr).item[0]; (i) < &(arr).item[(arr).size]; (i)++)
/*
* darray_foreach_reverse(T *&i, darray(T) arr) {...}
*
* Like darray_foreach, but traverse in reverse order.
*/
#define darray_foreach_reverse(i, arr) \
for ((i) = &(arr).item[(arr).size]; (i)-- > &(arr).item[0]; )
#endif /* CCAN_DARRAY_H */
/*
darray_growalloc(arr, newAlloc) sees if the darray can currently hold newAlloc items;
if not, it increases the alloc to satisfy this requirement, allocating slack
space to avoid having to reallocate for every size increment.
darray_from_string(arr, str) copies a string to an darray_char.
darray_push(arr, item) pushes an item to the end of the darray.
darray_pop(arr) pops it back out. Be sure there is at least one item in the darray before calling.
darray_pop_check(arr) does the same as darray_pop, but returns NULL if there are no more items left in the darray.
darray_make_room(arr, room) ensures there's 'room' elements of space after the end of the darray, and it returns a pointer to this space.
Currently requires HAVE_STATEMENT_EXPR, but I plan to remove this dependency by creating an inline function.
The following require HAVE_TYPEOF==1 :
darray_appends(arr, item0, item1...) appends a collection of comma-delimited items to the darray.
darray_prepends(arr, item0, item1...) prepends a collection of comma-delimited items to the darray.\
Examples:
darray(int) arr;
int *i;
darray_appends(arr, 0,1,2,3,4);
darray_appends(arr, -5,-4,-3,-2,-1);
darray_foreach(i, arr)
printf("%d ", *i);
printf("\n");
darray_free(arr);
typedef struct {int n,d;} Fraction;
darray(Fraction) fractions;
Fraction *i;
darray_appends(fractions, {3,4}, {3,5}, {2,1});
darray_foreach(i, fractions)
printf("%d/%d\n", i->n, i->d);
darray_free(fractions);
*/

View File

@ -0,0 +1,252 @@
const unsigned long lotsOfNumbers[] = {
0x3BC1544A, 0xDED23357, 0xC7CA2233, 0x642EB9E8,
0x79AF03EF, 0x2BA52B1B, 0xA1D838D1, 0x3D658883,
0xD8559EA3, 0x47DF11FE, 0x5A6F486E, 0x0E522BFD,
0x80E2FE25, 0xF2C260AE, 0x13068792, 0x66C084B2,
0x9B9161F5, 0xC69F1C58, 0xE01C9F2F, 0x421FEC70,
0xC8D8FE72, 0x97E8BA29, 0x25A221D1, 0x03E0AFA1,
0x7542E923, 0x5BC83711, 0xE537C213, 0x77CD74AF,
0x5A8DF654, 0xE05167C9, 0x4E74FC54, 0x468935A3,
0xA2CB5BE5, 0x6D6EC517, 0x638327AB, 0x95C0B00F,
0x66222D5D, 0xAD073850, 0xC8A42217, 0x3B286F2E,
0x2F460545, 0x9F15AC1E, 0x4AFB0BFA, 0xDF4ED449,
0xF69E6FB3, 0x8BA26583, 0x7560C6C8, 0x2BDBC15B,
0x8DE1EA24, 0xC50A691D, 0xC0752AFB, 0x0E4DC9F8,
0xCEC08C8F, 0x110170AB, 0xD8B9294A, 0xBEDF0E6A,
0x6467AFB6, 0xEA7F34CF, 0xD98D4B19, 0x893A251C,
0xAA6924BE, 0xBA910F15, 0xA9B34632, 0xDC49B63B,
0xA125D202, 0x1E153833, 0x44A897B5, 0x5DF3AD99,
0x3984C923, 0x52F52692, 0x471B5A4D, 0x413B26D5,
0x64BD2A63, 0xBCC8D10D, 0x9B19CBA4, 0xE75277B9,
0x2A8A6933, 0xDF24D9F8, 0x65B03518, 0x88D8FCE2,
0x1D87C609, 0x3F71E663, 0x12B02BAE, 0xCA168CA6,
0x83E91177, 0xE94BA59E, 0x77975B46, 0x5DC0B431,
0x6F940C79, 0x234A4D00, 0xE33B5110, 0x43F422F1,
0x5CFEFA0E, 0x97018BE4, 0xA042F93E, 0x78CEE834,
0x296E3609, 0x622C3BF4, 0xFBCDC3FB, 0x9DBE670E,
0xC073E528, 0x58AC51A9, 0x8333A59B, 0x0C5E2480,
0x93321265, 0x137AD111, 0x92C86613, 0xEFF2D3D5,
0x2310CD8C, 0x281BCAD3, 0xDF3FF3AA, 0x3D5F454F,
0xDA9F1F0D, 0x3AE6A570, 0xB2F8ACF0, 0x4F271B03,
0x636EE513, 0x3CB336CB, 0xB34BD5EF, 0x55ED6801,
0x3C28EDD4, 0x7E8071EB, 0x2753ACA0, 0xE41B9DB7,
0xB817E32A, 0xD3B1ACFE, 0x9C99D0A0, 0x6F3F6B96,
0xCE3DDB62, 0x79CBC3A0, 0x0E17F223, 0x697474F5,
0x4AF1A354, 0x2B6B995D, 0x3A1FFC28, 0x6B190136,
0x813E15B3, 0xA7C3C074, 0xEB602DEE, 0x075B0A26,
0x820F13A6, 0x188748DD, 0xA38AD7A6, 0x371D4CA9,
0xFBDCF297, 0x6A03FB8D, 0x4A70AE69, 0x8B8A3F96,
0x1F40734A, 0xAC8E85F8, 0x6DD7EB6C, 0x7EA514DF,
0x78E69630, 0x878759D7, 0xDC49AA71, 0x8A8728F5,
0x70FCE0FC, 0x3D67452B, 0x4AB23B80, 0x21FA846A,
0xB0A3E976, 0x99AF0681, 0x89485BD6, 0x0D0853D7,
0xC87F3990, 0xBD856176, 0x0AFA8A1E, 0x041C79FF,
0x2556E0B6, 0x4283777D, 0x1AE0E9DE, 0x0ACDA034,
0x4A30466A, 0xBCE768DF, 0xB0256A33, 0x026B68F9,
0xDF89120F, 0xB3618203, 0xF9BB23C1, 0x1A6AA8E8,
0xF6B83C04, 0x9B3078EF, 0x435921E4, 0x33E1C9D6,
0xC4269BF4, 0xFF857F0E, 0xFBBC0B2A, 0x6BC5BC34,
0x7C51886B, 0x6B712B33, 0x5C755D05, 0xDFBA1AB8,
0x339F5BAD, 0xF2267FDD, 0x64C62EBC, 0x594D643B,
0xF936F1C3, 0xCA7191BC, 0x9E6EAFA3, 0xF5A46FE4,
0x8E8873D5, 0xA4139274, 0x0C3AD48B, 0x9A267F86,
0x594704BF, 0x708E43A0, 0xF1A7E87B, 0x33ED9446,
0x917822DD, 0xD9051619, 0x1085F49F, 0x65D4E981,
0x6236D329, 0x987A7977, 0xF0333380, 0x9239B9EC,
0x3715E988, 0x41141FD7, 0xA13F0375, 0xA820B2FC,
0xD2EE0260, 0x6C7939DE, 0xCB250C59, 0xF9B4BA87,
0xF499016D, 0x1709EEFE, 0x2FA88C7D, 0xBA39EAAA,
0x33E629D5, 0x8BDF95F7, 0xEB6300E0, 0xCDD9E7ED,
0xB22F2379, 0x387971A1, 0xC4989C9D, 0xF45CF5A5,
0x17A7818D, 0x62F1F5E7, 0xB39843A4, 0x4B356C99,
0xD6059E6A, 0xC0D4D916, 0x5213FCAC, 0xD17977E8,
0x93BCE0A2, 0x7F6E7557, 0x143A0E68, 0x4BC13C29,
0x15EEBD55, 0x64F13E7A, 0x96263BF8, 0x4C9DCCD4,
0xABB90BC2, 0x44564FF4, 0x15C5D4A2, 0x92BF93DF,
0x88DD7E20, 0x48AA572A, 0x8BC08AC1, 0x96290FAC,
0x412753AE, 0x5FC85DF0, 0x18A345FD, 0x5C350B21,
0x9EB19808, 0xCC98394B, 0x75A964BB, 0x3D05B418,
0xDC8183BC, 0x2DFEA07E, 0x4D5420D7, 0x8E6433FA,
0x3A0DD21D, 0xDE093044, 0x46C70B90, 0x6E6EAEA6,
0x4C852056, 0xC4C0DE59, 0xD2DBD4C3, 0x95ECCB96,
0x2532A9C1, 0xA7B1A13F, 0x8A4ED15C, 0xFD012D44,
0xAA81F579, 0xBADE503E, 0xFC88F509, 0xA7707ACA,
0x8017492D, 0x1DC3FFAB, 0xF5A3332F, 0x761CDFC8,
0xCB7BF537, 0xDF805D6D, 0x7B8A7B21, 0xDBDF2689,
0x933ACDEC, 0xC462D1BC, 0x7CEAC38F, 0xAAD4D068,
0x873A6635, 0xFD68682C, 0x8BFAD93C, 0x5ECCD070,
0xA7E7DF5E, 0x3B9EC4EA, 0x1AA9E4F3, 0xB7F2CC42,
0x879E622E, 0x766AAA44, 0xD04ADCBB, 0xB073073B,
0x23E49537, 0x9072D26E, 0x79E95449, 0xC6CF5BD5,
0x83DAA46E, 0xFBB82182, 0x393660B5, 0xCF3FE74D,
0x2BC8ADFD, 0x0E7073C8, 0x59B38370, 0x77004B86,
0xE466A857, 0xE7C98C37, 0x33ACD076, 0xF714AB2D,
0x7C74158D, 0x520DE73C, 0xCFF2C3BF, 0x1F1FC41D,
0xCDC717E0, 0xC6FD75B9, 0x595779FA, 0x8695CC03,
0x015FBB96, 0xA7C8844F, 0x88FA407D, 0xD92DF345,
0x79858A10, 0x6C3B52E0, 0x0BA7B076, 0x852EB21F,
0xEAC2BA1C, 0x588D204F, 0xC043C966, 0x9D4F440F,
0x95F19188, 0x872DAE89, 0xB496BED0, 0x36AAF573,
0xABC5CBF7, 0x601882C9, 0xF62C6D2D, 0x83E9276F,
0x1E851AF7, 0x11E56617, 0xE381AA22, 0x23872E14,
0x563F1351, 0x2E41EA11, 0x55B9E3F4, 0xA65F6CBE,
0xC0061BA3, 0x13F7F5ED, 0x1FCAC43B, 0xFF5B54BD,
0x3EB0302C, 0x80619FBD, 0x54B2C9D5, 0xFBF42A36,
0x64BF8FE7, 0x296AD5F5, 0x162B0E1D, 0xE100B34B,
0xB080A6DA, 0x14459D2A, 0x5793A95D, 0xFE8C3579,
0xF66BC9AF, 0xF3FDE61C, 0xB8DD6A80, 0x52556542,
0xBFAE9683, 0xF2663FF6, 0x0A2AD60B, 0xD95A2C0B,
0xBCAA0EFD, 0x1DA6EAD3, 0x060DA04E, 0xD7BF6846,
0xF26FBFA2, 0x514D0E84, 0xACE516D6, 0x61B20BD3,
0x00198868, 0xDB501990, 0x6B352D25, 0xB1D13CA3,
0x927CDA88, 0xA05F8C7B, 0xCE1520A4, 0x20875B9E,
0xC3737F98, 0xEF2BB54B, 0x274FE7D8, 0xC5B215C7,
0xF3013DD8, 0x1C801F47, 0xC5BFE0D4, 0x4157E39C,
0x753EEDCB, 0x022EBB01, 0xA11272EE, 0xCB2B9AC2,
0xDD68D509, 0x6D370297, 0xD1B797B5, 0x5184F5E1,
0x75F75A53, 0xCC849E35, 0x618C7F22, 0x197F36CD,
0xA48666E8, 0x2D554CDD, 0xDF0FC30C, 0x595D46E5,
0x2FC10916, 0xED0E156A, 0x46E0DDE1, 0xAE64F9C0,
0x12CC2C13, 0xEE4403D1, 0xE533D892, 0xFE595605,
0x4604790D, 0x803CF6AA, 0x8DFD63CF, 0x54D60899,
0x8590B57E, 0x397140EE, 0x362AD074, 0x0C4C6600,
0x148B32C5, 0x7EDF2402, 0x857C9B42, 0x23849DFC,
0x0C9A22F2, 0x4F8D65F4, 0x4ED17FD2, 0xF98C057A,
0x4EF7E6E1, 0xADAA8803, 0x171B46C5, 0xE5239AAE,
0x5269A989, 0xE98A6164, 0x8115C340, 0xB850277C,
0x12B3DC95, 0x6E9C2243, 0xD86BB397, 0x5EDFA619,
0x67016A34, 0x0B8F0307, 0x497C7947, 0x6DCDCBF2,
0x26ABB02D, 0x157C23DA, 0xFEB0DC2A, 0xD3ABDECC,
0x441E9835, 0x0E506068, 0x407C4CE5, 0x75CE382C,
0x75756184, 0x79191BE6, 0x650B5AA4, 0x95441AF8,
0x0721EFA5, 0x5F834955, 0x5F775009, 0x6FC4BF5D,
0x07B9B28D, 0x5B0C3407, 0xCF622B61, 0xEE06B8F3,
0x6A207BEF, 0x1E57CC62, 0xC05D6618, 0xF0A51B1F,
0xE5FAD5CE, 0xE8187CE3, 0xB7B13F6E, 0x3107FFB9,
0xFAD6AE53, 0xA530CB65, 0x16417E6B, 0xDAFC53EE,
0x52126CE0, 0x03774AA3, 0x3EA7DF10, 0x48010F66,
0xEB77C464, 0x46099FFB, 0xDC6B9ECE, 0x4D0E39A8,
0xBA00D6F1, 0x47A3A174, 0x4BC0DC3C, 0xA8FC61BD,
0x1E937E8B, 0xFB3BD002, 0xA0B1BE03, 0x8AF96C13,
0x9EE7CF41, 0xA776B208, 0x843E951C, 0x37E1DAA4,
0x3C8C2681, 0x9296D21D, 0xDD216E3D, 0x4923F357,
0x6C4A5BA8, 0x62A76612, 0x83B4C690, 0x3A4468A6,
0x3656E5D9, 0xE4FBE234, 0x8C4457A6, 0x41726880,
0xE4EC0B0F, 0x90FEFCCE, 0xAC0A2EAA, 0x2E133570,
0x96806C74, 0x00EFE5F1, 0x028982D9, 0x0C0BADFD,
0x5BE983F2, 0xDFD4B776, 0xF61BFF31, 0x06106654,
0x66AFE70A, 0xCAD56143, 0x9E9D7368, 0xCAAB3824,
0x69E462E5, 0x3DA295CE, 0x676D201F, 0x092F6CC9,
0x3D2245A8, 0x79C07ADF, 0x91BB1257, 0x53C3E5AC,
0x2F5C690C, 0x17C52299, 0x348B4223, 0x543CE6E8,
0x3AD7D22C, 0x841710BA, 0x583F689F, 0x30F56831,
0x7E8FFAA1, 0x7EB85021, 0x2313C120, 0xC7720FF1,
0x606E16CB, 0x036EDC90, 0x7A0A29AC, 0xF2963CB3,
0x787DED71, 0xFD6364B3, 0x718256AC, 0xFBD5C0C4,
0xA4E0148C, 0x535BA861, 0xD1750DE0, 0x10543417,
0x41E2A75F, 0x3045F720, 0x66339C92, 0xB68D0069,
0xA6A6C9CB, 0xB31F92EE, 0xE6EBFD0E, 0xCD2D8BA5,
0x764A8CE0, 0x3197FB3E, 0xAA455F50, 0x327D2488,
0xA4F408B7, 0xFE6F6440, 0xE67008FF, 0x5B449588,
0xE893BF7E, 0xBFAEDE65, 0xC03EC09A, 0x82E181F1,
0xAC019DD3, 0x25BCF222, 0x538F37F0, 0xCA4FF151,
0x11792C56, 0x9B39B3F3, 0x39AA29D5, 0x43B6AD16,
0x84AEC679, 0xEAB994A2, 0xE79B1F12, 0x21A95475,
0x4600EA99, 0xFB2671C8, 0xCA0B0E9D, 0xC71D4A8C,
0x04E5F752, 0x8A02AA94, 0xF5284D09, 0x653CE2CA,
0x70E7EA0E, 0x1C423CCB, 0xF8D97F3F, 0xF1166F8E,
0xD384F2DF, 0x672A2E0F, 0x4320846E, 0x2ADB170E,
0x9364F18E, 0xE2E6C563, 0xFF6D8B3F, 0xFD3B927A,
0x8FC12FF4, 0x848D58ED, 0x90F1C64D, 0xD3AF3B60,
0xC2DCED87, 0x3D46B3FE, 0x530473D4, 0x7C540B51,
0x91429037, 0x8CAB594F, 0xDCA42CA8, 0x73DC71C5,
0xB2628E7A, 0x752B258D, 0x7649AE67, 0xF1EA243B,
0x236E66A5, 0x76EE1618, 0x12E094F1, 0xF0834CA4,
0x181B377E, 0xE8343806, 0xF10DB718, 0x9C41BA01,
0x339CCE0E, 0x5E17036D, 0x08321A94, 0xE2B1F74A,
0x67E33CBA, 0xADEEA6E1, 0xB814B339, 0x1B526C92,
0xE7324F94, 0xF2C2073B, 0x7A0C616B, 0x5C00EE67,
0x6DCB71EE, 0x8B50779C, 0xE226E3D1, 0xDDA75F7E,
0x73D7D930, 0x10B06DB1, 0x5D60B048, 0xBFDE4890,
0x4C4A08EB, 0x336EB637, 0x42CCE81A, 0x74468A7E,
0xE14B042D, 0x61CDEDC1, 0xEFCBDB6F, 0x82C98EBB,
0x4338C016, 0x3D7E41B9, 0x6661D003, 0x310199EA,
0x1180ABAB, 0xA621BDA4, 0xD7A6FF18, 0xC70224C5,
0x6DFA60EA, 0x6871A8A9, 0x7664FEAE, 0xBCD25F41,
0x8913D31D, 0x2C1DB753, 0x1E8509F1, 0x7C6A41EF,
0x58618E73, 0xBCC61595, 0xC035DCF3, 0xA624D1A5,
0xF73ADCCB, 0x40FD8D0E, 0xF8E7179B, 0xDFA0795D,
0xE332E3D3, 0xDD514B8F, 0xF3A35BDC, 0x41309E5C,
0x69BD1051, 0xE5280DD9, 0x1D319B29, 0xF291D296,
0x725C62C0, 0x6022B2AA, 0xB1F94727, 0x96C44950,
0x6EA2711E, 0xDCC479FA, 0xE32C59A4, 0xCF067207,
0xC83C3204, 0x58C97481, 0xB17567C7, 0x8823DD90,
0x2297E4F6, 0x48F5E77D, 0x84973489, 0x81EAD180,
0x4290ABFC, 0x5591A8B1, 0x8C4E7663, 0xC0DD2DCD,
0x5041AA71, 0x526EB6B0, 0x9E9DC448, 0x745788B5,
0x66EBBD1A, 0xF18A915B, 0x4DB6DDD6, 0x89B3A4DE,
0x51F61F7A, 0x124E16A7, 0x8333C2C7, 0x4599A5BE,
0xCDC39263, 0xC567E7A3, 0xF2854DAD, 0x1205A63C,
0x5C9AD7D0, 0xD27999B9, 0x00A445DE, 0x5FBD9597,
0x847A97F2, 0xF1903833, 0x5E6D1CAC, 0x4F4D7E87,
0x379E0388, 0xF2E4DA01, 0x04DDC9D9, 0x7E5E9CA1,
0xEFF8C773, 0xB3EA4FB8, 0xB9F07B49, 0x249FE3FF,
0x2B462589, 0x3D792DDE, 0xE9450BF9, 0xD5BCDF1F,
0x12B046A9, 0x7C3BB764, 0xC876762F, 0x1E4A070B,
0x1BD21A0E, 0x368F6C73, 0x4318B4F3, 0x865BF9BA,
0xDA2755E8, 0xBA2A416B, 0x892EC8BD, 0xAFF132B6,
0x5D236D28, 0x042DC228, 0xCBAFD36F, 0x8FAC29FE,
0xC1618E9B, 0x3032A586, 0x60AD7F85, 0x8DD5FD2D,
0xC7ED013A, 0xDA7B9527, 0x531D268A, 0x828006DA,
0xA6C271BF, 0xEF262D73, 0x1C686ACD, 0x6C1D0842,
0xFEA0057B, 0x781D79DF, 0xB7013855, 0xCA50C924,
0x2D434666, 0x3E017172, 0x5C806111, 0x293F51EC,
0x9D913C77, 0x216B3785, 0x86954853, 0x82932413,
0x62164836, 0x9A2E24CA, 0x5380517F, 0x2B0414C5,
0x4710928F, 0xB5B1DC8E, 0x543905FF, 0x739EADC3,
0xA91125E8, 0xAC81F242, 0x56FC2679, 0x7FA6388A,
0x196D0474, 0xEDF3E337, 0xB40D1B44, 0x00E9D7B5,
0x2378CFC9, 0x878C68A8, 0x6F397817, 0x2707529F,
0x221ED5B0, 0x90D965FD, 0x8E648703, 0x889C774C,
0xDE08963B, 0xC405F74E, 0xEF4C0EA2, 0xC2123688,
0xCE92171D, 0x6BC26425, 0xBC16C790, 0xF2BADE50,
0x144E9835, 0x1871FA87, 0x2250351A, 0xC8AF1671,
0x304B7D6B, 0x2D2D1635, 0xD9FCD535, 0xF46B836F,
0xC0B781BF, 0xD945D82F, 0x45ACDBB2, 0x50EB33A8,
0x2761879F, 0xD0E25279, 0xE022ECAE, 0xDA193AB7,
0x81E39A78, 0x67272C20, 0x5B878A4E, 0x64361F1D,
0x2B83F58E, 0x2A9A017F, 0x507929AC, 0x8173FE1E,
0x971F2410, 0xF11304BE, 0xDBD4230C, 0xD9D689E8,
0x790B8E66, 0x4009A29B, 0xC00CF152, 0x8A9245FA,
0x571808CE, 0x18802F6C, 0xEDAA74B8, 0xAFF8A5C3,
0xDCCC3726, 0x8F8EE064, 0x15152CBB, 0xADB4F189,
0x0D2ADA0A, 0xF5CE9515, 0x9DCB9D56, 0xE6F8158C,
0x36A35921, 0x14E83535, 0x135B5372, 0x916FBF6B,
0x9AE11EB4, 0xB395A6A4, 0x7A813C9C, 0xF4C76DC5,
0x0FFC9880, 0xD9AD9FAD, 0xB7CB45F8, 0x73385623,
0x947AF1CC, 0x77A3D98B, 0x18407675, 0x00974514,
0x50C6DABC, 0x237B672F, 0x7333F841, 0x729DDC99,
0xD09DF0E7, 0x98C13440, 0x45BAC57F, 0x391ED4C3,
0x32939D28, 0xDE00F063, 0x8B82EC37, 0x55AB229A,
0x8C837AB1, 0x3086EABC, 0x21469D8E, 0xC2282941,
0x0EDA9B65, 0xB365A1B3, 0xCA047C36, 0x2B355957,
0x57403D65, 0xF0DE0AFA, 0xD4C9DE27, 0xE841E29F,
0x8A9BC5EB, 0x61B5D7CF, 0x2472F58E, 0x46195BE2,
0xEFFF1557, 0xC4F7397E, 0x78901506, 0x83B88513,
0xEED98887, 0x4049EA2A, 0x3DDE8305, 0xAAA987B4,
0x24493B6B, 0x2DCD7DCB, 0x80B69098, 0xB6395978,
0x32A560D7, 0x94593F7A, 0x73B7E752, 0x2DCE252A,
0x84B5C39A, 0x7A861EEC, 0x24184281, 0x78C0DDCD,
0x58B8C4D0, 0x482B723B, 0xAA8807A3, 0x339A6003,
0x779A6B74, 0xF53F8FEC, 0x5EE37218, 0xC1B6C5B2,
0x47D45939, 0xD499852D, 0x351E4618, 0x3157CFE4,
0xCA97B899, 0xDD216C5E, 0x8E433EE6, 0x65598AEE,
0x325F782D, 0xB0D127D2, 0x003FAC45, 0xD54A90D4,
0x651A673F, 0x8EBF84D6, 0x25C6F32B, 0x34DB8DEB,
0xF702079D, 0x688C0AF1, 0xA420E5B4, 0xFCAFEBC0,
0x272C28B0, 0x8C21FB6D, 0xAA712659, 0x4AD3C638,
0xA1329FCC, 0x8D2D4516, 0x1C350A61, 0x6EB98EF8,
0x512DB1C8, 0x2E047041, 0xF298AF97, 0xE5E40306,
0x55F301D1, 0x1276C70F, 0xAD1B393C, 0xA98756B0,
0x0A54197B, 0xA81E3DF2, 0xA505683F, 0xACB6BBAC
};

File diff suppressed because it is too large Load Diff

358
ccan/darray/test/run.c Normal file
View File

@ -0,0 +1,358 @@
#include <ccan/tap/tap.h>
#include <ccan/darray/darray.h>
#include <stdio.h>
#include "lotsOfNumbers.h"
#include "lotsOfStrings.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
struct {
char *stringsF, *stringsB;
//items of lotsOfStrings glued together
size_t stringsSize; //total strlen of all strings combined
} amalgams;
static void generateAmalgams(void);
static void freeAmalgams(void);
static int isZeros(void *ptr, size_t size);
static void memtile(void *dest, size_t destWidth, const void *src, size_t srcWidth);
#if 0
#define testing(...) printf("Testing %s...\n", #__VA_ARGS__)
#define trace(...) do {printf(__VA_ARGS__); puts("");} while(0)
#else
#define testing(...) do {} while(0)
#define trace(...) do {} while(0)
#endif
#include "testLits.h"
int main(void) {
darray(long) arr = darray_new();
darray_char str = darray_new();
#define reset(arr) do {darray_free(arr); darray_init(arr);} while(0)
size_t i;
trace("Generating amalgams (internal)");
generateAmalgams();
plan_tests(41);
testLits();
testing(darray_push);
{
for (i=0; i < ARRAY_SIZE(lotsOfNumbers); i++)
darray_push(arr, lotsOfNumbers[i]);
ok1(darray_size(arr) == ARRAY_SIZE(lotsOfNumbers));
ok1(darray_alloc(arr) >= darray_size(arr));
ok1(!memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)));
}
reset(arr);
testing(darray_prepend, darray_pop);
{
for (i = ARRAY_SIZE(lotsOfNumbers); i;)
darray_prepend(arr, lotsOfNumbers[--i]);
ok1(darray_size(arr) == ARRAY_SIZE(lotsOfNumbers));
ok1(darray_alloc(arr) >= darray_size(arr));
ok1(!memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)));
for (i = ARRAY_SIZE(lotsOfNumbers); i;) {
if (darray_pop(arr) != (long)lotsOfNumbers[--i]) {
i++;
break;
}
}
ok1(i==0);
ok1(darray_size(arr) == 0);
}
reset(arr);
testing(darray_from_c, darray_foreach, darray_foreach_reverse);
{
long *i;
size_t j;
darray_from_c(arr, lotsOfNumbers);
ok1(darray_size(arr) == ARRAY_SIZE(lotsOfNumbers));
ok1(darray_alloc(arr) >= darray_size(arr));
ok1(memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)) == 0);
j = 0;
darray_foreach(i, arr) {
if (i - arr.item != j)
break;
if (*i != (long)lotsOfNumbers[j])
break;
j++;
};
ok1(j == ARRAY_SIZE(lotsOfNumbers));
j = 0;
darray_foreach_reverse(i, arr) {
if (i - arr.item != darray_size(arr)-j-1)
break;
if (*i != (long)lotsOfNumbers[darray_size(arr)-j-1])
break;
j++;
};
ok1(j == ARRAY_SIZE(lotsOfNumbers));
}
reset(arr);
testing(darray_append_string);
{
for (i=0; i < ARRAY_SIZE(lotsOfStrings); i++)
darray_append_string(str, lotsOfStrings[i]);
ok1(str.size == amalgams.stringsSize);
ok1(str.alloc > str.size);
ok1(str.item[str.size] == 0);
ok1(!strcmp(str.item, amalgams.stringsF));
}
reset(str);
testing(darray_prepend_string);
{
for (i=0; i < ARRAY_SIZE(lotsOfStrings); i++)
darray_prepend_string(str, lotsOfStrings[i]);
ok1(str.size == amalgams.stringsSize);
ok1(str.alloc > str.size);
ok1(str.item[str.size] == 0);
ok1(!strcmp(str.item, amalgams.stringsB));
}
reset(str);
testing(darray_from_string);
{
for (i=0; i < ARRAY_SIZE(lotsOfStrings); i++) {
darray_from_string(str, lotsOfStrings[i]);
if (str.size != strlen(lotsOfStrings[i]))
break;
if (str.alloc < strlen(lotsOfStrings[i])+1)
break;
if (strcmp(str.item, lotsOfStrings[i]))
break;
}
ok1(i == ARRAY_SIZE(lotsOfStrings));
}
reset(str);
testing(darray_resize0);
{
size_t prevSize=0, size;
for (i=0; i < ARRAY_SIZE(lotsOfNumbers); i++, prevSize=size) {
size = lotsOfNumbers[i] & 0xFFFF;
darray_resize0(arr, size);
if (darray_size(arr) != size)
break;
if (darray_alloc(arr) < size)
break;
if (size>prevSize) {
if (!isZeros(arr.item+prevSize, (size-prevSize)*sizeof(*arr.item)))
break;
}
//fill the darray with lotsOfNumbers garbage
memtile(arr.item, darray_size(arr)*sizeof(*arr.item), lotsOfNumbers, sizeof(lotsOfNumbers));
}
ok1(i == ARRAY_SIZE(lotsOfNumbers));
}
reset(arr);
testing(darray_realloc);
{
size_t s,a;
for (i=0; i < ARRAY_SIZE(lotsOfNumbers); i++) {
arr.size = (s = lotsOfNumbers[i] >> 16);
//give size a nonsense value to make sure darray_realloc doesn't care about it
a = amalgams.stringsSize/sizeof(*arr.item)+2;
darray_realloc(arr, a = lotsOfNumbers[i] % ((amalgams.stringsSize/sizeof(*arr.item))+1));
if (a*sizeof(*arr.item) > amalgams.stringsSize)
break;
if (darray_alloc(arr) != a)
break;
if (darray_size(arr) != s)
break;
memtile(arr.item, a*sizeof(*arr.item), amalgams.stringsF, a*sizeof(*arr.item));
if (memcmp(arr.item, amalgams.stringsF, a*sizeof(*arr.item)))
break;
}
ok1(i == ARRAY_SIZE(lotsOfNumbers));
}
reset(arr);
testing(darray_growalloc);
{
size_t prevA, s, a;
for (i=0; i < ARRAY_SIZE(lotsOfNumbers); i++) {
arr.size = (s = lotsOfNumbers[i] >> 16);
//give size a nonsense value to make sure darray_growalloc doesn't care about it
a = amalgams.stringsSize/sizeof(*arr.item)+2;
prevA = darray_alloc(arr);
darray_growalloc(arr, a = lotsOfNumbers[i] % ((amalgams.stringsSize/sizeof(*arr.item))+1));
if (a*sizeof(*arr.item) > amalgams.stringsSize)
break;
if (darray_alloc(arr) < a)
break;
if (darray_alloc(arr) < prevA)
break;
if (darray_size(arr) != s)
break;
memtile(arr.item, a*sizeof(*arr.item), amalgams.stringsF, a*sizeof(*arr.item));
if (memcmp(arr.item, amalgams.stringsF, a*sizeof(*arr.item)))
break;
//clear the darray every now and then
if (!(lotsOfNumbers[i] & 15)) {
reset(arr);
}
}
ok1(i == ARRAY_SIZE(lotsOfNumbers));
}
reset(arr);
testing(darray_make_room);
{
for (i=0; i < ARRAY_SIZE(lotsOfStrings); i++) {
char *dest = darray_make_room(str, strlen(lotsOfStrings[i]));
if (str.alloc < str.size+strlen(lotsOfStrings[i]))
break;
if (dest != str.item+str.size)
break;
memcpy(dest, lotsOfStrings[i], strlen(lotsOfStrings[i]));
str.size += strlen(lotsOfStrings[i]);
}
ok1(i == ARRAY_SIZE(lotsOfStrings));
ok1(str.size == amalgams.stringsSize);
darray_append(str, 0);
ok1(!strcmp(str.item, amalgams.stringsF));
}
reset(str);
testing(darray_appends, darray_prepends, darray_pop_check);
{
darray(const char*) arr = darray_new();
const char *n[9] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight"};
#if HAVE_TYPEOF
darray_appends(arr, n[5], n[6], n[7], n[8]);
#else
darray_appends_t(arr, const char *, n[5], n[6], n[7], n[8]);
#endif
ok1(darray_size(arr)==4 && darray_alloc(arr)>=4);
#if HAVE_TYPEOF
darray_prepends(arr, n[0], n[1], n[2], n[3], n[4]);
#else
darray_prepends_t(arr, const char *, n[0], n[1], n[2], n[3], n[4]);
#endif
ok1(darray_size(arr)==9 && darray_alloc(arr)>=9);
ok1(arr.item[0]==n[0] &&
arr.item[1]==n[1] &&
arr.item[2]==n[2] &&
arr.item[3]==n[3] &&
arr.item[4]==n[4] &&
arr.item[5]==n[5] &&
arr.item[6]==n[6] &&
arr.item[7]==n[7] &&
arr.item[8]==n[8]);
ok1(darray_pop_check(arr)==n[8] &&
darray_pop_check(arr)==n[7] &&
darray_pop_check(arr)==n[6] &&
darray_pop_check(arr)==n[5] &&
darray_pop_check(arr)==n[4] &&
darray_pop_check(arr)==n[3] &&
darray_pop_check(arr)==n[2] &&
darray_pop_check(arr)==n[1] &&
darray_pop_check(arr)==n[0]);
ok1(darray_size(arr)==0);
ok1(darray_pop_check(arr)==NULL && darray_pop_check(arr)==NULL && darray_pop_check(arr)==NULL);
darray_free(arr);
}
trace("Freeing amalgams (internal)");
freeAmalgams();
return exit_status();
}
static void generateAmalgams(void) {
size_t i;
size_t lotsOfStringsLen = 0;
const char *src;
char *p;
for (i=0; i < ARRAY_SIZE(lotsOfStrings); i++)
lotsOfStringsLen += strlen(lotsOfStrings[i]);
amalgams.stringsSize = lotsOfStringsLen;
amalgams.stringsF = malloc(lotsOfStringsLen+1);
amalgams.stringsB = malloc(lotsOfStringsLen+1);
for (i=0,p=amalgams.stringsF; i < ARRAY_SIZE(lotsOfStrings); i++) {
size_t len = strlen(src=lotsOfStrings[i]);
memcpy(p, src, len);
p += len;
}
*p = 0;
ok1(p-amalgams.stringsF == (long)lotsOfStringsLen);
ok1(strlen(amalgams.stringsF) == lotsOfStringsLen);
for (i = ARRAY_SIZE(lotsOfStrings), p = amalgams.stringsB; i--;) {
size_t len = strlen(src=lotsOfStrings[i]);
memcpy(p, src, len);
p += len;
}
*p = 0;
ok1(p-amalgams.stringsB == (long)lotsOfStringsLen);
ok1(strlen(amalgams.stringsB) == lotsOfStringsLen);
}
static void freeAmalgams(void) {
free(amalgams.stringsF);
free(amalgams.stringsB);
}
static int isZeros(void *ptr, size_t size) {
unsigned char *pc = ptr;
size_t *pl;
if (size>8) {
//test one byte at a time until we have an aligned size_t pointer
while ((size_t)pc & (sizeof(size_t)-1))
if (*pc++)
return 0;
pl = (size_t*)pc;
size -= pc-(unsigned char*)ptr;
while (size >= sizeof(size_t)) {
size -= sizeof(size_t);
if (*pl++)
return 0;
}
pc = (unsigned char*)pl;
}
while (size--)
if (*pc++)
return 0;
return 1;
}
static void memtile(void *dest, size_t destWidth, const void *src, size_t srcWidth) {
char *d = dest;
while (destWidth > srcWidth) {
destWidth -= srcWidth;
memcpy(d, src, srcWidth);
d += srcWidth;
}
memcpy(d, src, destWidth);
}

569
ccan/darray/test/testLits.h Normal file
View File

@ -0,0 +1,569 @@
static int testdarray_from_lit(void);
static int testdarray_append_lit(void);
static int testdarray_prepend_lit(void);
static void testLits(void) {
testing(darray_from_lit);
ok1(testdarray_from_lit());
testing(testdarray_append_lit);
ok1(testdarray_append_lit());
testing(testdarray_prepend_lit);
ok1(testdarray_prepend_lit());
}
static int testdarray_from_lit(void) {
darray_char a = darray_new();
size_t testsPassed = 0;
size_t len = 0;
/* Test 0 */
darray_from_lit(a, "\xC0\x19\xDE\x94\xC9\xB1_\xDF\xBEr[\xBB\x43\x65\xC7\xD8\x93\xB7\x16u\x1D\x8C\x64\x91\xF5\xDE*GC\xECp\xCA!\x15\xF0\x07(b(\x87\xE0nDP\xC5\x1C\xC5\xB4\x38\xC3i\xA6\xEE\x81\xB0p\x9C\x94\xA2w\xA2$\xF5%rS\xF3\\f\x1A\xF4\xFC\x93\xDD'\xE8\xA7\x11\xF4\xF7\xC9\xCE\x92I\xF6\x94p");
len = strlen("\xC0\x19\xDE\x94\xC9\xB1_\xDF\xBEr[\xBB\x43\x65\xC7\xD8\x93\xB7\x16u\x1D\x8C\x64\x91\xF5\xDE*GC\xECp\xCA!\x15\xF0\x07(b(\x87\xE0nDP\xC5\x1C\xC5\xB4\x38\xC3i\xA6\xEE\x81\xB0p\x9C\x94\xA2w\xA2$\xF5%rS\xF3\\f\x1A\xF4\xFC\x93\xDD'\xE8\xA7\x11\xF4\xF7\xC9\xCE\x92I\xF6\x94p");
if (len != sizeof("\xC0\x19\xDE\x94\xC9\xB1_\xDF\xBEr[\xBB\x43\x65\xC7\xD8\x93\xB7\x16u\x1D\x8C\x64\x91\xF5\xDE*GC\xECp\xCA!\x15\xF0\x07(b(\x87\xE0nDP\xC5\x1C\xC5\xB4\x38\xC3i\xA6\xEE\x81\xB0p\x9C\x94\xA2w\xA2$\xF5%rS\xF3\\f\x1A\xF4\xFC\x93\xDD'\xE8\xA7\x11\xF4\xF7\xC9\xCE\x92I\xF6\x94p")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "\xC0\x19\xDE\x94\xC9\xB1_\xDF\xBEr[\xBB\x43\x65\xC7\xD8\x93\xB7\x16u\x1D\x8C\x64\x91\xF5\xDE*GC\xECp\xCA!\x15\xF0\x07(b(\x87\xE0nDP\xC5\x1C\xC5\xB4\x38\xC3i\xA6\xEE\x81\xB0p\x9C\x94\xA2w\xA2$\xF5%rS\xF3\\f\x1A\xF4\xFC\x93\xDD'\xE8\xA7\x11\xF4\xF7\xC9\xCE\x92I\xF6\x94p"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 1 */
darray_from_lit(a, "\xEC\x08\xC5\xB9\x97m\xA4\xBF\x12\x0E\xC6\xB4\x1FN\x13\xB0^\xBB\x32(*\xD5\x8DQ\x87o7\xBB\x01\x96z\xF0\xC3!\x04\x80\xD8\xDA\x18\xDB\xCA\x94\x1A\xD4\xBF\xE8\x83\xE2\xF6\x91yk\xA6\xE1\x96\x39\xFF)\xB2\xB3\xFC\xA6\xA7\xD8\xAE\xF8U\xCD)\xDD\x9Al\xFB\xDEw?\xD8\xD8\xBC\"z\xC9\x7F\x92r\tUm\x95\x17\xAD\x96=\xBE\xF5\xDD\x13\x8A\x62\x01\xB7\x0E\x06\xC2\xA1\xEE\x8Cje3O6\x9C_)v\xCD/\xB8z%\xA2> \xDF\x1B\xC1\x62\x8E\x14\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7F\x92r\tUm\x95\x17\xAD\x96=\xBE\xF5\xDD\x13\x8A\x62\x01\xB7\x0E\x06\xC2\xA1\xEE\x8Cje3O6\x9C_)v\xCD/\xB8z%\xA2> \xDF\x1B\xC1\x62\x8E\x14\x61\xA0\xCAl\xD3\x8D\xBA}C\x7F}~\xD9\xEB]\x8C\x9B\x9Cq\xB5\x38\xC4O\xC9\x17\xE6\xEF\xF7\x9E\x12\x1D\xA1\x13\x8F<\x9D\xEF\x92\x93w\x1F=\xFF\x8F\xDDJ\xBB\xD2}\x98\x1D)\xB3\x98\xE2n6/\xB0\x38\x44")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "\xEC\x08\xC5\xB9\x97m\xA4\xBF\x12\x0E\xC6\xB4\x1FN\x13\xB0^\xBB\x32(*\xD5\x8DQ\x87o7\xBB\x01\x96z\xF0\xC3!\x04\x80\xD8\xDA\x18\xDB\xCA\x94\x1A\xD4\xBF\xE8\x83\xE2\xF6\x91yk\xA6\xE1\x96\x39\xFF)\xB2\xB3\xFC\xA6\xA7\xD8\xAE\xF8U\xCD)\xDD\x9Al\xFB\xDEw?\xD8\xD8\xBC\"z\xC9\x7F\x92r\tUm\x95\x17\xAD\x96=\xBE\xF5\xDD\x13\x8A\x62\x01\xB7\x0E\x06\xC2\xA1\xEE\x8Cje3O6\x9C_)v\xCD/\xB8z%\xA2> \xDF\x1B\xC1\x62\x8E\x14\x61\xA0\xCAl\xD3\x8D\xBA}C\x7F}~\xD9\xEB]\x8C\x9B\x9Cq\xB5\x38\xC4O\xC9\x17\xE6\xEF\xF7\x9E\x12\x1D\xA1\x13\x8F<\x9D\xEF\x92\x93w\x1F=\xFF\x8F\xDDJ\xBB\xD2}\x98\x1D)\xB3\x98\xE2n6/\xB0\x38\x44"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 2 */
darray_from_lit(a, "~Er=L\xA6\xC0\xB1m\xC2\x66`\xA4\x89\xE6\xA8\xEE\x03,\xA5\xC4\xAD\xC5\xC1\xE5\x38\xA3\x99\x9F^\x13\x41]|\x81J=\xA9\xE5\xAC\f\xD6\x92/\x07z\x90+\x9C\xA4O\xF4\xC4\xA3\x12\"\xC2{\xB7\x1E\xA4\x66\xB5\xC8\xB4\x45\xC8#G\x15\x37\x33\x9E\x9B\x8D\x91 \x13\xE2(\x91QV5\xAD\v\v\xD1\x11\xB5i\xE3\xF0\x01Z\xF0\xFD\\\xFA\x07W\xD8p\xB4\x92\x1B/>\xAF\xFC\x83\xE6x");
len = strlen("~Er=L\xA6\xC0\xB1m\xC2\x66`\xA4\x89\xE6\xA8\xEE\x03,\xA5\xC4\xAD\xC5\xC1\xE5\x38\xA3\x99\x9F^\x13\x41]|\x81J=\xA9\xE5\xAC\f\xD6\x92/\x07z\x90+\x9C\xA4O\xF4\xC4\xA3\x12\"\xC2{\xB7\x1E\xA4\x66\xB5\xC8\xB4\x45\xC8#G\x15\x37\x33\x9E\x9B\x8D\x91 \x13\xE2(\x91QV5\xAD\v\v\xD1\x11\xB5i\xE3\xF0\x01Z\xF0\xFD\\\xFA\x07W\xD8p\xB4\x92\x1B/>\xAF\xFC\x83\xE6x");
if (len != sizeof("~Er=L\xA6\xC0\xB1m\xC2\x66`\xA4\x89\xE6\xA8\xEE\x03,\xA5\xC4\xAD\xC5\xC1\xE5\x38\xA3\x99\x9F^\x13\x41]|\x81J=\xA9\xE5\xAC\f\xD6\x92/\x07z\x90+\x9C\xA4O\xF4\xC4\xA3\x12\"\xC2{\xB7\x1E\xA4\x66\xB5\xC8\xB4\x45\xC8#G\x15\x37\x33\x9E\x9B\x8D\x91 \x13\xE2(\x91QV5\xAD\v\v\xD1\x11\xB5i\xE3\xF0\x01Z\xF0\xFD\\\xFA\x07W\xD8p\xB4\x92\x1B/>\xAF\xFC\x83\xE6x")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "~Er=L\xA6\xC0\xB1m\xC2\x66`\xA4\x89\xE6\xA8\xEE\x03,\xA5\xC4\xAD\xC5\xC1\xE5\x38\xA3\x99\x9F^\x13\x41]|\x81J=\xA9\xE5\xAC\f\xD6\x92/\x07z\x90+\x9C\xA4O\xF4\xC4\xA3\x12\"\xC2{\xB7\x1E\xA4\x66\xB5\xC8\xB4\x45\xC8#G\x15\x37\x33\x9E\x9B\x8D\x91 \x13\xE2(\x91QV5\xAD\v\v\xD1\x11\xB5i\xE3\xF0\x01Z\xF0\xFD\\\xFA\x07W\xD8p\xB4\x92\x1B/>\xAF\xFC\x83\xE6x"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 3 */
darray_from_lit(a, "h\xC2\x1E&\xB3\x43\x88\x11&i\x16\xA3\x05>\x94*D\x14&\x17%x\xB9z\x8F\x7F\x15LLU\x16\x1A\x34\x1C-\xD6\xD3\xEC\x89y\xB3\x82\xC4\xFBw\xAC\xE4\xDA\xC1\xB7\x17\xCC`u]\xC6\x99\x0F \x8F\xA8\x11\x86\xD8)\x01\xE6\x38\x30\xF7\xD1\xB6\x96\xAE\xC6<8`\xD3*\x9D p\x01\x85v\xB0\th\x81H\xFF]_\xF3\x15\x9D\xCB[\xF8/n\xC9\x1E\x89>\x9E\xC7/~\xEFQ\\\x1A_\xE4\xE5\xFC\x1C'\xEF\xC8\xE0\x43!\x8AYc_y\xBB\xEE\x7Fy\xF4Ms\xD2\x62\xBAY\xA9\xDC\xAA\xCE\xEDSz\x92m\xF2\x17mO\xB3[\x89\x1E\xBC\xED$\xF1\x07g4\x1B\nhr\xAF\x42\xCF\x1A\xA6\x83\x80(\xA2\x1C\x37\xE3\xFC\x05\xDC\x1F#\x92\"\xDD\x8BrRn\xF7\xCF\xB8\xD8\xEE\x1EwdaA#\xA0\x9E}\x85\xC8Gm\x1C<\xE7\x95\xD0\xC8\xB5X\xEF\x35\xB9\xD6XTW\x88\x8E\x05u\x80\x41\x83?\x9CL\xEA\x92L|%");
len = strlen("h\xC2\x1E&\xB3\x43\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xA9\xDC\xAA\xCE\xEDSz\x92m\xF2\x17mO\xB3[\x89\x1E\xBC\xED$\xF1\x07g4\x1B\nhr\xAF\x42\xCF\x1A\xA6\x83\x80(\xA2\x1C\x37\xE3\xFC\x05\xDC\x1F#\x92\"\xDD\x8BrRn\xF7\xCF\xB8\xD8\xEE\x1EwdaA#\xA0\x9E}\x85\xC8Gm\x1C<\xE7\x95\xD0\xC8\xB5X\xEF\x35\xB9\xD6XTW\x88\x8E\x05u\x80\x41\x83?\x9CL\xEA\x92L|%")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "h\xC2\x1E&\xB3\x43\x88\x11&i\x16\xA3\x05>\x94*D\x14&\x17%x\xB9z\x8F\x7F\x15LLU\x16\x1A\x34\x1C-\xD6\xD3\xEC\x89y\xB3\x82\xC4\xFBw\xAC\xE4\xDA\xC1\xB7\x17\xCC`u]\xC6\x99\x0F \x8F\xA8\x11\x86\xD8)\x01\xE6\x38\x30\xF7\xD1\xB6\x96\xAE\xC6<8`\xD3*\x9D p\x01\x85v\xB0\th\x81H\xFF]_\xF3\x15\x9D\xCB[\xF8/n\xC9\x1E\x89>\x9E\xC7/~\xEFQ\\\x1A_\xE4\xE5\xFC\x1C'\xEF\xC8\xE0\x43!\x8AYc_y\xBB\xEE\x7Fy\xF4Ms\xD2\x62\xBAY\xA9\xDC\xAA\xCE\xEDSz\x92m\xF2\x17mO\xB3[\x89\x1E\xBC\xED$\xF1\x07g4\x1B\nhr\xAF\x42\xCF\x1A\xA6\x83\x80(\xA2\x1C\x37\xE3\xFC\x05\xDC\x1F#\x92\"\xDD\x8BrRn\xF7\xCF\xB8\xD8\xEE\x1EwdaA#\xA0\x9E}\x85\xC8Gm\x1C<\xE7\x95\xD0\xC8\xB5X\xEF\x35\xB9\xD6XTW\x88\x8E\x05u\x80\x41\x83?\x9CL\xEA\x92L|%"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 4 */
darray_from_lit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\x66\xBC\x06\x63\x9D\x99\xF0\xCA\xD2\xD2\x9EO\xD2\f2\x96.p\x81\x82wP*\xC0m\x93\xD9\xCB \xED\x94r\xA9:\vU\x19i\xAD\x88\x12\xD1\x1CP\xE5&*\xD7\x06\xFE\x90\x96N\"\xF4\x1A \x89\x64\x38\x65\x32\xF5\x8B\xB5V\xD3\x8A\xC6\n\xF0\xC7u\xEC!\x10\xE5\x42\xE5\x61\x05\x94\x9B\x11v\xC8n%5\xEA\xBC\x41K(\xF6\xD8.\xADS+\xCB\xAD\xAE@;\xAFP^\xD9\xDD\xC1\x1F:\xFA\v\x99\x85g3\xAC\x84\xC8xA\x1F\xA2\x9E\x89\x1F\x41\x08\x61\x41\x9C\x06\x07\x46\xF1\xBE\x83\x42\xF9\xAA\xD5\r\x8AUZ\x1E-\xF7\xD4\x9D\xAC\x04\xFF#\no\xBF\xC5\x9E\n0\x12\x64\x96\xFF\xF5'\xD6j\x10'\xE7\xB2rB2X\xBCY\xD9\x44\x9E\x1E\xBB-\t\x84+\xA8[z\x87\xF8\xE3K\xD1R'\xB0\xBA\x13\xBF\x64\xFA\x85g\x81{\xC6\xDC\xBA\xCF\x85wd\xC3u\xDC\x33\xF0t\\.&<\x92~\xC4_\xCF\xBC\xB9\xE9\x31\x65\x1B\x1F+\xEF\x32\xD3\xEB,\xE6\x36\x06*3\xB0")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "\"\xD3\x84h)\xB7{\xB8\xDB\xD6y\xE9\x16+\xAD\xC4\xE9n\xDBZ\xAB\x38}3ic\xDE\x64\xC4\x91`\xE7\xD9I\xDC\xF8\xC3*/\x85P\xFB\xB7\x95lk5\xF4\xE2\x02\x15K\xDE\xF9\xA4l\xDEQ\xFE\x14G\xD5\t\xC3\x62;\rU\xF9\xBF\x99\x9F\x9D\x92U\x9D\x66\xBC\x06\x63\x9D\x99\xF0\xCA\xD2\xD2\x9EO\xD2\f2\x96.p\x81\x82wP*\xC0m\x93\xD9\xCB \xED\x94r\xA9:\vU\x19i\xAD\x88\x12\xD1\x1CP\xE5&*\xD7\x06\xFE\x90\x96N\"\xF4\x1A \x89\x64\x38\x65\x32\xF5\x8B\xB5V\xD3\x8A\xC6\n\xF0\xC7u\xEC!\x10\xE5\x42\xE5\x61\x05\x94\x9B\x11v\xC8n%5\xEA\xBC\x41K(\xF6\xD8.\xADS+\xCB\xAD\xAE@;\xAFP^\xD9\xDD\xC1\x1F:\xFA\v\x99\x85g3\xAC\x84\xC8xA\x1F\xA2\x9E\x89\x1F\x41\x08\x61\x41\x9C\x06\x07\x46\xF1\xBE\x83\x42\xF9\xAA\xD5\r\x8AUZ\x1E-\xF7\xD4\x9D\xAC\x04\xFF#\no\xBF\xC5\x9E\n0\x12\x64\x96\xFF\xF5'\xD6j\x10'\xE7\xB2rB2X\xBCY\xD9\x44\x9E\x1E\xBB-\t\x84+\xA8[z\x87\xF8\xE3K\xD1R'\xB0\xBA\x13\xBF\x64\xFA\x85g\x81{\xC6\xDC\xBA\xCF\x85wd\xC3u\xDC\x33\xF0t\\.&<\x92~\xC4_\xCF\xBC\xB9\xE9\x31\x65\x1B\x1F+\xEF\x32\xD3\xEB,\xE6\x36\x06*3\xB0"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 5 */
darray_from_lit(a, "\x16\x33\xBB\xD6\xAB\xCC\n\xBC{\xD3\xC0\xC2>Gc\xAC\xAB\xC8T\xBA\x17\x30`\x8E\x8D\xACs\x93]\xF8\x96\xDE\x07\n\xBF\x35\\[\xA7\xDF\x38\xFC\xCC\na\xFFx\x96\x05\xFD'\r&\xFE\x35\xB5\xBAY\x14=\xE2\x1D\x9B_S^\x1C\ne\xC4\xED\x89\x88\x07\x1En\x1A\x32vV\xE2m\x93\x94`]'\x07\xFE*\x1F\xAB\x96\xBAQZtfOa\xE5\x19\xDB\x13@/\x9F\x96\x37u\x9C\xEE\x0Fh\x80w\xBB\xE4\xB5\x12\x83\x83\x0F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*\xD7?\xBD|\x84\x93\xE3\xBD\xC3\xEFyP\xC8\xF5\x64|\xB0\x62\t*\x9C\x39\n\x93\xBA\xF8\xD9\xE1\x97r\xCE\xF2\xFE\r\xB6\xE1\xAA~\xEE\x33\x08u\x12\xC8\x17\x90\xBF\xC1\xFE;YF\x9F\xD9\xE4y\xD9I`\xC6\x93j\x94\x02\x34\x65OB\x9F\x99Z\v\x8A\x1AJ@\xFE\xCB\xFCly+f\xC7\x8F\x1A\xFD\xBDJ\xAFhnk\x15G\xCC\x9DPI?B\xDD\xBC\x9B\x12\xE8\x42y8")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "\x16\x33\xBB\xD6\xAB\xCC\n\xBC{\xD3\xC0\xC2>Gc\xAC\xAB\xC8T\xBA\x17\x30`\x8E\x8D\xACs\x93]\xF8\x96\xDE\x07\n\xBF\x35\\[\xA7\xDF\x38\xFC\xCC\na\xFFx\x96\x05\xFD'\r&\xFE\x35\xB5\xBAY\x14=\xE2\x1D\x9B_S^\x1C\ne\xC4\xED\x89\x88\x07\x1En\x1A\x32vV\xE2m\x93\x94`]'\x07\xFE*\x1F\xAB\x96\xBAQZtfOa\xE5\x19\xDB\x13@/\x9F\x96\x37u\x9C\xEE\x0Fh\x80w\xBB\xE4\xB5\x12\x83\x83\x0F\xC0\x1BK\xE9\xDD_\x07\xB3\r\x95\xF1\xDAs\x91\xCE\x9EI\x88\xC7\x15\xC6@\xD1W\x15/c\x97\xDD\x41:P\x93\xF0\xB7\x42\x16\xFA\x84Zv[\xCC\x39\xA1*xcV\x90\xB3\xC4!\x03\xB1\xC3\x43$U\xC5;\xE5\xA2\x92Y]\xB5\x14U'\x12\x44oE\xCB^\x06\x89\x14\xCC\x97<\xFFi\xC8\x8D\xDB\x10\xD2\xA0\vtw>\xD7Q\xA8\xA1\xEA\xA6\x84\xED\xB6\x8C\x84za,|\x1Ahm\x98\x34j\x92k\xE3\x39\xAC\xCE\x96\xF8\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?\xCA\x42JUULji\xADN\xBD\x06\x93\xAB\xA2\xD6\x8F\x45\xF8~,\xE0\x95\xAD\xE6\xD5\x1BJ\x80\x0E\xC8L\x01\xC2\xE4\x39\xD4\xCE%5\xC3\xA4\xC6\x04{}\x89\n\xFF\x46\x16\xAF\x63\x0E\xE1\x99S\xAB\x63\x41(\xE8\xA8\xC0\x8F\xB2\xC8z\xDA\xA5\xF5\xC2\x13\x38\xA7K\xC9\xBD\xC0\xFD\xA2\xA5\xF5h\x08\xAD\xD0x&\xA7\xB1\v\xE6lTc$\x16\x81\x12Qs\xAA\xFE\xF6\xCD\xC9\xF5\xAD\x1A*lm\xB2\xDB\xC7\x08m;\xCE\x1C\xC9\xD7&VG\x07\xE9\x93\xE7\x04\x86\xF3\xD1[\xAE\x87:Ce\xE5\x61@\x9DV\x89+\xEA(\xF7\xB2\xB5g\xF4\xFF\x61\xDF\x92\xD8\x97\x96|}kb\xED\xB5\x04@\xC3\xF9=\xF1\x39\x03I\x87\xEF\xC5\x37t\xCC\x80;\x1A\xCE\x34\x37\x96\xDBHq\x1D\xF0\xE8\x92\x8B\xC4\x61\xF3\xD6\xA2\x35\x33\x34\x90\xB6Jbr\x7F\x8FI\xF4\x18\xCE\x04\v\xA0\x33K\x1D\xC2\x9F\xA9\x1A\xFDi\xFCn\x18\xD0\xBE-$2\x9BK\xD9\xBF\xD7Q.\xFD\x80\x0F")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "ZE\x16p\xE4ni/\xD6\x35\x81L\x8E\xF8\x1B$\xC9\xA7\x88\xEE,\x02\xA1\x31\x97.\x9AYn\x9E\x8C\xDC\x9E{<\x0F\xF5\x15\"{`&|\x1Fk\xFE\x44z\xABq\xB9.\xE2O\x07\xB4\x1B~\x87\xBBO\xBB\xC6\xA5\xA5Z\x1F\x8Ezu9\xC6\x46\x96\x94\xCA$\x88>\x14I\xEA\xF7\x31\xF3\x95H\x8E\"x.\xEC\xEF\xC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\x90\xB6Jbr\x7F\x8FI\xF4\x18\xCE\x04\v\xA0\x33K\x1D\xC2\x9F\xA9\x1A\xFDi\xFCn\x18\xD0\xBE-$2\x9BK\xD9\xBF\xD7Q.\xFD\x80\x0F"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 7 */
darray_from_lit(a, ")~\x96\x02\xE7h9\xB1\x65\x35\x8B\xF8\r\x81\x07\xCD\x9F\xD8-\xE2LB\xA1\xEA\n\x7F\xB1\xBFP15\x88\x32\x9C\x34\xCF\x02\xF8\x64\x8F\x43+\x1B\xB1\x8B\xAC\xB4\x96\xB3\xCB\xDB\x64\xF8\x91\xC0o$\f\x9A\xF6!\x97=jmU\xFD\x9C\xDB}\x15\x81\xAF\xE4q\x8C\xD7\xB8>\x9B\n\x96\f\xE0/Z\x1B\xB9\xE6|;/\xD2\x93\xC9\xC3\x63\x0FP#-\xF5\xDF\xF5\xFB@$\xB9\xEDG\xBF\xC1\xE2\xBF\xF8\x30\xC5p\xFB\xFF\xA9\xA6\xF7\xBD\xFD@\xC2\xFD\x92 \xA0\x91H\xA5\xD1\xC4\xCF\xB7\xD9T\xA9v\xF8q \xBA?\x9B\xA9@\xC8.\xBC\x89\xC0\x62\xD1\x38\x98\x83V\xB6\xB8\x85\x66\x1C\xC9Y\xCE\x8D\xF4\xCA\xCC\xDF\xB4\x06\xE1\xFC|\xA5i\xE2\x85\x02T\xEE\x35P\xDE\xDE\xE8\xE7Y\xB1\xDC:\x8A\xF6=a\xD8\x7F");
len = strlen(")~\x96\x02\xE7h9\xB1\x65\x35\x8B\xF8\r\x81\x07\xCD\x9F\xD8-\xE2LB\xA1\xEA\n\x7F\xB1\xBFP15\x88\x32\x9C\x34\xCF\x02\xF8\x64\x8F\x43+\x1B\xB1\x8B\xAC\xB4\x96\xB3\xCB\xDB\x64\xF8\x91\xC0o$\f\x9A\xF6!\x97=jmU\xFD\x9C\xDB}\x15\x81\xAF\xE4q\x8C\xD7\xB8>\x9B\n\x96\f\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(strcmp(a.item, ")~\x96\x02\xE7h9\xB1\x65\x35\x8B\xF8\r\x81\x07\xCD\x9F\xD8-\xE2LB\xA1\xEA\n\x7F\xB1\xBFP15\x88\x32\x9C\x34\xCF\x02\xF8\x64\x8F\x43+\x1B\xB1\x8B\xAC\xB4\x96\xB3\xCB\xDB\x64\xF8\x91\xC0o$\f\x9A\xF6!\x97=jmU\xFD\x9C\xDB}\x15\x81\xAF\xE4q\x8C\xD7\xB8>\x9B\n\x96\f\xE0/Z\x1B\xB9\xE6|;/\xD2\x93\xC9\xC3\x63\x0FP#-\xF5\xDF\xF5\xFB@$\xB9\xEDG\xBF\xC1\xE2\xBF\xF8\x30\xC5p\xFB\xFF\xA9\xA6\xF7\xBD\xFD@\xC2\xFD\x92 \xA0\x91H\xA5\xD1\xC4\xCF\xB7\xD9T\xA9v\xF8q \xBA?\x9B\xA9@\xC8.\xBC\x89\xC0\x62\xD1\x38\x98\x83V\xB6\xB8\x85\x66\x1C\xC9Y\xCE\x8D\xF4\xCA\xCC\xDF\xB4\x06\xE1\xFC|\xA5i\xE2\x85\x02T\xEE\x35P\xDE\xDE\xE8\xE7Y\xB1\xDC:\x8A\xF6=a\xD8\x7F"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 8 */
darray_from_lit(a, "!\xB5\xEB\xC0[\xE5\x35\x1F\x44\x84.\r\xE7\x44\xD3\nJ\xD8`\xFA\x85\x03\xE1_rm\xDD\x04yn\x90S\x8DH\x01\x0F\n(:\xD5\x14\x1C\x42\x81#&%;Y\xC7\xBA\x91\xEFhA\x12\x92\x04\x41\x96j\xB3R\x8D\xDF\x87\x16^\xBE\x42$0\xF9j\x13y\xB3\x61I\x8A\x8C+m\x9B\xD4=\x8A/q\fR@^\x97H2Gb\x1D\vA\v\r\xE1\xC5\x88rd\x88\x8B\xF0\xC0[\x8C\x45\x37\xC1\x45\xC8\x1F\\3\xB7\xD5\xAA\x98\xCD\x19\xE4*\xCDk\x95\xFE\x04\x33\x38\x14\x11\xA2p");
len = strlen("!\xB5\xEB\xC0[\xE5\x35\x1F\x44\x84.\r\xE7\x44\xD3\nJ\xD8`\xFA\x85\x03\xE1_rm\xDD\x04yn\x90S\x8DH\x01\x0F\n(:\xD5\x14\x1C\x42\x81#&%;Y\xC7\xBA\x91\xEFhA\x12\x92\x04\x41\x96j\xB3R\x8D\xDF\x87\x16^\xBE\x42$0\xF9j\x13y\xB3\x61I\x8A\x8C+m\x9B\xD4=\x8A/q\fR@^\x97H2Gb\x1D\vA\v\r\xE1\xC5\x88rd\x88\x8B\xF0\xC0[\x8C\x45\x37\xC1\x45\xC8\x1F\\3\xB7\xD5\xAA\x98\xCD\x19\xE4*\xCDk\x95\xFE\x04\x33\x38\x14\x11\xA2p");
if (len != sizeof("!\xB5\xEB\xC0[\xE5\x35\x1F\x44\x84.\r\xE7\x44\xD3\nJ\xD8`\xFA\x85\x03\xE1_rm\xDD\x04yn\x90S\x8DH\x01\x0F\n(:\xD5\x14\x1C\x42\x81#&%;Y\xC7\xBA\x91\xEFhA\x12\x92\x04\x41\x96j\xB3R\x8D\xDF\x87\x16^\xBE\x42$0\xF9j\x13y\xB3\x61I\x8A\x8C+m\x9B\xD4=\x8A/q\fR@^\x97H2Gb\x1D\vA\v\r\xE1\xC5\x88rd\x88\x8B\xF0\xC0[\x8C\x45\x37\xC1\x45\xC8\x1F\\3\xB7\xD5\xAA\x98\xCD\x19\xE4*\xCDk\x95\xFE\x04\x33\x38\x14\x11\xA2p")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "!\xB5\xEB\xC0[\xE5\x35\x1F\x44\x84.\r\xE7\x44\xD3\nJ\xD8`\xFA\x85\x03\xE1_rm\xDD\x04yn\x90S\x8DH\x01\x0F\n(:\xD5\x14\x1C\x42\x81#&%;Y\xC7\xBA\x91\xEFhA\x12\x92\x04\x41\x96j\xB3R\x8D\xDF\x87\x16^\xBE\x42$0\xF9j\x13y\xB3\x61I\x8A\x8C+m\x9B\xD4=\x8A/q\fR@^\x97H2Gb\x1D\vA\v\r\xE1\xC5\x88rd\x88\x8B\xF0\xC0[\x8C\x45\x37\xC1\x45\xC8\x1F\\3\xB7\xD5\xAA\x98\xCD\x19\xE4*\xCDk\x95\xFE\x04\x33\x38\x14\x11\xA2p"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
/* Test 9 */
darray_from_lit(a, "\xB7<\x14\x01\xC2\x91K\xC8O\xAD\xD2L\x83\\\x8B\xAE\x11\x1B\xB9\x44GR\xC7\xDD\xAD\x18\x0F\x14\x02\xE2R\r\x13I\xE0#\x9E$\x19\x89\x9C&t\x0F\xDF-w\xD0\x96yg\x86\x1B\x1E\xDF\x13\x0Er|\xB6\x38.,k\x11\xB9\xE5\xF2\xEC\xBD]\xB3\xAF\xD8\xA7\xF6\xFB\x0Ek\xA0\xC8\xD3\x46\xC2%\xE9t[\x05\xF9\x96g\x82.S;ZX\xED\x34Z\xF2'YD\x89o\xA1\xBB\xCB\xBE\xB3\x1B'M\n\xCESc(\xECT9\xA5\x83\x30\x80\x44\x08\x90\x33\xAE\x08\x62\"\xE6\x82G\xFDN\x95\xC1\x01\xFE/LS\x1A'Z3L\xF5\xC8\xE0>(_\x17\xDA\xCC\xED\xB6\xED\x84K7\x1B\x95-t\xE0<\xE4V\xE2\x94\x8F%\x83W\xDB\x99_\x9D-\xF9\x45\x18\xB8\x38\xE7\xD9\xDD\xAF\xE6\x62\x07\x95\x01\xB1\x8C_\x02\x80\xC1\xD8\\\x87\xBF\xEB\xF5\xFB \x9Cm\xE2n\x1Fm\xA8\x33\x1CY\";\x8F\x17\xE8\xD7\x9Aj\n\xF9\\\xC7\xEB\xF3\x88\xCDHXoJ\xD2\n\xECZ\x9AK\xD3-\xC3\xA9)pa%\x1E\x8A\x64\x8E$k0\xD3\x86p\x9A\x9A\x32\xF1x!\xA7\xB1HV\xCB\x94z\xB1\x33.W\xF6Vtp\x9C$`\x93\x8A\xC9S]\x99\x07\x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q\xAE\x35\xC3\x61\x1E\xF1\xBDvs/\xC2\xC9\xD9\x96\xA0t\x19\xC1\xA7\x04\xA8\x7F\xC4\xEC-\x1B\xD2\xE3\xF6\x9D\x12\xD2\xC2")-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, "\xB7<\x14\x01\xC2\x91K\xC8O\xAD\xD2L\x83\\\x8B\xAE\x11\x1B\xB9\x44GR\xC7\xDD\xAD\x18\x0F\x14\x02\xE2R\r\x13I\xE0#\x9E$\x19\x89\x9C&t\x0F\xDF-w\xD0\x96yg\x86\x1B\x1E\xDF\x13\x0Er|\xB6\x38.,k\x11\xB9\xE5\xF2\xEC\xBD]\xB3\xAF\xD8\xA7\xF6\xFB\x0Ek\xA0\xC8\xD3\x46\xC2%\xE9t[\x05\xF9\x96g\x82.S;ZX\xED\x34Z\xF2'YD\x89o\xA1\xBB\xCB\xBE\xB3\x1B'M\n\xCESc(\xECT9\xA5\x83\x30\x80\x44\x08\x90\x33\xAE\x08\x62\"\xE6\x82G\xFDN\x95\xC1\x01\xFE/LS\x1A'Z3L\xF5\xC8\xE0>(_\x17\xDA\xCC\xED\xB6\xED\x84K7\x1B\x95-t\xE0<\xE4V\xE2\x94\x8F%\x83W\xDB\x99_\x9D-\xF9\x45\x18\xB8\x38\xE7\xD9\xDD\xAF\xE6\x62\x07\x95\x01\xB1\x8C_\x02\x80\xC1\xD8\\\x87\xBF\xEB\xF5\xFB \x9Cm\xE2n\x1Fm\xA8\x33\x1CY\";\x8F\x17\xE8\xD7\x9Aj\n\xF9\\\xC7\xEB\xF3\x88\xCDHXoJ\xD2\n\xECZ\x9AK\xD3-\xC3\xA9)pa%\x1E\x8A\x64\x8E$k0\xD3\x86p\x9A\x9A\x32\xF1x!\xA7\xB1HV\xCB\x94z\xB1\x33.W\xF6Vtp\x9C$`\x93\x8A\xC9S]\x99\x07\xB3\xD7?\xE8j\x08\xEA#\x9E\x65{.}IJ\x0E\x99\xB5\xCCS=jk-2\xB2\x94q\xAE\x35\xC3\x61\x1E\xF1\xBDvs/\xC2\xC9\xD9\x96\xA0t\x19\xC1\xA7\x04\xA8\x7F\xC4\xEC-\x1B\xD2\xE3\xF6\x9D\x12\xD2\xC2"))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
end:
darray_free(a);
return testsPassed == 10;
}
typedef struct {
char *item;
size_t size;
} testLits_string;
static int testdarray_append_lit(void) {
darray_char a = darray_new();
darray(testLits_string) strings = darray_new();
testLits_string *i;
size_t testsPassed = 0;
size_t oldSize;
testLits_string append;
size_t offs = 0;
/* Test 0 */
append.size = sizeof("v\xF8\xFE\xC6\x9D^5\xF4=kK\xD1(Mz\x9D\xA3\r\x12\x7F(D\xFC?\x89\x7F\xD2\x97\x0E]\f\xB4\x9F\x45n\x99h\xDE\x36\xBF>\xA7\xEF\x94\\>wVa\xFF\xBD\x08\xF1;\xF3\nx\xBFV*\x9C\xFC@\x1D\x02:\xD7\x9Bxvr}\xD6\xAC\x86I\xACN\x14\x06|\x7FSP\x8C\xB3\xFB~\xC9\t\xB3\xA4\x1EMO\x1C\xA3n\xA0\xB3\xC2n\x8B\xC6\x9CHi\x7F\tX9\x01\xDC\xED\x11I\xC4\f\x16\x14\xBC\x12\\\xB2\xCE\xAB\xE4\x1E-kZ\t\x13\xEF\xA6\xA2\x1B\xCC\x19\x86\xD4\x80#\x95\xB6\xC6zssc\xB4(\xBE\x9D\x9C\x98:\xB2\xEA\x45\xA8\xBB\x08\xC0J\x17^H\xBFL\xF8\xE1\xF4P\x1Ay5\xF6S0i\x1Fn\xB7Y\xD8\x98\x85\x01\x90\x8E\x1A/&\xEF")-1;
oldSize = a.size;
darray_append_lit(a, "v\xF8\xFE\xC6\x9D^5\xF4=kK\xD1(Mz\x9D\xA3\r\x12\x7F(D\xFC?\x89\x7F\xD2\x97\x0E]\f\xB4\x9F\x45n\x99h\xDE\x36\xBF>\xA7\xEF\x94\\>wVa\xFF\xBD\x08\xF1;\xF3\nx\xBFV*\x9C\xFC@\x1D\x02:\xD7\x9Bxvr}\xD6\xAC\x86I\xACN\x14\x06|\x7FSP\x8C\xB3\xFB~\xC9\t\xB3\xA4\x1EMO\x1C\xA3n\xA0\xB3\xC2n\x8B\xC6\x9CHi\x7F\tX9\x01\xDC\xED\x11I\xC4\f\x16\x14\xBC\x12\\\xB2\xCE\xAB\xE4\x1E-kZ\t\x13\xEF\xA6\xA2\x1B\xCC\x19\x86\xD4\x80#\x95\xB6\xC6zssc\xB4(\xBE\x9D\x9C\x98:\xB2\xEA\x45\xA8\xBB\x08\xC0J\x17^H\xBFL\xF8\xE1\xF4P\x1Ay5\xF6S0i\x1Fn\xB7Y\xD8\x98\x85\x01\x90\x8E\x1A/&\xEF");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "v\xF8\xFE\xC6\x9D^5\xF4=kK\xD1(Mz\x9D\xA3\r\x12\x7F(D\xFC?\x89\x7F\xD2\x97\x0E]\f\xB4\x9F\x45n\x99h\xDE\x36\xBF>\xA7\xEF\x94\\>wVa\xFF\xBD\x08\xF1;\xF3\nx\xBFV*\x9C\xFC@\x1D\x02:\xD7\x9Bxvr}\xD6\xAC\x86I\xACN\x14\x06|\x7FSP\x8C\xB3\xFB~\xC9\t\xB3\xA4\x1EMO\x1C\xA3n\xA0\xB3\xC2n\x8B\xC6\x9CHi\x7F\tX9\x01\xDC\xED\x11I\xC4\f\x16\x14\xBC\x12\\\xB2\xCE\xAB\xE4\x1E-kZ\t\x13\xEF\xA6\xA2\x1B\xCC\x19\x86\xD4\x80#\x95\xB6\xC6zssc\xB4(\xBE\x9D\x9C\x98:\xB2\xEA\x45\xA8\xBB\x08\xC0J\x17^H\xBFL\xF8\xE1\xF4P\x1Ay5\xF6S0i\x1Fn\xB7Y\xD8\x98\x85\x01\x90\x8E\x1A/&\xEF", a.size-oldSize))
goto end;
append.item = strdup("v\xF8\xFE\xC6\x9D^5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end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\f\x8F[w\xD4\xAE\xBC\x1Dn\xF7\xE0jD\xA4p\x0E\n<\x9C\xF0Z\xC1I\x86~\xD1G\xB3\x01\xA6\x86)q1\x12\xD5\x08\x0E\x08\x7F+/pp\x14\xF0\xCF\x97%\xE0Q\x06\xCE)\xDF\x92\xBD\x06Z\xC2\x80\x94\xE3V%*\x18\xE1\xF4\xFA\xBD\x14MCjZ\xB2(\x91\x19\x8A\xB1\x34\xD3\x45\xC4\x1F\x39Q\xCB`\x0F\x9C\x81J\x0F\x86%\xA2\xEA>\x04\x7F\x94\x9F\xC7\xD2\xD9`\xEB\x30\xE7\xCDp\xBC\xD5\xD7\xDD!j|\xC1T\xE1 NB;A\xF7\xA2\x9C\xA6!\xDF\xB5\x9D\x64\x86\xD8\xFD\xD1\x99\xA3\xD0\\Q\xE1|\r\x18\xD9;\xE0\x95\xD8h\xF0\xC2V\xD7\\\x01\x91\xBEg\xC6\x44\x97U\xF8s/\xF7\x8C\xF4y\xDA\xC3\x38$\x8Fr\x86\x9D\xB4u\xAF\x0Et\xEC\xDD\xB0\"~x\x8F\x9B\x7F\xABl\x05\xAC\"\xA0\t\xCEL+\xDD\xB1V!\xAF\xFA\xD3\x03\xFB\xC2g\xEB\xA8\xDB\xF8\x16r\xB1\x41\xD9\x14\x06O\\O\xEB\x92\xF4\x39\xB1\x18s\x9B\x41#Q\xC3\x66\xCC\xA6\x33\xD4n\x12\v", a.size-oldSize))
goto end;
append.item = strdup("\f\x8F[w\xD4\xAE\xBC\x1Dn\xF7\xE0jD\xA4p\x0E\n<\x9C\xF0Z\xC1I\x86~\xD1G\xB3\x01\xA6\x86)q1\x12\xD5\x08\x0E\x08\x7F+/pp\x14\xF0\xCF\x97%\xE0Q\x06\xCE)\xDF\x92\xBD\x06Z\xC2\x80\x94\xE3V%*\x18\xE1\xF4\xFA\xBD\x14MCjZ\xB2(\x91\x19\x8A\xB1\x34\xD3\x45\xC4\x1F\x39Q\xCB`\x0F\x9C\x81J\x0F\x86%\xA2\xEA>\x04\x7F\x94\x9F\xC7\xD2\xD9`\xEB\x30\xE7\xCDp\xBC\xD5\xD7\xDD!j|\xC1T\xE1 NB;A\xF7\xA2\x9C\xA6!\xDF\xB5\x9D\x64\x86\xD8\xFD\xD1\x99\xA3\xD0\\Q\xE1|\r\x18\xD9;\xE0\x95\xD8h\xF0\xC2V\xD7\\\x01\x91\xBEg\xC6\x44\x97U\xF8s/\xF7\x8C\xF4y\xDA\xC3\x38$\x8Fr\x86\x9D\xB4u\xAF\x0Et\xEC\xDD\xB0\"~x\x8F\x9B\x7F\xABl\x05\xAC\"\xA0\t\xCEL+\xDD\xB1V!\xAF\xFA\xD3\x03\xFB\xC2g\xEB\xA8\xDB\xF8\x16r\xB1\x41\xD9\x14\x06O\\O\xEB\x92\xF4\x39\xB1\x18s\x9B\x41#Q\xC3\x66\xCC\xA6\x33\xD4n\x12\v");
darray_append(strings, append);
testsPassed++;
/* Test 2 */
append.size = sizeof("\xE1\xAF\x8F\xA8\xDBXq\xF3Mv\xEDK\xA6\xE3\xBCh\xFDq\xFC\xC5\xE0\x99\x41\xCD\xF8\fx\x98 +d}\x8B\xF8\xA0\xAA\x01\x86\xAD\xAB\f \x81\x63*\xF3)\xAE\x8Eu]\xC0j\"c\xA0W\xC0`\x1F\x44\xB7\x96R\x05+\xF9\x98\x87z\xFB/83\xC4P\xADnV?\xF2Y\x05\xC3\x42\xE3\xEA\x84\xEB\xF3).\xEE\xC7&>\x14&rr\xC8\x41\x04*\x95\x32\x63q\x13\xEC*\x9C\x1A\x15\xF4\xB2\xEA\xF5m\xA3wp\xD1NR\x8D\xF4z\x93\xC8\x38{\x93\x43\xE8\xA6( \xF8\xEA\x45\x18\xE2\xAF\xE7\x08\x66\xEE\x12.\xBD\xF3\xBEg\x9D\xDB\xFF`\xAF\x64\x0EQ\xAD~%8\xB2\xFDHd\xAD\x65\x9A\x10O\x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xDA\xB9\x33\xBB\xC7\x11\xEA\x31\xB9\xEEG\xBB\x81\x36\xB7L\xBB\xDC`\x04\x30x(\xB0\x7F!b4\xC6\xAE\xA8\xEE\xA1\xBB\x37:\xA8k<\xF7\xE9\xEB\xC7\xAF\x62\x31\xCDJ\xE6\xAB\xC3%2\xD9\x0F.\xB8\\\xE0\xB7\x91\x36\xBE\x95[\"\xA4\f\xAD\x96k\x14\xDD]\xE4\xD8\xC5\x87q\xF0\xE5\x02\xAA\xC1{6&\x1C\xB2\xD0]\x1F\xBA\xA1\xE4#N\t\x94\xAE\xBBZ\xF1\xD5\xE8\xCA\x43\xE6\x8A\xA7\xFEl\x81=v\xC5\x06\x8C");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\xE1\xAF\x8F\xA8\xDBXq\xF3Mv\xEDK\xA6\xE3\xBCh\xFDq\xFC\xC5\xE0\x99\x41\xCD\xF8\fx\x98 +d}\x8B\xF8\xA0\xAA\x01\x86\xAD\xAB\f \x81\x63*\xF3)\xAE\x8Eu]\xC0j\"c\xA0W\xC0`\x1F\x44\xB7\x96R\x05+\xF9\x98\x87z\xFB/83\xC4P\xADnV?\xF2Y\x05\xC3\x42\xE3\xEA\x84\xEB\xF3).\xEE\xC7&>\x14&rr\xC8\x41\x04*\x95\x32\x63q\x13\xEC*\x9C\x1A\x15\xF4\xB2\xEA\xF5m\xA3wp\xD1NR\x8D\xF4z\x93\xC8\x38{\x93\x43\xE8\xA6( \xF8\xEA\x45\x18\xE2\xAF\xE7\x08\x66\xEE\x12.\xBD\xF3\xBEg\x9D\xDB\xFF`\xAF\x64\x0EQ\xAD~%8\xB2\xFDHd\xAD\x65\x9A\x10O\xAA\xD8|\xA4\xD4\xFE\x81\xE7\xE3\xFA\x96u\x9B\x0F\xA8x\xC2\x10&\xCC\xB4\xB5\x1C|n\x06P\x03\x94i\xF6}\xCB\xA5\xE7\x95+\xD6\xB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\xE9\xEB\xC7\xAF\x62\x31\xCDJ\xE6\xAB\xC3%2\xD9\x0F.\xB8\\\xE0\xB7\x91\x36\xBE\x95[\"\xA4\f\xAD\x96k\x14\xDD]\xE4\xD8\xC5\x87q\xF0\xE5\x02\xAA\xC1{6&\x1C\xB2\xD0]\x1F\xBA\xA1\xE4#N\t\x94\xAE\xBBZ\xF1\xD5\xE8\xCA\x43\xE6\x8A\xA7\xFEl\x81=v\xC5\x06\x8C");
darray_append(strings, append);
testsPassed++;
/* Test 3 */
append.size = sizeof("y\xC8}P\x83\xD3\xD3>\xC4\xED\x84o\x92\xC0\x33\x34\x87_\x8Cm\x91(Z;+\xC9\xBF\xD4\xCF\x90L \xBB\xA6\xE0Y\xF7\\3%\xDC\x63\x1A\xF0/}\xE0\xDE\xCF\xD0\x31\xEA\xF1|F\xA8\x94\xCDp\xEF@\xAEi\x95\xCA\x45\xC4\x8F\xA4\x65\xE7\xFD*\x90\xEC\xA8\xA6\xFF\x96N\xDF\xEBG\xE8\n^\x9C\xFD\x37\x1F\x43T\x08\xBA\x37H\f\xDC\x99\xAAQ,\x96z\x97=3ib4*u\xFE\x98\xFB\f\xE7jqL\xE5\xAD\x30\x19\xB8*\x94\xC0\x03\x46\x01\x8C\xCD>\xFE\xBEL\xBB[>;\x15\xD4\xDC\xE2\xC0\x1E\xC7\xF2\x96IOPt.\xB1\x63\xC4\xDE\xC1\vL\xE0\x9A\xBA\x99\n\xF5i\xB6{L\xA6\t\xFF\x1B\x64N\xF4\xDD\xDD\xFDG]\x8Dk\xAF\x0E\xB5\x38\x39:\xA2l\xA6tHN\xC6\xC9\x01{r:h\xD0\xA3\x62\x05\xD0~o\xBB")-1;
oldSize = a.size;
darray_append_lit(a, "y\xC8}P\x83\xD3\xD3>\xC4\xED\x84o\x92\xC0\x33\x34\x87_\x8Cm\x91(Z;+\xC9\xBF\xD4\xCF\x90L \xBB\xA6\xE0Y\xF7\\3%\xDC\x63\x1A\xF0/}\xE0\xDE\xCF\xD0\x31\xEA\xF1|F\xA8\x94\xCDp\xEF@\xAEi\x95\xCA\x45\xC4\x8F\xA4\x65\xE7\xFD*\x90\xEC\xA8\xA6\xFF\x96N\xDF\xEBG\xE8\n^\x9C\xFD\x37\x1F\x43T\x08\xBA\x37H\f\xDC\x99\xAAQ,\x96z\x97=3ib4*u\xFE\x98\xFB\f\xE7jqL\xE5\xAD\x30\x19\xB8*\x94\xC0\x03\x46\x01\x8C\xCD>\xFE\xBEL\xBB[>;\x15\xD4\xDC\xE2\xC0\x1E\xC7\xF2\x96IOPt.\xB1\x63\xC4\xDE\xC1\vL\xE0\x9A\xBA\x99\n\xF5i\xB6{L\xA6\t\xFF\x1B\x64N\xF4\xDD\xDD\xFDG]\x8Dk\xAF\x0E\xB5\x38\x39:\xA2l\xA6tHN\xC6\xC9\x01{r:h\xD0\xA3\x62\x05\xD0~o\xBB");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "y\xC8}P\x83\xD3\xD3>\xC4\xED\x84o\x92\xC0\x33\x34\x87_\x8Cm\x91(Z;+\xC9\xBF\xD4\xCF\x90L \xBB\xA6\xE0Y\xF7\\3%\xDC\x63\x1A\xF0/}\xE0\xDE\xCF\xD0\x31\xEA\xF1|F\xA8\x94\xCDp\xEF@\xAEi\x95\xCA\x45\xC4\x8F\xA4\x65\xE7\xFD*\x90\xEC\xA8\xA6\xFF\x96N\xDF\xEBG\xE8\n^\x9C\xFD\x37\x1F\x43T\x08\xBA\x37H\f\xDC\x99\xAAQ,\x96z\x97=3ib4*u\xFE\x98\xFB\f\xE7jqL\xE5\xAD\x30\x19\xB8*\x94\xC0\x03\x46\x01\x8C\xCD>\xFE\xBEL\xBB[>;\x15\xD4\xDC\xE2\xC0\x1E\xC7\xF2\x96IOPt.\xB1\x63\xC4\xDE\xC1\vL\xE0\x9A\xBA\x99\n\xF5i\xB6{L\xA6\t\xFF\x1B\x64N\xF4\xDD\xDD\xFDG]\x8Dk\xAF\x0E\xB5\x38\x39:\xA2l\xA6tHN\xC6\xC9\x01{r:h\xD0\xA3\x62\x05\xD0~o\xBB", a.size-oldSize))
goto end;
append.item = strdup("y\xC8}P\x83\xD3\xD3>\xC4\xED\x84o\x92\xC0\x33\x34\x87_\x8Cm\x91(Z;+\xC9\xBF\xD4\xCF\x90L \xBB\xA6\xE0Y\xF7\\3%\xDC\x63\x1A\xF0/}\xE0\xDE\xCF\xD0\x31\xEA\xF1|F\xA8\x94\xCDp\xEF@\xAEi\x95\xCA\x45\xC4\x8F\xA4\x65\xE7\xFD*\x90\xEC\xA8\xA6\xFF\x96N\xDF\xEBG\xE8\n^\x9C\xFD\x37\x1F\x43T\x08\xBA\x37H\f\xDC\x99\xAAQ,\x96z\x97=3ib4*u\xFE\x98\xFB\f\xE7jqL\xE5\xAD\x30\x19\xB8*\x94\xC0\x03\x46\x01\x8C\xCD>\xFE\xBEL\xBB[>;\x15\xD4\xDC\xE2\xC0\x1E\xC7\xF2\x96IOPt.\xB1\x63\xC4\xDE\xC1\vL\xE0\x9A\xBA\x99\n\xF5i\xB6{L\xA6\t\xFF\x1B\x64N\xF4\xDD\xDD\xFDG]\x8Dk\xAF\x0E\xB5\x38\x39:\xA2l\xA6tHN\xC6\xC9\x01{r:h\xD0\xA3\x62\x05\xD0~o\xBB");
darray_append(strings, append);
testsPassed++;
/* Test 4 */
append.size = sizeof("\x93\x8A\x19^\x10\\\xD9\x8D\x9D\x7F\xCA\x8F\x1B\x85\x42\x1F\xCFG\xBD\x63M\x81\x44\xA3\xA9\x8F\xCA_\x80)\xBBqjo\xCD\x01\x8A\x17\xA4\x07:[\xFF+X\xEB\x19\xAC\xA2\xAB\xC7\xC8\x65H?\xE7\xE2H\xF0$\x01\x08\vrR\x1AI\xE0&\xBF~\xD1\x9AUDZX8<\x92\x64\x9CP\v\xBE(\xD7\n\v\x99\xEC\x18\x93\x36V\x01\f\xA7M\xA3 \xD8\x98%\"\xCA\xBD\x63\xA8\x8Bg\x13\x8A>f'\"w\xD4\xF6U\xA8Jy\x07\x85v5\xA2\t\x94\x17W\x96\xE2<RSl-\xB1\x87L\xBC\xFD\xC5i`s\x81\x06\xB9\n\xE8\xD6\x64\xEE\xFA\xC2\x8A\x32n\x9B\x90.\xC9G\xAEW\xEAv.\"\x9D&\x91 \xDF\xC4y\xC3\x42\x97\xB8\xAAV\xAC+\x8A\xF9{\x82\xD5\xD7\xDC q\x80\xB0\xB1na\x85\x42\xF2\x32\xAD\x32\x41\x90V\xFF\xA5\x10\x66\x0E,C\x87\xD4\x8C\x84\xF0uD[\x03\x13\xB2\xE5J\xB6\x8B\x99\xB9\xF4\x8A\x1B\xF7\x85")-1;
oldSize = a.size;
darray_append_lit(a, "\x93\x8A\x19^\x10\\\xD9\x8D\x9D\x7F\xCA\x8F\x1B\x85\x42\x1F\xCFG\xBD\x63M\x81\x44\xA3\xA9\x8F\xCA_\x80)\xBBqjo\xCD\x01\x8A\x17\xA4\x07:[\xFF+X\xEB\x19\xAC\xA2\xAB\xC7\xC8\x65H?\xE7\xE2H\xF0$\x01\x08\vrR\x1AI\xE0&\xBF~\xD1\x9AUDZX8<\x92\x64\x9CP\v\xBE(\xD7\n\v\x99\xEC\x18\x93\x36V\x01\f\xA7M\xA3 \xD8\x98%\"\xCA\xBD\x63\xA8\x8Bg\x13\x8A>f'\"w\xD4\xF6U\xA8Jy\x07\x85v5\xA2\t\x94\x17W\x96\xE2<RSl-\xB1\x87L\xBC\xFD\xC5i`s\x81\x06\xB9\n\xE8\xD6\x64\xEE\xFA\xC2\x8A\x32n\x9B\x90.\xC9G\xAEW\xEAv.\"\x9D&\x91 \xDF\xC4y\xC3\x42\x97\xB8\xAAV\xAC+\x8A\xF9{\x82\xD5\xD7\xDC q\x80\xB0\xB1na\x85\x42\xF2\x32\xAD\x32\x41\x90V\xFF\xA5\x10\x66\x0E,C\x87\xD4\x8C\x84\xF0uD[\x03\x13\xB2\xE5J\xB6\x8B\x99\xB9\xF4\x8A\x1B\xF7\x85");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\x93\x8A\x19^\x10\\\xD9\x8D\x9D\x7F\xCA\x8F\x1B\x85\x42\x1F\xCFG\xBD\x63M\x81\x44\xA3\xA9\x8F\xCA_\x80)\xBBqjo\xCD\x01\x8A\x17\xA4\x07:[\xFF+X\xEB\x19\xAC\xA2\xAB\xC7\xC8\x65H?\xE7\xE2H\xF0$\x01\x08\vrR\x1AI\xE0&\xBF~\xD1\x9AUDZX8<\x92\x64\x9CP\v\xBE(\xD7\n\v\x99\xEC\x18\x93\x36V\x01\f\xA7M\xA3 \xD8\x98%\"\xCA\xBD\x63\xA8\x8Bg\x13\x8A>f'\"w\xD4\xF6U\xA8Jy\x07\x85v5\xA2\t\x94\x17W\x96\xE2<RSl-\xB1\x87L\xBC\xFD\xC5i`s\x81\x06\xB9\n\xE8\xD6\x64\xEE\xFA\xC2\x8A\x32n\x9B\x90.\xC9G\xAEW\xEAv.\"\x9D&\x91 \xDF\xC4y\xC3\x42\x97\xB8\xAAV\xAC+\x8A\xF9{\x82\xD5\xD7\xDC q\x80\xB0\xB1na\x85\x42\xF2\x32\xAD\x32\x41\x90V\xFF\xA5\x10\x66\x0E,C\x87\xD4\x8C\x84\xF0uD[\x03\x13\xB2\xE5J\xB6\x8B\x99\xB9\xF4\x8A\x1B\xF7\x85", a.size-oldSize))
goto end;
append.item = strdup("\x93\x8A\x19^\x10\\\xD9\x8D\x9D\x7F\xCA\x8F\x1B\x85\x42\x1F\xCFG\xBD\x63M\x81\x44\xA3\xA9\x8F\xCA_\x80)\xBBqjo\xCD\x01\x8A\x17\xA4\x07:[\xFF+X\xEB\x19\xAC\xA2\xAB\xC7\xC8\x65H?\xE7\xE2H\xF0$\x01\x08\vrR\x1AI\xE0&\xBF~\xD1\x9AUDZX8<\x92\x64\x9CP\v\xBE(\xD7\n\v\x99\xEC\x18\x93\x36V\x01\f\xA7M\xA3 \xD8\x98%\"\xCA\xBD\x63\xA8\x8Bg\x13\x8A>f'\"w\xD4\xF6U\xA8Jy\x07\x85v5\xA2\t\x94\x17W\x96\xE2<RSl-\xB1\x87L\xBC\xFD\xC5i`s\x81\x06\xB9\n\xE8\xD6\x64\xEE\xFA\xC2\x8A\x32n\x9B\x90.\xC9G\xAEW\xEAv.\"\x9D&\x91 \xDF\xC4y\xC3\x42\x97\xB8\xAAV\xAC+\x8A\xF9{\x82\xD5\xD7\xDC q\x80\xB0\xB1na\x85\x42\xF2\x32\xAD\x32\x41\x90V\xFF\xA5\x10\x66\x0E,C\x87\xD4\x8C\x84\xF0uD[\x03\x13\xB2\xE5J\xB6\x8B\x99\xB9\xF4\x8A\x1B\xF7\x85");
darray_append(strings, append);
testsPassed++;
/* Test 5 */
append.size = sizeof("\xF5\x08$:\xCC\xD7\x8A\xB8%\xF4P6\x18")-1;
oldSize = a.size;
darray_append_lit(a, "\xF5\x08$:\xCC\xD7\x8A\xB8%\xF4P6\x18");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\xF5\x08$:\xCC\xD7\x8A\xB8%\xF4P6\x18", a.size-oldSize))
goto end;
append.item = strdup("\xF5\x08$:\xCC\xD7\x8A\xB8%\xF4P6\x18");
darray_append(strings, append);
testsPassed++;
/* Test 6 */
append.size = sizeof("2\x9A\x86\x94H\xA8\xD4\x8F\xE4\xD5\x10\xB3\xC3~\xF7\xB5g:n(\xA7x\xFD\xB7\xD5{\xED\xD7\xDDZ\xA2\x81\xD7\xD1m\x8E\xD3\x07\xA5\x9C\xFCl$4\xC1k\xE2X\xCF\x84\xB2\xEB];p\x9A)\x02q\xC1\x1E\xB6\vKud\xE7ttR\xB8@\x1C\xF9\xB6\xCE>s\xF9\x9F\x07\x99O\xAD\xB1\x7F\xC2I7\xA3O\x9D^-\xD9\xDE\xE0\x9CqY\\:0[\xD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95\x82.\xCE\xD1>\x06KQ\r_\xCEmy\xA9\xACv\xE8\x35\x8BWy\xBD_\x16\x33\\\xC8\xE1p\xFBIm\xCBvP\x11U\x94\x88(\xC1\xAD\xCC\x90\x03\xB2\xCEU\xDC\t]\xF7\x89\x90z\xE2\xB8\x17\xE7\xB4\xCD\xC4\x65\xC2\xCC\x36[Y\x95\xA1\x82\xB6\x07_o\xD7\x31\xE0\xC8p\x92\xFA\x31\xCD\xD5\xC6\xA9\xEA\xCF\x85\x96)\xF6\x15N\xB0xh\xA1_\xFC\xEB\t\x86Zc\xFA\xCD\xB9\xB7\t\xE8\x42P\x10<Y\xD5\x30\xE7\n\xE0i\x0F\x9Ew\xF2@\xF5\x17\xC1mp\x9E\xA6\xE6+\x14\x98\x8C\x1E\xBCL\xFC\x17\x89nW\xE8\x9E\xBE\x9El\xEB\x88\xD0\xD1\xD4\x94Gt\v\r\x0F\xDC\xBAZ J8\xC7\xF4\x9A\x81\xC3=\xC8\x8C\x18\xC5\xE8{Y\xBA\xCB>\xD9\x35\x90\xEF\xB2\x99\xC0\x0F\xBE\xCF\xB0\x65\xC4\x99L)e\x99\x86-\xDBVJ\xA6\xCA\t\xA2m\xF9\xD9H\xF7\x04\x1C \x9C\xD2\x05 K\x1C\xA3,\x96\x61jH\xC0\xC3\xEC\xB3\n*\xDA\xFD\xDF\n\x9B\xB6\xF4yDzs");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "2\x9A\x86\x94H\xA8\xD4\x8F\xE4\xD5\x10\xB3\xC3~\xF7\xB5g:n(\xA7x\xFD\xB7\xD5{\xED\xD7\xDDZ\xA2\x81\xD7\xD1m\x8E\xD3\x07\xA5\x9C\xFCl$4\xC1k\xE2X\xCF\x84\xB2\xEB];p\x9A)\x02q\xC1\x1E\xB6\vKud\xE7ttR\xB8@\x1C\xF9\xB6\xCE>s\xF9\x9F\x07\x99O\xAD\xB1\x7F\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xD7,5Q\xAF\xEA\x8DU\f\xEB\x8A\xF8\x41\xD4L\xF9Q@\x1A\xD6\x63w7\x8B\x9F\xF5\x18\x9AU\"\x13\xC9\xFD\xD1\x43\xF7\xD9~M>\x8B@\xC0\xEE\xB6H\x8D\x89\x8C\x04@\x83\xBC\x35\x16\xC7\xB8\x44\xC0;\xA7\x31\xDE\xC2\x11{\xF3\xC1\xAF\xC4HP\xA3\xAA\xA7Wl\xA5\xC3\x44\x92\xB6\x65\xE4\x1A\xDE\xFC\x02\xA6[Z\xC8\xE8\x8A\xE8\xD8kE\xB5\xCE\x31=\x9C\f\x8F\xD0\xB7\xFB\xD6G\xF8\x9C\xD7\xC4\x33O:\x9F\x06\x9Dz\xCF\xA7\xDD-\x05L:\x1B\xEA\xD1\x35\x61\xFC\x99\x44\xF3\xE1\x65O\xBD\xA5x\x99\xF8\x10\x91\xDE\xA2\x0E\xE8j\xCE\x1E/G)\x9F\x32\xE9\x90\xED\x95\x1B\xA3Y4\xE1\x46!\xC4\x82\x99,0\xF8\xBD\x9B\xED\x8Fxh\xF4\xA9MNS,\xECj\x10>\x98\xE9]\xEE\xB4\xD5%]\x1E\xB4\xB3\xD6\x44\x66\x64$\xB2\xAC\xA0\xB3@P\xF7\fu\"(\xA9\x1E#l_.\x9D\xF6\x34\xCF\xD1:T\x06V\xF2\xA7g\x1A'f\xD2\xD6\xF5\x39\x02\x8F\x93\v\x11Tyf:\xDD\xB0Z\xA5\"\xE8ns{P\xCD\x38\x45\xC6\xA8+\xB3)\xF0\xCD\x83IUTQ~8\xDFj\xA1\xA2]d\x8D\x34\xA6\xD6\n\x9EP}y\xAC\xD5\x14\x92\xE6\xBA\x9FJ%][\xC4\xFB\xCBi2\xE6\xF7\x98\x87@\x11\xA0");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\xBD\x8EJ\xA8\x91\xFC;\x11_\x0F\xB8=\xDC\x8AjL0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\xAC\xD5\x14\x92\xE6\xBA\x9FJ%][\xC4\xFB\xCBi2\xE6\xF7\x98\x87@\x11\xA0");
darray_append(strings, append);
testsPassed++;
/* Test 8 */
append.size = sizeof("\x8E}z\x05\xDF\xD6\xF1\xD2\xBC\x15\xC1\xED\xF7\xF6\xFC\x83\xA8\x32\x33=\xB8K\x14\x86\xCCX1nD\x99\xBD\x44IB\xF6+\x97\xF2\x15\x86\xFA\xD9\xA5\xB8\xE9\x01;\x92\xC3\xF0\xD8\xA8]\xBF\xB7\xB8\x03\x38.\xF0KMW\xF1\xBAU]1\xC5\x61\x38zvR\xAD\xB0\x66\x03\x08\xFB\x86\xCFY\xB0\v\xBE+d\xF2\x84\x41\xC5\x84pUy\xE8\xAF\x94=\xE3\x33v+e\xFCi\xFB\x97\xB8\x32\xD4:9:\xE8\x15\x84\xF9\xE0\xAA\x11\xFF\xB9\x94\x13\xE4\xD3J\x88\x37\xD6\xE7\xF2\xAB\x36\xDC\xA5l38F\xDB\xD8\x95\x14\x1C\x1B\x36\xE0-\x93\x1E\x07\x94l\x03x\x16\x11\x94\xCD\"8\xD8\xED+\x10\xB5\xDCznl\xCD\x99SA\x12Y0\xAB\x81\f\xAC\xCB\xFE\x8A\x46\x8E\x7F\x8F\x97\x14\xF5\x38v~#\xB4")-1;
oldSize = a.size;
darray_append_lit(a, "\x8E}z\x05\xDF\xD6\xF1\xD2\xBC\x15\xC1\xED\xF7\xF6\xFC\x83\xA8\x32\x33=\xB8K\x14\x86\xCCX1nD\x99\xBD\x44IB\xF6+\x97\xF2\x15\x86\xFA\xD9\xA5\xB8\xE9\x01;\x92\xC3\xF0\xD8\xA8]\xBF\xB7\xB8\x03\x38.\xF0KMW\xF1\xBAU]1\xC5\x61\x38zvR\xAD\xB0\x66\x03\x08\xFB\x86\xCFY\xB0\v\xBE+d\xF2\x84\x41\xC5\x84pUy\xE8\xAF\x94=\xE3\x33v+e\xFCi\xFB\x97\xB8\x32\xD4:9:\xE8\x15\x84\xF9\xE0\xAA\x11\xFF\xB9\x94\x13\xE4\xD3J\x88\x37\xD6\xE7\xF2\xAB\x36\xDC\xA5l38F\xDB\xD8\x95\x14\x1C\x1B\x36\xE0-\x93\x1E\x07\x94l\x03x\x16\x11\x94\xCD\"8\xD8\xED+\x10\xB5\xDCznl\xCD\x99SA\x12Y0\xAB\x81\f\xAC\xCB\xFE\x8A\x46\x8E\x7F\x8F\x97\x14\xF5\x38v~#\xB4");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\x8E}z\x05\xDF\xD6\xF1\xD2\xBC\x15\xC1\xED\xF7\xF6\xFC\x83\xA8\x32\x33=\xB8K\x14\x86\xCCX1nD\x99\xBD\x44IB\xF6+\x97\xF2\x15\x86\xFA\xD9\xA5\xB8\xE9\x01;\x92\xC3\xF0\xD8\xA8]\xBF\xB7\xB8\x03\x38.\xF0KMW\xF1\xBAU]1\xC5\x61\x38zvR\xAD\xB0\x66\x03\x08\xFB\x86\xCFY\xB0\v\xBE+d\xF2\x84\x41\xC5\x84pUy\xE8\xAF\x94=\xE3\x33v+e\xFCi\xFB\x97\xB8\x32\xD4:9:\xE8\x15\x84\xF9\xE0\xAA\x11\xFF\xB9\x94\x13\xE4\xD3J\x88\x37\xD6\xE7\xF2\xAB\x36\xDC\xA5l38F\xDB\xD8\x95\x14\x1C\x1B\x36\xE0-\x93\x1E\x07\x94l\x03x\x16\x11\x94\xCD\"8\xD8\xED+\x10\xB5\xDCznl\xCD\x99SA\x12Y0\xAB\x81\f\xAC\xCB\xFE\x8A\x46\x8E\x7F\x8F\x97\x14\xF5\x38v~#\xB4", a.size-oldSize))
goto end;
append.item = strdup("\x8E}z\x05\xDF\xD6\xF1\xD2\xBC\x15\xC1\xED\xF7\xF6\xFC\x83\xA8\x32\x33=\xB8K\x14\x86\xCCX1nD\x99\xBD\x44IB\xF6+\x97\xF2\x15\x86\xFA\xD9\xA5\xB8\xE9\x01;\x92\xC3\xF0\xD8\xA8]\xBF\xB7\xB8\x03\x38.\xF0KMW\xF1\xBAU]1\xC5\x61\x38zvR\xAD\xB0\x66\x03\x08\xFB\x86\xCFY\xB0\v\xBE+d\xF2\x84\x41\xC5\x84pUy\xE8\xAF\x94=\xE3\x33v+e\xFCi\xFB\x97\xB8\x32\xD4:9:\xE8\x15\x84\xF9\xE0\xAA\x11\xFF\xB9\x94\x13\xE4\xD3J\x88\x37\xD6\xE7\xF2\xAB\x36\xDC\xA5l38F\xDB\xD8\x95\x14\x1C\x1B\x36\xE0-\x93\x1E\x07\x94l\x03x\x16\x11\x94\xCD\"8\xD8\xED+\x10\xB5\xDCznl\xCD\x99SA\x12Y0\xAB\x81\f\xAC\xCB\xFE\x8A\x46\x8E\x7F\x8F\x97\x14\xF5\x38v~#\xB4");
darray_append(strings, append);
testsPassed++;
/* Test 9 */
append.size = sizeof("\x18`\v\xC8\xC5N\xEEM!\x9D\x06@\x98#l\xCEOW(*\f\x92\xF2\xEA\x08\xA6\xCF\x06\xA9Z0\xA3.\xF6\x99\xE0\f@\xA8\x8E\xE7\xD8\xF1.R)\xF4%Y;\xD5h1\x9BW\x81\x8B\xA7Y$\x9A\xD8\xA6L\x85\x43J\xD9\x33\x81\x9A\xEBt/\x0Fs\xFE\x19\xEBg\x93\xDD\x1Dn\xDEzd&\x85\xB8\xAE\x92\xF4\x42\xFA\x45\x94\x0F[Z\x17\xFA\x41Zq\xFF\xD1z\x05}\xFFK\xE9r\xAF\xAB\x61\x86\x98j$\xB0\x9C:\xD8\x1D\xE8\xFD\xE9\x84\xEA\xFE\x63\x99\xC0Y\xCC\xDE\xF7\x1E\xE5\xA7\x96\xE0\xC2M\fA-\x90#\x9F[x\x13#\x8Ev\xBF\xAF\x87\xE1\x8E\xD8>\xF8\xC4'g\xE3L\xC0\xE0\xDC\x15Z\x98\xC4%\xE1\x91\xE9\xEA\xE3\xF6V\x90NK5_K\xE0\x1E\x35")-1;
oldSize = a.size;
darray_append_lit(a, "\x18`\v\xC8\xC5N\xEEM!\x9D\x06@\x98#l\xCEOW(*\f\x92\xF2\xEA\x08\xA6\xCF\x06\xA9Z0\xA3.\xF6\x99\xE0\f@\xA8\x8E\xE7\xD8\xF1.R)\xF4%Y;\xD5h1\x9BW\x81\x8B\xA7Y$\x9A\xD8\xA6L\x85\x43J\xD9\x33\x81\x9A\xEBt/\x0Fs\xFE\x19\xEBg\x93\xDD\x1Dn\xDEzd&\x85\xB8\xAE\x92\xF4\x42\xFA\x45\x94\x0F[Z\x17\xFA\x41Zq\xFF\xD1z\x05}\xFFK\xE9r\xAF\xAB\x61\x86\x98j$\xB0\x9C:\xD8\x1D\xE8\xFD\xE9\x84\xEA\xFE\x63\x99\xC0Y\xCC\xDE\xF7\x1E\xE5\xA7\x96\xE0\xC2M\fA-\x90#\x9F[x\x13#\x8Ev\xBF\xAF\x87\xE1\x8E\xD8>\xF8\xC4'g\xE3L\xC0\xE0\xDC\x15Z\x98\xC4%\xE1\x91\xE9\xEA\xE3\xF6V\x90NK5_K\xE0\x1E\x35");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, "\x18`\v\xC8\xC5N\xEEM!\x9D\x06@\x98#l\xCEOW(*\f\x92\xF2\xEA\x08\xA6\xCF\x06\xA9Z0\xA3.\xF6\x99\xE0\f@\xA8\x8E\xE7\xD8\xF1.R)\xF4%Y;\xD5h1\x9BW\x81\x8B\xA7Y$\x9A\xD8\xA6L\x85\x43J\xD9\x33\x81\x9A\xEBt/\x0Fs\xFE\x19\xEBg\x93\xDD\x1Dn\xDEzd&\x85\xB8\xAE\x92\xF4\x42\xFA\x45\x94\x0F[Z\x17\xFA\x41Zq\xFF\xD1z\x05}\xFFK\xE9r\xAF\xAB\x61\x86\x98j$\xB0\x9C:\xD8\x1D\xE8\xFD\xE9\x84\xEA\xFE\x63\x99\xC0Y\xCC\xDE\xF7\x1E\xE5\xA7\x96\xE0\xC2M\fA-\x90#\x9F[x\x13#\x8Ev\xBF\xAF\x87\xE1\x8E\xD8>\xF8\xC4'g\xE3L\xC0\xE0\xDC\x15Z\x98\xC4%\xE1\x91\xE9\xEA\xE3\xF6V\x90NK5_K\xE0\x1E\x35", a.size-oldSize))
goto end;
append.item = strdup("\x18`\v\xC8\xC5N\xEEM!\x9D\x06@\x98#l\xCEOW(*\f\x92\xF2\xEA\x08\xA6\xCF\x06\xA9Z0\xA3.\xF6\x99\xE0\f@\xA8\x8E\xE7\xD8\xF1.R)\xF4%Y;\xD5h1\x9BW\x81\x8B\xA7Y$\x9A\xD8\xA6L\x85\x43J\xD9\x33\x81\x9A\xEBt/\x0Fs\xFE\x19\xEBg\x93\xDD\x1Dn\xDEzd&\x85\xB8\xAE\x92\xF4\x42\xFA\x45\x94\x0F[Z\x17\xFA\x41Zq\xFF\xD1z\x05}\xFFK\xE9r\xAF\xAB\x61\x86\x98j$\xB0\x9C:\xD8\x1D\xE8\xFD\xE9\x84\xEA\xFE\x63\x99\xC0Y\xCC\xDE\xF7\x1E\xE5\xA7\x96\xE0\xC2M\fA-\x90#\x9F[x\x13#\x8Ev\xBF\xAF\x87\xE1\x8E\xD8>\xF8\xC4'g\xE3L\xC0\xE0\xDC\x15Z\x98\xC4%\xE1\x91\xE9\xEA\xE3\xF6V\x90NK5_K\xE0\x1E\x35");
darray_append(strings, append);
testsPassed++;
if (strings.size != 10)
goto end;
darray_foreach(i, strings) {
if (a.size-offs < i->size)
goto end;
if (memcmp(a.item+offs, i->item, i->size))
goto end;
offs += i->size;
};
if (offs != a.size)
goto end;
if (a.item[offs])
goto end;
testsPassed++;
end:
darray_free(a);
darray_foreach(i, strings)
free(i->item);
darray_free(strings);
return testsPassed == 10+1;
}
static int testdarray_prepend_lit(void) {
darray_char a = darray_new();
darray(testLits_string) strings = darray_new();
testLits_string *i;
size_t testsPassed = 0;
size_t oldSize;
testLits_string append;
size_t offs;
/* Test 0 */
append.size = sizeof("*g\xC2;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F9\\\x16M\xEC\xAB\xC1\x34\x80~\xCE\r:K\xB4\x19\x99\xE1\x82/\x96\x87\xCD\xDD");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "*g\xC2;\x98\x92\xD3\x84\xF4\x64\xB4\xC8\x83@\xA6s\xE5\xEF,\xB4\xAB\x12\x36\xE9\x8F\x88\xF8\x9C\v\x08\xE6M\x98\xA0\x1D\x9B\xF5\xD9\xEC \xC2\xFFK;'\xFE?\xF0\xAB\xA3>\x97\xB4n\x11\x65\xA1\xFC\r\x13\x8BU\xC4;\xC3\xD2\xA8l\xE6\xA7\xE0\xCA\xB7@\xA2\xD2\x89\x14\x8A\x05\x33\xB9\xF7\x45yp\x17\xDC\x9C\xBF,\xB6Z(\xE9\xD9\x34g\x0E`\x80\x8Ag\xD0%I\xC1?Y\x16\xFA\xE2.\xB9\x36\xEA\xC1\x06Kj\x9Bx\xF9\xD0\x84\x89\x91\xF4\x87\x14\x93h(\xF1\x98\x38\x9Cq\xC6,\x13\x04\x61\xDA\xC2\xA1\xFE\xF3\xEAz\x9F\xCAyS\xEF\xBB\xF9\\\x16M\xEC\xAB\xC1\x34\x80~\xCE\r:K\xB4\x19\x99\xE1\x82/\x96\x87\xCD\xDD", a.size-oldSize))
goto end;
append.item = strdup("*g\xC2;\x98\x92\xD3\x84\xF4\x64\xB4\xC8\x83@\xA6s\xE5\xEF,\xB4\xAB\x12\x36\xE9\x8F\x88\xF8\x9C\v\x08\xE6M\x98\xA0\x1D\x9B\xF5\xD9\xEC \xC2\xFFK;'\xFE?\xF0\xAB\xA3>\x97\xB4n\x11\x65\xA1\xFC\r\x13\x8BU\xC4;\xC3\xD2\xA8l\xE6\xA7\xE0\xCA\xB7@\xA2\xD2\x89\x14\x8A\x05\x33\xB9\xF7\x45yp\x17\xDC\x9C\xBF,\xB6Z(\xE9\xD9\x34g\x0E`\x80\x8Ag\xD0%I\xC1?Y\x16\xFA\xE2.\xB9\x36\xEA\xC1\x06Kj\x9Bx\xF9\xD0\x84\x89\x91\xF4\x87\x14\x93h(\xF1\x98\x38\x9Cq\xC6,\x13\x04\x61\xDA\xC2\xA1\xFE\xF3\xEAz\x9F\xCAyS\xEF\xBB\xF9\\\x16M\xEC\xAB\xC1\x34\x80~\xCE\r:K\xB4\x19\x99\xE1\x82/\x96\x87\xCD\xDD");
darray_append(strings, append);
testsPassed++;
/* Test 1 */
append.size = sizeof("B\xFD\xE5\xB0\xAC]`\n><\xFF\xDC\x38k\x03!\xE5\xFF\xC1\x31\x94\xC8\x1C\xAE\x83\x39\xA2K\xC5u\xA4\xD3\x9C\x07\xB0\xCE\xDF\x33\xE6\x02\xE3P\xE0\x83\xD8\x97<\x95\xF1\xFF\x34I\x89\xD2\x17\xD9\x17\xACH\x01-1-\xBB\x86\xFE\xED\x01\xBA\x01\tvf\x95Wm\xE0\xCBX%\x0E<\xC9\x9D\x19\x06\xD6\x36\xD9\x1C\tI\xB5IE\x80\x87oM;\x1D\xC3\x9D\xB6\t\x89\x37\xE9\xC2\x34\x94\xE3\xEC].I\x86\xD5\x9C\xAE\x87\xB0m\x11=\xDF\xB1\xFE\xD2\xF6`z3\xE7\xC6\xE8\xEEl\x15\x9D>3\xF8\x8D\xC2\x65(`\xE6I\x9B\x15\xFD\xED \f\xC3_\xC5\xBA\x38\xCB\xF7\x9B\xD9\x14VQM\xAD\x98\xDEJ\xCC#\xA8\x92\xB7\x14\xC1\nX\xD9\xB4\x96$\xB1\x12\xAF\x06\x07TmmTM\xAC\x33\xD4:\x8A\x94M:Srcr\x17\x95pKE\xC1\t\xC0\xB1\x84\x11\xF5\x97\x15\x62\x11\x33\x05\xB5\x9A.@\xBF\x13\xD7\xCAn\xBE\x34\xB5\xA6\x15\xB6\x88\x13\xDE\xA3\xE9\xC3/\xF9\x36L\\\x0E\x1Fg\xDD\xC0\x01\xD0\x90\x9ENq*\xBD\x31/ttV\xAC\xA4\x12?s\xC1\xFF\x35\xBB~\xDC\x05\x06\xFF\xF8\xFA\x1B\x65\x11T\x8Fz\xF3W0\x98\x1D\x7F\x03\x9AQ3\te\xAB]\x93\xD6xfS\xE5\xB2$(\xFA\xE4\xD1\xCC\xA9\x80\xF0\xC3\x36uK\xF0\xD2(B`\x11\x04\x9Bx")-1;
oldSize = a.size;
darray_prepend_lit(a, "B\xFD\xE5\xB0\xAC]`\n><\xFF\xDC\x38k\x03!\xE5\xFF\xC1\x31\x94\xC8\x1C\xAE\x83\x39\xA2K\xC5u\xA4\xD3\x9C\x07\xB0\xCE\xDF\x33\xE6\x02\xE3P\xE0\x83\xD8\x97<\x95\xF1\xFF\x34I\x89\xD2\x17\xD9\x17\xACH\x01-1-\xBB\x86\xFE\xED\x01\xBA\x01\tvf\x95Wm\xE0\xCBX%\x0E<\xC9\x9D\x19\x06\xD6\x36\xD9\x1C\tI\xB5IE\x80\x87oM;\x1D\xC3\x9D\xB6\t\x89\x37\xE9\xC2\x34\x94\xE3\xEC].I\x86\xD5\x9C\xAE\x87\xB0m\x11=\xDF\xB1\xFE\xD2\xF6`z3\xE7\xC6\xE8\xEEl\x15\x9D>3\xF8\x8D\xC2\x65(`\xE6I\x9B\x15\xFD\xED \f\xC3_\xC5\xBA\x38\xCB\xF7\x9B\xD9\x14VQM\xAD\x98\xDEJ\xCC#\xA8\x92\xB7\x14\xC1\nX\xD9\xB4\x96$\xB1\x12\xAF\x06\x07TmmTM\xAC\x33\xD4:\x8A\x94M:Srcr\x17\x95pKE\xC1\t\xC0\xB1\x84\x11\xF5\x97\x15\x62\x11\x33\x05\xB5\x9A.@\xBF\x13\xD7\xCAn\xBE\x34\xB5\xA6\x15\xB6\x88\x13\xDE\xA3\xE9\xC3/\xF9\x36L\\\x0E\x1Fg\xDD\xC0\x01\xD0\x90\x9ENq*\xBD\x31/ttV\xAC\xA4\x12?s\xC1\xFF\x35\xBB~\xDC\x05\x06\xFF\xF8\xFA\x1B\x65\x11T\x8Fz\xF3W0\x98\x1D\x7F\x03\x9AQ3\te\xAB]\x93\xD6xfS\xE5\xB2$(\xFA\xE4\xD1\xCC\xA9\x80\xF0\xC3\x36uK\xF0\xD2(B`\x11\x04\x9Bx");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "B\xFD\xE5\xB0\xAC]`\n><\xFF\xDC\x38k\x03!\xE5\xFF\xC1\x31\x94\xC8\x1C\xAE\x83\x39\xA2K\xC5u\xA4\xD3\x9C\x07\xB0\xCE\xDF\x33\xE6\x02\xE3P\xE0\x83\xD8\x97<\x95\xF1\xFF\x34I\x89\xD2\x17\xD9\x17\xACH\x01-1-\xBB\x86\xFE\xED\x01\xBA\x01\tvf\x95Wm\xE0\xCBX%\x0E<\xC9\x9D\x19\x06\xD6\x36\xD9\x1C\tI\xB5IE\x80\x87oM;\x1D\xC3\x9D\xB6\t\x89\x37\xE9\xC2\x34\x94\xE3\xEC].I\x86\xD5\x9C\xAE\x87\xB0m\x11=\xDF\xB1\xFE\xD2\xF6`z3\xE7\xC6\xE8\xEEl\x15\x9D>3\xF8\x8D\xC2\x65(`\xE6I\x9B\x15\xFD\xED \f\xC3_\xC5\xBA\x38\xCB\xF7\x9B\xD9\x14VQM\xAD\x98\xDEJ\xCC#\xA8\x92\xB7\x14\xC1\nX\xD9\xB4\x96$\xB1\x12\xAF\x06\x07TmmTM\xAC\x33\xD4:\x8A\x94M:Srcr\x17\x95pKE\xC1\t\xC0\xB1\x84\x11\xF5\x97\x15\x62\x11\x33\x05\xB5\x9A.@\xBF\x13\xD7\xCAn\xBE\x34\xB5\xA6\x15\xB6\x88\x13\xDE\xA3\xE9\xC3/\xF9\x36L\\\x0E\x1Fg\xDD\xC0\x01\xD0\x90\x9ENq*\xBD\x31/ttV\xAC\xA4\x12?s\xC1\xFF\x35\xBB~\xDC\x05\x06\xFF\xF8\xFA\x1B\x65\x11T\x8Fz\xF3W0\x98\x1D\x7F\x03\x9AQ3\te\xAB]\x93\xD6xfS\xE5\xB2$(\xFA\xE4\xD1\xCC\xA9\x80\xF0\xC3\x36uK\xF0\xD2(B`\x11\x04\x9Bx", a.size-oldSize))
goto end;
append.item = strdup("B\xFD\xE5\xB0\xAC]`\n><\xFF\xDC\x38k\x03!\xE5\xFF\xC1\x31\x94\xC8\x1C\xAE\x83\x39\xA2K\xC5u\xA4\xD3\x9C\x07\xB0\xCE\xDF\x33\xE6\x02\xE3P\xE0\x83\xD8\x97<\x95\xF1\xFF\x34I\x89\xD2\x17\xD9\x17\xACH\x01-1-\xBB\x86\xFE\xED\x01\xBA\x01\tvf\x95Wm\xE0\xCBX%\x0E<\xC9\x9D\x19\x06\xD6\x36\xD9\x1C\tI\xB5IE\x80\x87oM;\x1D\xC3\x9D\xB6\t\x89\x37\xE9\xC2\x34\x94\xE3\xEC].I\x86\xD5\x9C\xAE\x87\xB0m\x11=\xDF\xB1\xFE\xD2\xF6`z3\xE7\xC6\xE8\xEEl\x15\x9D>3\xF8\x8D\xC2\x65(`\xE6I\x9B\x15\xFD\xED \f\xC3_\xC5\xBA\x38\xCB\xF7\x9B\xD9\x14VQM\xAD\x98\xDEJ\xCC#\xA8\x92\xB7\x14\xC1\nX\xD9\xB4\x96$\xB1\x12\xAF\x06\x07TmmTM\xAC\x33\xD4:\x8A\x94M:Srcr\x17\x95pKE\xC1\t\xC0\xB1\x84\x11\xF5\x97\x15\x62\x11\x33\x05\xB5\x9A.@\xBF\x13\xD7\xCAn\xBE\x34\xB5\xA6\x15\xB6\x88\x13\xDE\xA3\xE9\xC3/\xF9\x36L\\\x0E\x1Fg\xDD\xC0\x01\xD0\x90\x9ENq*\xBD\x31/ttV\xAC\xA4\x12?s\xC1\xFF\x35\xBB~\xDC\x05\x06\xFF\xF8\xFA\x1B\x65\x11T\x8Fz\xF3W0\x98\x1D\x7F\x03\x9AQ3\te\xAB]\x93\xD6xfS\xE5\xB2$(\xFA\xE4\xD1\xCC\xA9\x80\xF0\xC3\x36uK\xF0\xD2(B`\x11\x04\x9Bx");
darray_append(strings, append);
testsPassed++;
/* Test 2 */
append.size = sizeof("\x1C\xBA\x07\x30\xD4|%e'yY\x7F\xE2\xD4~\xAB<\xEC%#\x80\xDC\x46\x65\xCA\x9D~\x86\xD6\x84\xF3\x38^\x90\x9A~F\x8F\xF7JH\xFC\xAB\x8Eo\x10W\x97\r\xDB\x36.\xEC\x92\xFBV\x11j\x98\xDAs\x1B&M\xB5\x1D\r\xCD\x14\x34\xA1\x96\xD5\xAD\x05)\xD0\xD9\xA5\xFA\xF3\xD9\x83n\x9A\x95\xDA\xB4\xF5\x1C\"6\x02\x36\x9B)\xA1\x35t+\xA9\xDBS\xD1\x42\x91\xCAr\x8Bq\xE9\x86\x18\xC2\xBE\xDC\xA3\xC4!\xCF\x33\xFE\x81^\x82\x35\x46\x31jG\xB3\x93\x8A\xB5\xD6\xC5\xE5IIVL.u\xD1\x91\"9\xB0\xAF\x86#\x8E\x81>\xC6\xC8\xF5\xAC\xD3\xA5\xC5O\x95\xCA\xAA\x93\x35\x9C\xE8\xB6R\x1F\xE4\xD8\r\xB5\x84K:\xBE\xF3\xDE\x9A\x83\xC8J\xD4\xD7\xBF\x84\x46\xE7\x05;\xFF}\xAAML\xF3\x65,\xA0\x8A\xBF\xA4\"\x9D\x0E*\xAE\x89NA \x12\xCD\xFC\x9A\xE2\xD9\xF0\x62\x08jA\xC3\x44}%\xD1O:\xBAs\xD1\x66I\x10r\x8C\x41\xBFY\r\xA5VP\xD0\x1E\xB6iC\xC9\x65 \xFF\xA9\x8E\x01\xEF\xAE@u\x14\x03\xE9\x34\x83\xBC\xED\x83\xBCW\xB8\xF0\xD9\x65\x41\x07\xA1\xB1 \x03\x39\xC6\x8C\xEF\x92\x81u\x10\x91\xB8\x38\x38*\"\x96m\xEB\fh\xFD%Z\xD7\x64GID^\xA4\x97Q\x8D\xB3\x1B\xE4O:\xC8\x9D\xD0\x89\xAF\xC4)6'\xD5\xB2.\xDD,kZ\xF0n|\x86kU\xB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\x10r\x8C\x41\xBFY\r\xA5VP\xD0\x1E\xB6iC\xC9\x65 \xFF\xA9\x8E\x01\xEF\xAE@u\x14\x03\xE9\x34\x83\xBC\xED\x83\xBCW\xB8\xF0\xD9\x65\x41\x07\xA1\xB1 \x03\x39\xC6\x8C\xEF\x92\x81u\x10\x91\xB8\x38\x38*\"\x96m\xEB\fh\xFD%Z\xD7\x64GID^\xA4\x97Q\x8D\xB3\x1B\xE4O:\xC8\x9D\xD0\x89\xAF\xC4)6'\xD5\xB2.\xDD,kZ\xF0n|\x86kU\xB2V\x01\x65\x0F\xA4\xF1\xEC\xD8\xF6\x89\x7F\x14\xCD\v\x14\xAD\x19\xA0`\x9F)\nW\xB6\x9C\x39\xEB;\xBEJ\xD8\x11\xB8.\xB9\xCF\x81N{m\xE9\x65L\xD2?7\x19\x03\xB8\xB5\x95\x9C!\xDA\x82\x43\x45\x42<\xF3\x8B\xA7\xAB\xE1\x41\x06\x88\x31\x8D\xC8\x7F\xF2\x99\f\xEF\xC5%\x80\x9E\xAC\x93S\x07\x46\xE1l\xC7\x7F\x86\xAA\x05\x83%\xA1\xD9\x34\xAE\xF8\x04\xBCh\xAE");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "\x1C\xBA\x07\x30\xD4|%e'yY\x7F\xE2\xD4~\xAB<\xEC%#\x80\xDC\x46\x65\xCA\x9D~\x86\xD6\x84\xF3\x38^\x90\x9A~F\x8F\xF7JH\xFC\xAB\x8Eo\x10W\x97\r\xDB\x36.\xEC\x92\xFBV\x11j\x98\xDAs\x1B&M\xB5\x1D\r\xCD\x14\x34\xA1\x96\xD5\xAD\x05)\xD0\xD9\xA5\xFA\xF3\xD9\x83n\x9A\x95\xDA\xB4\xF5\x1C\"6\x02\x36\x9B)\xA1\x35t+\xA9\xDBS\xD1\x42\x91\xCAr\x8Bq\xE9\x86\x18\xC2\xBE\xDC\xA3\xC4!\xCF\x33\xFE\x81^\x82\x35\x46\x31jG\xB3\x93\x8A\xB5\xD6\xC5\xE5IIVL.u\xD1\x91\"9\xB0\xAF\x86#\x8E\x81>\xC6\xC8\xF5\xAC\xD3\xA5\xC5O\x95\xCA\xAA\x93\x35\x9C\xE8\xB6R\x1F\xE4\xD8\r\xB5\x84K:\xBE\xF3\xDE\x9A\x83\xC8J\xD4\xD7\xBF\x84\x46\xE7\x05;\xFF}\xAAML\xF3\x65,\xA0\x8A\xBF\xA4\"\x9D\x0E*\xAE\x89NA \x12\xCD\xFC\x9A\xE2\xD9\xF0\x62\x08jA\xC3\x44}%\xD1O:\xBAs\xD1\x66I\x10r\x8C\x41\xBFY\r\xA5VP\xD0\x1E\xB6iC\xC9\x65 \xFF\xA9\x8E\x01\xEF\xAE@u\x14\x03\xE9\x34\x83\xBC\xED\x83\xBCW\xB8\xF0\xD9\x65\x41\x07\xA1\xB1 \x03\x39\xC6\x8C\xEF\x92\x81u\x10\x91\xB8\x38\x38*\"\x96m\xEB\fh\xFD%Z\xD7\x64GID^\xA4\x97Q\x8D\xB3\x1B\xE4O:\xC8\x9D\xD0\x89\xAF\xC4)6'\xD5\xB2.\xDD,kZ\xF0n|\x86kU\xB2V\x01\x65\x0F\xA4\xF1\xEC\xD8\xF6\x89\x7F\x14\xCD\v\x14\xAD\x19\xA0`\x9F)\nW\xB6\x9C\x39\xEB;\xBEJ\xD8\x11\xB8.\xB9\xCF\x81N{m\xE9\x65L\xD2?7\x19\x03\xB8\xB5\x95\x9C!\xDA\x82\x43\x45\x42<\xF3\x8B\xA7\xAB\xE1\x41\x06\x88\x31\x8D\xC8\x7F\xF2\x99\f\xEF\xC5%\x80\x9E\xAC\x93S\x07\x46\xE1l\xC7\x7F\x86\xAA\x05\x83%\xA1\xD9\x34\xAE\xF8\x04\xBCh\xAE", a.size-oldSize))
goto end;
append.item = strdup("\x1C\xBA\x07\x30\xD4|%e'yY\x7F\xE2\xD4~\xAB<\xEC%#\x80\xDC\x46\x65\xCA\x9D~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\x65L\xD2?7\x19\x03\xB8\xB5\x95\x9C!\xDA\x82\x43\x45\x42<\xF3\x8B\xA7\xAB\xE1\x41\x06\x88\x31\x8D\xC8\x7F\xF2\x99\f\xEF\xC5%\x80\x9E\xAC\x93S\x07\x46\xE1l\xC7\x7F\x86\xAA\x05\x83%\xA1\xD9\x34\xAE\xF8\x04\xBCh\xAE");
darray_append(strings, append);
testsPassed++;
/* Test 3 */
append.size = sizeof("\xE8\xD1\x31")-1;
oldSize = a.size;
darray_prepend_lit(a, "\xE8\xD1\x31");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "\xE8\xD1\x31", a.size-oldSize))
goto end;
append.item = strdup("\xE8\xD1\x31");
darray_append(strings, append);
testsPassed++;
/* Test 4 */
append.size = sizeof("\\\x99{A\xC4\x86\xEA\xC4\x41]\xACi\x8C\x08\xFC?\x17\x9E\x90\x83<a\xB9n\xE7g\x04\xF8;\x97\x63=\x7FPy\xDB\xBCJ=\xDA\x13V{pg\xD4/\xB5\x1B\xDD&io\x9D?\xA7\x18,\xE4h\xE3\xB1]\xE4\xB5Iq\xDE\x02%\xBD\x9Al\x8Co\xEC")-1;
oldSize = a.size;
darray_prepend_lit(a, "\\\x99{A\xC4\x86\xEA\xC4\x41]\xACi\x8C\x08\xFC?\x17\x9E\x90\x83<a\xB9n\xE7g\x04\xF8;\x97\x63=\x7FPy\xDB\xBCJ=\xDA\x13V{pg\xD4/\xB5\x1B\xDD&io\x9D?\xA7\x18,\xE4h\xE3\xB1]\xE4\xB5Iq\xDE\x02%\xBD\x9Al\x8Co\xEC");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "\\\x99{A\xC4\x86\xEA\xC4\x41]\xACi\x8C\x08\xFC?\x17\x9E\x90\x83<a\xB9n\xE7g\x04\xF8;\x97\x63=\x7FPy\xDB\xBCJ=\xDA\x13V{pg\xD4/\xB5\x1B\xDD&io\x9D?\xA7\x18,\xE4h\xE3\xB1]\xE4\xB5Iq\xDE\x02%\xBD\x9Al\x8Co\xEC", a.size-oldSize))
goto end;
append.item = strdup("\\\x99{A\xC4\x86\xEA\xC4\x41]\xACi\x8C\x08\xFC?\x17\x9E\x90\x83<a\xB9n\xE7g\x04\xF8;\x97\x63=\x7FPy\xDB\xBCJ=\xDA\x13V{pg\xD4/\xB5\x1B\xDD&io\x9D?\xA7\x18,\xE4h\xE3\xB1]\xE4\xB5Iq\xDE\x02%\xBD\x9Al\x8Co\xEC");
darray_append(strings, append);
testsPassed++;
/* Test 5 */
append.size = sizeof("\x1A\xDD\xD2\xAE\xA7H\xB1\xD4J\xA0\xC5Y\x08\xC7Q\xD4\x41\x46\xA5\x1F\xE1\xEE\x14\x0EP\xFE\x14o\xEF\xB8\x33\x93\x43\xB5YEV3L\xF4\x9F=\x19P\x9B&\xE5\xA7\xF9\x63s\xCB\xCF\x87M^\x92\xB6TnT")-1;
oldSize = a.size;
darray_prepend_lit(a, "\x1A\xDD\xD2\xAE\xA7H\xB1\xD4J\xA0\xC5Y\x08\xC7Q\xD4\x41\x46\xA5\x1F\xE1\xEE\x14\x0EP\xFE\x14o\xEF\xB8\x33\x93\x43\xB5YEV3L\xF4\x9F=\x19P\x9B&\xE5\xA7\xF9\x63s\xCB\xCF\x87M^\x92\xB6TnT");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "\x1A\xDD\xD2\xAE\xA7H\xB1\xD4J\xA0\xC5Y\x08\xC7Q\xD4\x41\x46\xA5\x1F\xE1\xEE\x14\x0EP\xFE\x14o\xEF\xB8\x33\x93\x43\xB5YEV3L\xF4\x9F=\x19P\x9B&\xE5\xA7\xF9\x63s\xCB\xCF\x87M^\x92\xB6TnT", a.size-oldSize))
goto end;
append.item = strdup("\x1A\xDD\xD2\xAE\xA7H\xB1\xD4J\xA0\xC5Y\x08\xC7Q\xD4\x41\x46\xA5\x1F\xE1\xEE\x14\x0EP\xFE\x14o\xEF\xB8\x33\x93\x43\xB5YEV3L\xF4\x9F=\x19P\x9B&\xE5\xA7\xF9\x63s\xCB\xCF\x87M^\x92\xB6TnT");
darray_append(strings, append);
testsPassed++;
/* Test 6 */
append.size = sizeof("\xAF\x37\xE2\x8Bl\xD3\xB9]\x8E\xF9N\xB2@\xE7\x45\xF8\x99\x9E\x66\xB8\xD6\xE4\x82\x44\x89\xD7\x93\xCF\xDF\xA2\x32\x42\xC2\x66\xF6\xA4\x83\x19\x95\x90ts\x99/\xA7\x33\xCC\xA5ka\xC2\x1E\x39\x36\x63\x99\xF7\x10\\\r\xE4\\\xE3\xAD+\xB9\xFC\xB8\xAC\x82K\xD5\x17\x45\xE8\x85\x12\v\xD5\xC2\r\x10\xEF@\xCF\x8B\x7F[w\xFD\x98\xBB\xB0\x30\xEBo~\xE9\x61\x18\xB7(\x1E\x93\xC7\x42J\x9F\x99\xE2\x9B@P\x16\xF8\x19\x9Ak\x17*\xF4\x9C\xFD\xFE\xDF\x95\xC2\x8C/\xBC\xB9\x8B\xB5`\xABt]\xEAl\xB7\xAD\\kn_K\xAER\v\xA7\x8E\xEF\x45\xEAw\x1D\xC7\x85\xA3\xAC\x99tcd\\n\xFA\x8B.\xD7\x91\xEB\x8D\tkkJ\xDD\xD6\"\xC0\x44\x46\xD2\xDD\xDDzn\xA6\x8A\xE2\xE1\xA7Q\xE5\x39\xC0\xC9\xBB=1K\xEC\x9A\xC2\xF0\x1CjS}q\f\xE1\x41\xD6,\x05\xB4\x16R\x05\xD4H\x9Bv\x93\xB4\xD8\xF2}\x1F\x64\xD6r\xFF\x14\x13I'b\x99[\x92\x1E\x9B\xB2\x35\x02\xE9=8\xB9\xD9\xBB\xEB*\x97\x8A\xC8\xEB\xF4!\xE2<\x05\xC3g\x1Dx\xEA\xF5\x99\x83lT\x1E/\xB4\x37})z\xA3\xBE\xF0?\x1FsM1\x81\xC3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1B+\xBE\xFD\xE9\x44\x38\x1D\xD4\x01\x03\xCD<a\xC7l\xE3w");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "\xAF\x37\xE2\x8Bl\xD3\xB9]\x8E\xF9N\xB2@\xE7\x45\xF8\x99\x9E\x66\xB8\xD6\xE4\x82\x44\x89\xD7\x93\xCF\xDF\xA2\x32\x42\xC2\x66\xF6\xA4\x83\x19\x95\x90ts\x99/\xA7\x33\xCC\xA5ka\xC2\x1E\x39\x36\x63\x99\xF7\x10\\\r\xE4\\\xE3\xAD+\xB9\xFC\xB8\xAC\x82K\xD5\x17\x45\xE8\x85\x12\v\xD5\xC2\r\x10\xEF@\xCF\x8B\x7F[w\xFD\x98\xBB\xB0\x30\xEBo~\xE9\x61\x18\xB7(\x1E\x93\xC7\x42J\x9F\x99\xE2\x9B@P\x16\xF8\x19\x9Ak\x17*\xF4\x9C\xFD\xFE\xDF\x95\xC2\x8C/\xBC\xB9\x8B\xB5`\xABt]\xEAl\xB7\xAD\\kn_K\xAER\v\xA7\x8E\xEF\x45\xEAw\x1D\xC7\x85\xA3\xAC\x99tcd\\n\xFA\x8B.\xD7\x91\xEB\x8D\tkkJ\xDD\xD6\"\xC0\x44\x46\xD2\xDD\xDDzn\xA6\x8A\xE2\xE1\xA7Q\xE5\x39\xC0\xC9\xBB=1K\xEC\x9A\xC2\xF0\x1CjS}q\f\xE1\x41\xD6,\x05\xB4\x16R\x05\xD4H\x9Bv\x93\xB4\xD8\xF2}\x1F\x64\xD6r\xFF\x14\x13I'b\x99[\x92\x1E\x9B\xB2\x35\x02\xE9=8\xB9\xD9\xBB\xEB*\x97\x8A\xC8\xEB\xF4!\xE2<\x05\xC3g\x1Dx\xEA\xF5\x99\x83lT\x1E/\xB4\x37})z\xA3\xBE\xF0?\x1FsM1\x81\xC3\x8B\xEA\xF6\x8C\xC3\x11\x9E\xC0\x89\xFA}\x95|tW\x1B+\xBE\xFD\xE9\x44\x38\x1D\xD4\x01\x03\xCD<a\xC7l\xE3w", a.size-oldSize))
goto end;
append.item = strdup("\xAF\x37\xE2\x8Bl\xD3\xB9]\x8E\xF9N\xB2@\xE7\x45\xF8\x99\x9E\x66\xB8\xD6\xE4\x82\x44\x89\xD7\x93\xCF\xDF\xA2\x32\x42\xC2\x66\xF6\xA4\x83\x19\x95\x90ts\x99/\xA7\x33\xCC\xA5ka\xC2\x1E\x39\x36\x63\x99\xF7\x10\\\r\xE4\\\xE3\xAD+\xB9\xFC\xB8\xAC\x82K\xD5\x17\x45\xE8\x85\x12\v\xD5\xC2\r\x10\xEF@\xCF\x8B\x7F[w\xFD\x98\xBB\xB0\x30\xEBo~\xE9\x61\x18\xB7(\x1E\x93\xC7\x42J\x9F\x99\xE2\x9B@P\x16\xF8\x19\x9Ak\x17*\xF4\x9C\xFD\xFE\xDF\x95\xC2\x8C/\xBC\xB9\x8B\xB5`\xABt]\xEAl\xB7\xAD\\kn_K\xAER\v\xA7\x8E\xEF\x45\xEAw\x1D\xC7\x85\xA3\xAC\x99tcd\\n\xFA\x8B.\xD7\x91\xEB\x8D\tkkJ\xDD\xD6\"\xC0\x44\x46\xD2\xDD\xDDzn\xA6\x8A\xE2\xE1\xA7Q\xE5\x39\xC0\xC9\xBB=1K\xEC\x9A\xC2\xF0\x1CjS}q\f\xE1\x41\xD6,\x05\xB4\x16R\x05\xD4H\x9Bv\x93\xB4\xD8\xF2}\x1F\x64\xD6r\xFF\x14\x13I'b\x99[\x92\x1E\x9B\xB2\x35\x02\xE9=8\xB9\xD9\xBB\xEB*\x97\x8A\xC8\xEB\xF4!\xE2<\x05\xC3g\x1Dx\xEA\xF5\x99\x83lT\x1E/\xB4\x37})z\xA3\xBE\xF0?\x1FsM1\x81\xC3\x8B\xEA\xF6\x8C\xC3\x11\x9E\xC0\x89\xFA}\x95|tW\x1B+\xBE\xFD\xE9\x44\x38\x1D\xD4\x01\x03\xCD<a\xC7l\xE3w");
darray_append(strings, append);
testsPassed++;
/* Test 7 */
append.size = sizeof("J\x8E\x1A\xBB\x35\xF4\xEDQ\xE5\xE6|Z[\x04\x37\xC7\xCB\xAB~\x07P\xFE\r9\xF4\x9A\x07\x02P\xB1{\xF9\x42\x1E\x91\x9A\xFC\x8E?\x17\x61Y\xDFIq\x9E\x03\xC7\xB4\xBC\xAA\x1E\xE6\xA4y\x15\x8D\x06\x42\x39\x1D\xDB\xC8\xC2O\xA4\xEA\xF9\xAC\x08\xF6\x1E\xD6\v\t\x14<u\xCC\x0E\xBA.f\xADQga)\x8B\x87\x65(%\xF1M\x88,C\x7FVx\x99\xCBp\xC8\xD3Pk\xC8;\r\xF7\xCE A\x11\xCA\x9A\xA6GW\x8E\x16\xAC\x30\xA8R\x12>\xC8\xCF\x30\x17\x1C\x16\x99\v\xA2\xC3Q{\x17\xB5|4\xC4On\x11\xBC\x46SL\xE1\x61\x1A\xE5W\xFF:\xA0\xDA\xBD\x95\xCBG\xAD(\xAE)-\\\x8F\x64\x95\v\xCB\xE1")-1;
oldSize = a.size;
darray_prepend_lit(a, "J\x8E\x1A\xBB\x35\xF4\xEDQ\xE5\xE6|Z[\x04\x37\xC7\xCB\xAB~\x07P\xFE\r9\xF4\x9A\x07\x02P\xB1{\xF9\x42\x1E\x91\x9A\xFC\x8E?\x17\x61Y\xDFIq\x9E\x03\xC7\xB4\xBC\xAA\x1E\xE6\xA4y\x15\x8D\x06\x42\x39\x1D\xDB\xC8\xC2O\xA4\xEA\xF9\xAC\x08\xF6\x1E\xD6\v\t\x14<u\xCC\x0E\xBA.f\xADQga)\x8B\x87\x65(%\xF1M\x88,C\x7FVx\x99\xCBp\xC8\xD3Pk\xC8;\r\xF7\xCE A\x11\xCA\x9A\xA6GW\x8E\x16\xAC\x30\xA8R\x12>\xC8\xCF\x30\x17\x1C\x16\x99\v\xA2\xC3Q{\x17\xB5|4\xC4On\x11\xBC\x46SL\xE1\x61\x1A\xE5W\xFF:\xA0\xDA\xBD\x95\xCBG\xAD(\xAE)-\\\x8F\x64\x95\v\xCB\xE1");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "J\x8E\x1A\xBB\x35\xF4\xEDQ\xE5\xE6|Z[\x04\x37\xC7\xCB\xAB~\x07P\xFE\r9\xF4\x9A\x07\x02P\xB1{\xF9\x42\x1E\x91\x9A\xFC\x8E?\x17\x61Y\xDFIq\x9E\x03\xC7\xB4\xBC\xAA\x1E\xE6\xA4y\x15\x8D\x06\x42\x39\x1D\xDB\xC8\xC2O\xA4\xEA\xF9\xAC\x08\xF6\x1E\xD6\v\t\x14<u\xCC\x0E\xBA.f\xADQga)\x8B\x87\x65(%\xF1M\x88,C\x7FVx\x99\xCBp\xC8\xD3Pk\xC8;\r\xF7\xCE A\x11\xCA\x9A\xA6GW\x8E\x16\xAC\x30\xA8R\x12>\xC8\xCF\x30\x17\x1C\x16\x99\v\xA2\xC3Q{\x17\xB5|4\xC4On\x11\xBC\x46SL\xE1\x61\x1A\xE5W\xFF:\xA0\xDA\xBD\x95\xCBG\xAD(\xAE)-\\\x8F\x64\x95\v\xCB\xE1", a.size-oldSize))
goto end;
append.item = strdup("J\x8E\x1A\xBB\x35\xF4\xEDQ\xE5\xE6|Z[\x04\x37\xC7\xCB\xAB~\x07P\xFE\r9\xF4\x9A\x07\x02P\xB1{\xF9\x42\x1E\x91\x9A\xFC\x8E?\x17\x61Y\xDFIq\x9E\x03\xC7\xB4\xBC\xAA\x1E\xE6\xA4y\x15\x8D\x06\x42\x39\x1D\xDB\xC8\xC2O\xA4\xEA\xF9\xAC\x08\xF6\x1E\xD6\v\t\x14<u\xCC\x0E\xBA.f\xADQga)\x8B\x87\x65(%\xF1M\x88,C\x7FVx\x99\xCBp\xC8\xD3Pk\xC8;\r\xF7\xCE A\x11\xCA\x9A\xA6GW\x8E\x16\xAC\x30\xA8R\x12>\xC8\xCF\x30\x17\x1C\x16\x99\v\xA2\xC3Q{\x17\xB5|4\xC4On\x11\xBC\x46SL\xE1\x61\x1A\xE5W\xFF:\xA0\xDA\xBD\x95\xCBG\xAD(\xAE)-\\\x8F\x64\x95\v\xCB\xE1");
darray_append(strings, append);
testsPassed++;
/* Test 8 */
append.size = sizeof("DM\x8D]\x92\xC8\x33Y\x8F\x04\x1C?\xB5I\xE9\xEF\xCC\xD4\xB8\xBF\xE9\xC1x\xEA\x46\xB5kQN\xBFLoT\xB4-v\xF5\x31\xD8\xC8\xD3\xF8;r\xE7\xE2\x62\xEF\xA8\xD8O+_M\xED\x16=6|\x86@\x1C\xF1t\x81^\xD1\x8D\xD7\x87\"g?D'\x90[\xBC\x9D\x62\f\xC8W\xD0\xE8\x14\x12o\x80;\n{\x1B\xC0\xD4\xBA\x13\xCD\x8CV\xB5\xFA\xCA&31\xBF\x1DIh\x18\xFB\x0E\xB2\x08i,\xA1\xCE\x9F\xCB\x9F)\xF6\x9E\x46\x95\x8A\xE2\xB3\x99\x36\x65\t\x1C\xFF\x8Bl=u\xBFzf\x9BI\t\xCDP6\x13\x84\x44\xFD\xDE\r\xB2\x36<\xF6\x1F\xEE_\xCC\x86<\x99\x1C\xDC\xAA\xE6Q\x08\xE0\xEC\x66\x11\xDD\xE8\xED\xD0\xCF+\x88\x43\x9B\x92\xE6\xE9mQ\xE0\x32\xD8h\x87\x8D\xB8\xA6r\x03\x80\x8E\xF5\xDB\xB8\xAE<\x17\x8B\xC4\xF2l\x90){\xF4\x84\t\xC5\x80H\xE2k\xFC\xD2\x0F\xBC\xB0\x1D\xE3Y\x8E#bk\xFE+\xCA\x84\xF0\x83\x14o\xA3(\xE5\v\x90\x8Ap\xD8S\xEDkg\x19\x66\xD0\x8Eo\x87\xEC\x44ymR\xEEI\x81\xC6Q>Xp\x8F\xB4\x64\xB5\x8Ar:\x10\xAD\x19/Y\xE2\xDF\xB8\xAA\xF9\x8F\xFD|\x94\xB5&|\x97\x05\x07\x91`v\xA3\xA2\xF9\xDEg\x8E\xF0\x9E}$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xCC\x38\xA8\xA2\x9D\v\f\xFC%\xFE\xCD\x30\x39\xEE\xECI\xAA\x18\x93\xC3\x33\x85\x9B\xA2\xF1\xBB%~\xC2");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "DM\x8D]\x92\xC8\x33Y\x8F\x04\x1C?\xB5I\xE9\xEF\xCC\xD4\xB8\xBF\xE9\xC1x\xEA\x46\xB5kQN\xBFLoT\xB4-v\xF5\x31\xD8\xC8\xD3\xF8;r\xE7\xE2\x62\xEF\xA8\xD8O+_M\xED\x16=6|\x86@\x1C\xF1t\x81^\xD1\x8D\xD7\x87\"g?D'\x90[\xBC\x9D\x62\f\xC8W\xD0\xE8\x14\x12o\x80;\n{\x1B\xC0\xD4\xBA\x13\xCD\x8CV\xB5\xFA\xCA&31\xBF\x1DIh\x18\xFB\x0E\xB2\x08i,\xA1\xCE\x9F\xCB\x9F)\xF6\x9E\x46\x95\x8A\xE2\xB3\x99\x36\x65\t\x1C\xFF\x8Bl=u\xBFzf\x9BI\t\xCDP6\x13\x84\x44\xFD\xDE\r\xB2\x36<\xF6\x1F\xEE_\xCC\x86<\x99\x1C\xDC\xAA\xE6Q\x08\xE0\xEC\x66\x11\xDD\xE8\xED\xD0\xCF+\x88\x43\x9B\x92\xE6\xE9mQ\xE0\x32\xD8h\x87\x8D\xB8\xA6r\x03\x80\x8E\xF5\xDB\xB8\xAE<\x17\x8B\xC4\xF2l\x90){\xF4\x84\t\xC5\x80H\xE2k\xFC\xD2\x0F\xBC\xB0\x1D\xE3Y\x8E#bk\xFE+\xCA\x84\xF0\x83\x14o\xA3(\xE5\v\x90\x8Ap\xD8S\xEDkg\x19\x66\xD0\x8Eo\x87\xEC\x44ymR\xEEI\x81\xC6Q>Xp\x8F\xB4\x64\xB5\x8Ar:\x10\xAD\x19/Y\xE2\xDF\xB8\xAA\xF9\x8F\xFD|\x94\xB5&|\x97\x05\x07\x91`v\xA3\xA2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\xF0\x9E}$\xDA\x63`\xCC\x38\xA8\xA2\x9D\v\f\xFC%\xFE\xCD\x30\x39\xEE\xECI\xAA\x18\x93\xC3\x33\x85\x9B\xA2\xF1\xBB%~\xC2");
darray_append(strings, append);
testsPassed++;
/* Test 9 */
append.size = sizeof("D\x16\xB9\x17yF\xDA\x32\x41\xF4\f\x04\x90\x45\x81\xB0\re\xDD\xC3\x65T\xDF>X\x03!)\xBDUY\xD8\x05\x35\xE6\x12\xA4z0\x1B\xD4\x45-\x17S\xBA%E\xF8\xFB\x32\x8B\x1B\xC0\x91\x39/\xD6\f^B\x01\x43/\x83\xD6`)\xD6\xAD\"\x9C\xD5\x32\xA5\xDC\x39\xC6We\xEB\x32p\xB9n\x89\x41\xBE\x18\xEF\x94\xE4h'\xEDY\xA6\x91\xC3\xD8\x06\xAC;:\xA6M\x7F\r\x07\xDB\x15q5R\xDC\xB2\x05\xAFU=\x1Ax\x86\x13T\x1B\x17\x8Ds\x8F\xF1-\xDD\xCD\x18\xB1\x16\xDF\x80x\v\x85\xDA\xFA\x90\x83\x86\x38x\xC6\xF2\x98\xF8\r\xDF\xC8q\xB5\xA2T=\x08\xB0M\x0E\x0F\x9B\x1C<\xC6\x86\xA8\x8BJ0\xFF\xD2\x1B\xCAh\x93\x32\xBE<\xDF\x7F\xD9\x1C\x16h{Hs\x85\xA1\f\x06\x93\xE4%\x95J\xDE\xAB\x45 \x89Pv\x05o\x02.\r\xA0\x8E\x86\xDF\x34X|*\x14G\x8D\x94)\xFE\xA5\x0Er\xC5\xD6o*us\xE5\x02\xAF\x85\xC7\xEF\x61G6\xEA$X9P\xE9~\x9D\xF5\x99\x8D=\xB7\x8FO\x97\xFA\"\xFF\x41\x41j\xE9\x61\x62\x1D]\xA2\x63\xCD\xC0\r\x83S\x15\x85\x7F\xA4\xA8\f\xE8\x82\xAC\xDC\xF5\x8B\xF2h\x81\xE7.\x92\x9F\x84\xB9J\x03\xD3\xD5<\x90")-1;
oldSize = a.size;
darray_prepend_lit(a, "D\x16\xB9\x17yF\xDA\x32\x41\xF4\f\x04\x90\x45\x81\xB0\re\xDD\xC3\x65T\xDF>X\x03!)\xBDUY\xD8\x05\x35\xE6\x12\xA4z0\x1B\xD4\x45-\x17S\xBA%E\xF8\xFB\x32\x8B\x1B\xC0\x91\x39/\xD6\f^B\x01\x43/\x83\xD6`)\xD6\xAD\"\x9C\xD5\x32\xA5\xDC\x39\xC6We\xEB\x32p\xB9n\x89\x41\xBE\x18\xEF\x94\xE4h'\xEDY\xA6\x91\xC3\xD8\x06\xAC;:\xA6M\x7F\r\x07\xDB\x15q5R\xDC\xB2\x05\xAFU=\x1Ax\x86\x13T\x1B\x17\x8Ds\x8F\xF1-\xDD\xCD\x18\xB1\x16\xDF\x80x\v\x85\xDA\xFA\x90\x83\x86\x38x\xC6\xF2\x98\xF8\r\xDF\xC8q\xB5\xA2T=\x08\xB0M\x0E\x0F\x9B\x1C<\xC6\x86\xA8\x8BJ0\xFF\xD2\x1B\xCAh\x93\x32\xBE<\xDF\x7F\xD9\x1C\x16h{Hs\x85\xA1\f\x06\x93\xE4%\x95J\xDE\xAB\x45 \x89Pv\x05o\x02.\r\xA0\x8E\x86\xDF\x34X|*\x14G\x8D\x94)\xFE\xA5\x0Er\xC5\xD6o*us\xE5\x02\xAF\x85\xC7\xEF\x61G6\xEA$X9P\xE9~\x9D\xF5\x99\x8D=\xB7\x8FO\x97\xFA\"\xFF\x41\x41j\xE9\x61\x62\x1D]\xA2\x63\xCD\xC0\r\x83S\x15\x85\x7F\xA4\xA8\f\xE8\x82\xAC\xDC\xF5\x8B\xF2h\x81\xE7.\x92\x9F\x84\xB9J\x03\xD3\xD5<\x90");
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, "D\x16\xB9\x17yF\xDA\x32\x41\xF4\f\x04\x90\x45\x81\xB0\re\xDD\xC3\x65T\xDF>X\x03!)\xBDUY\xD8\x05\x35\xE6\x12\xA4z0\x1B\xD4\x45-\x17S\xBA%E\xF8\xFB\x32\x8B\x1B\xC0\x91\x39/\xD6\f^B\x01\x43/\x83\xD6`)\xD6\xAD\"\x9C\xD5\x32\xA5\xDC\x39\xC6We\xEB\x32p\xB9n\x89\x41\xBE\x18\xEF\x94\xE4h'\xEDY\xA6\x91\xC3\xD8\x06\xAC;:\xA6M\x7F\r\x07\xDB\x15q5R\xDC\xB2\x05\xAFU=\x1Ax\x86\x13T\x1B\x17\x8Ds\x8F\xF1-\xDD\xCD\x18\xB1\x16\xDF\x80x\v\x85\xDA\xFA\x90\x83\x86\x38x\xC6\xF2\x98\xF8\r\xDF\xC8q\xB5\xA2T=\x08\xB0M\x0E\x0F\x9B\x1C<\xC6\x86\xA8\x8BJ0\xFF\xD2\x1B\xCAh\x93\x32\xBE<\xDF\x7F\xD9\x1C\x16h{Hs\x85\xA1\f\x06\x93\xE4%\x95J\xDE\xAB\x45 \x89Pv\x05o\x02.\r\xA0\x8E\x86\xDF\x34X|*\x14G\x8D\x94)\xFE\xA5\x0Er\xC5\xD6o*us\xE5\x02\xAF\x85\xC7\xEF\x61G6\xEA$X9P\xE9~\x9D\xF5\x99\x8D=\xB7\x8FO\x97\xFA\"\xFF\x41\x41j\xE9\x61\x62\x1D]\xA2\x63\xCD\xC0\r\x83S\x15\x85\x7F\xA4\xA8\f\xE8\x82\xAC\xDC\xF5\x8B\xF2h\x81\xE7.\x92\x9F\x84\xB9J\x03\xD3\xD5<\x90", a.size-oldSize))
goto end;
append.item = strdup("D\x16\xB9\x17yF\xDA\x32\x41\xF4\f\x04\x90\x45\x81\xB0\re\xDD\xC3\x65T\xDF>X\x03!)\xBDUY\xD8\x05\x35\xE6\x12\xA4z0\x1B\xD4\x45-\x17S\xBA%E\xF8\xFB\x32\x8B\x1B\xC0\x91\x39/\xD6\f^B\x01\x43/\x83\xD6`)\xD6\xAD\"\x9C\xD5\x32\xA5\xDC\x39\xC6We\xEB\x32p\xB9n\x89\x41\xBE\x18\xEF\x94\xE4h'\xEDY\xA6\x91\xC3\xD8\x06\xAC;:\xA6M\x7F\r\x07\xDB\x15q5R\xDC\xB2\x05\xAFU=\x1Ax\x86\x13T\x1B\x17\x8Ds\x8F\xF1-\xDD\xCD\x18\xB1\x16\xDF\x80x\v\x85\xDA\xFA\x90\x83\x86\x38x\xC6\xF2\x98\xF8\r\xDF\xC8q\xB5\xA2T=\x08\xB0M\x0E\x0F\x9B\x1C<\xC6\x86\xA8\x8BJ0\xFF\xD2\x1B\xCAh\x93\x32\xBE<\xDF\x7F\xD9\x1C\x16h{Hs\x85\xA1\f\x06\x93\xE4%\x95J\xDE\xAB\x45 \x89Pv\x05o\x02.\r\xA0\x8E\x86\xDF\x34X|*\x14G\x8D\x94)\xFE\xA5\x0Er\xC5\xD6o*us\xE5\x02\xAF\x85\xC7\xEF\x61G6\xEA$X9P\xE9~\x9D\xF5\x99\x8D=\xB7\x8FO\x97\xFA\"\xFF\x41\x41j\xE9\x61\x62\x1D]\xA2\x63\xCD\xC0\r\x83S\x15\x85\x7F\xA4\xA8\f\xE8\x82\xAC\xDC\xF5\x8B\xF2h\x81\xE7.\x92\x9F\x84\xB9J\x03\xD3\xD5<\x90");
darray_append(strings, append);
testsPassed++;
offs = a.size;
if (a.item[offs])
goto end;
if (strings.size != 10)
goto end;
darray_foreach(i, strings) {
if (offs < i->size)
goto end;
offs -= i->size;
if (memcmp(a.item+offs, i->item, i->size))
goto end;
};
if (offs)
goto end;
testsPassed++;
end:
darray_free(a);
darray_foreach(i, strings)
free(i->item);
darray_free(strings);
return testsPassed == 10+1;
}

View File

@ -0,0 +1,149 @@
static int testdarray_from_lit(void);
static int testdarray_append_lit(void);
static int testdarray_prepend_lit(void);
static void testLits(void) {
testing(darray_from_lit);
ok1(testdarray_from_lit());
testing(testdarray_append_lit);
ok1(testdarray_append_lit());
testing(testdarray_prepend_lit);
ok1(testdarray_prepend_lit());
}
static int testdarray_from_lit(void) {
darray_char a = darray_new();
size_t testsPassed = 0;
size_t len = 0;
@forEachRandomString
/* Test @i */
darray_from_lit(a, @str);
len = strlen(@str);
if (len != sizeof(@str)-1)
goto end;
if (a.size != len)
goto end;
if (a.size > a.alloc)
goto end;
if (strcmp(a.item, @str))
goto end;
darray_free(a);
darray_init(a);
testsPassed++;
@end
end:
darray_free(a);
return testsPassed == @amount;
}
typedef struct {
char *item;
size_t size;
} testLits_string;
static int testdarray_append_lit(void) {
darray_char a = darray_new();
darray(testLits_string) strings = darray_new();
testLits_string *i;
size_t testsPassed = 0;
size_t oldSize;
testLits_string append;
size_t offs = 0;
@forEachRandomString
/* Test @i */
append.size = sizeof(@str)-1;
oldSize = a.size;
darray_append_lit(a, @str);
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item+oldSize, @str, a.size-oldSize))
goto end;
append.item = strdup(@str);
darray_append(strings, append);
testsPassed++;
@end
if (strings.size != @amount)
goto end;
darray_foreach(i, strings) {
if (a.size-offs < i->size)
goto end;
if (memcmp(a.item+offs, i->item, i->size))
goto end;
offs += i->size;
};
if (offs != a.size)
goto end;
if (a.item[offs])
goto end;
testsPassed++;
end:
darray_free(a);
darray_foreach(i, strings)
free(i->item);
darray_free(strings);
return testsPassed == @amount+1;
}
static int testdarray_prepend_lit(void) {
darray_char a = darray_new();
darray(testLits_string) strings = darray_new();
testLits_string *i;
size_t testsPassed = 0;
size_t oldSize;
testLits_string append;
size_t offs;
@forEachRandomString
/* Test @i */
append.size = sizeof(@str)-1;
oldSize = a.size;
darray_prepend_lit(a, @str);
if (a.size != oldSize+append.size)
goto end;
if (a.size > a.alloc)
goto end;
if (a.item[a.size])
goto end;
if (memcmp(a.item, @str, a.size-oldSize))
goto end;
append.item = strdup(@str);
darray_append(strings, append);
testsPassed++;
@end
offs = a.size;
if (a.item[offs])
goto end;
if (strings.size != @amount)
goto end;
darray_foreach(i, strings) {
if (offs < i->size)
goto end;
offs -= i->size;
if (memcmp(a.item+offs, i->item, i->size))
goto end;
};
if (offs)
goto end;
testsPassed++;
end:
darray_free(a);
darray_foreach(i, strings)
free(i->item);
darray_free(strings);
return testsPassed == @amount+1;
}

View File

@ -0,0 +1,78 @@
#!/usr/bin/perl
use strict;
use warnings;
my $amount = 10;
my $maxLen = 509;
srand(0);
my $templateFile = 'testLits.h.template';
my $outFile = 'testLits.h';
open(TF, $templateFile);
open(OUT, '>'.$outFile);
select OUT;
my $inLoop = 0;
my $loopText = '';
foreach my $line (<TF>) {
$line =~ s/\@amount/$amount/g;
if (!$inLoop) {
if ($line =~ /\@forEachRandomString/) {
$inLoop = 1;
next;
}
print $line;
} elsif ($inLoop == 1) {
if ($line =~ /\@end/) {
$inLoop = 0;
#handle $loopText
for (my $i=0; $i<$amount; $i++) {
my $str = randomCString($maxLen);
my $lt = $loopText;
$lt =~ s/\@i/$i/g;
$lt =~ s/\@str/\"$str\"/g;
print "$lt\n";
}
$loopText = '';
next;
}
$loopText .= $line;
}
}
close(OUT);
close(TF);
#argument: maxLen
sub randomCString {
my $len = int(rand($_[0]+1));
my $lastWasHex = 0;
my $str = '';
for (my $i=0; $i<$len; $i++) {
my $cn = int(rand(255)) + 1;
my $c = chr($cn);
if ($lastWasHex && ($c =~ /[0-9A-Fa-f]/)) {
$lastWasHex = 1;
$str .= sprintf("\\x%02X", $cn);
} elsif ($c =~ /[\t\n\013\f\r]/) {
$lastWasHex = 0;
$c =~ tr/\t\n\013\f\r/tnvfr/;
$str .= '\\'.$c;
} elsif ($cn<32 || $cn>126) {
$lastWasHex = 1;
$str .= sprintf("\\x%02X", $cn);
} else {
$lastWasHex = 0;
if ($c =~ /[\"\\]/) {
$str .= '\\'.$c;
} else {
$str .= $c;
}
}
}
return $str;
}

28
ccan/ilog/LICENSE Normal file
View File

@ -0,0 +1,28 @@
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
moral rights retained by the original author(s) and/or performer(s);
publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
rights protecting the extraction, dissemination, use and reuse of data in a Work;
database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

50
ccan/ilog/_info Normal file
View File

@ -0,0 +1,50 @@
/**
* ilog - Integer logarithm.
*
* ilog_32() and ilog_64() compute the minimum number of bits required to store
* an unsigned 32-bit or 64-bit value without any leading zero bits.
*
* This can also be thought of as the location of the highest set bit, with
* counting starting from one (so that 0 returns 0, 1 returns 1, and 2**31
* returns 32).
*
* When the value is known to be non-zero ilog32_nz() and ilog64_nz() can
* compile into as few as two instructions, one of which may get optimized out
* later.
*
* STATIC_ILOG_32 and STATIC_ILOG_64 allow computation on compile-time
* constants, so other compile-time constants can be derived from them.
*
* Example:
* #include <stdio.h>
* #include <limits.h>
* #include <ccan/ilog/ilog.h>
*
* int main(void){
* int i;
* printf("ilog32(0x%08X)=%i\n",0,ilog32(0));
* for(i=1;i<=STATIC_ILOG_32(USHRT_MAX);i++){
* uint32_t v;
* v=(uint32_t)1U<<(i-1);
* //Here we know v is non-zero, so we can use ilog32_nz().
* printf("ilog32(0x%08X)=%i\n",v,ilog32_nz(v));
* }
* return 0;
* }
*
* License: CC0 (Public domain)
* Author: Timothy B. Terriberry <tterribe@xiph.org>
*/
#include "config.h"
#include <string.h>
#include <stdio.h>
int main(int _argc,const char *_argv[]){
/*Expect exactly one argument.*/
if(_argc!=2)return 1;
if(strcmp(_argv[1],"depends")==0){
printf("ccan/compiler\n");
return 0;
}
return 1;
}

141
ccan/ilog/ilog.c Normal file
View File

@ -0,0 +1,141 @@
/*(C) Timothy B. Terriberry (tterribe@xiph.org) 2001-2009 CC0 (Public domain).
* See LICENSE file for details. */
#include "ilog.h"
#include <limits.h>
/*The fastest fallback strategy for platforms with fast multiplication appears
to be based on de Bruijn sequences~\cite{LP98}.
Tests confirmed this to be true even on an ARM11, where it is actually faster
than using the native clz instruction.
Define ILOG_NODEBRUIJN to use a simpler fallback on platforms where
multiplication or table lookups are too expensive.
@UNPUBLISHED{LP98,
author="Charles E. Leiserson and Harald Prokop",
title="Using de {Bruijn} Sequences to Index a 1 in a Computer Word",
month=Jun,
year=1998,
note="\url{http://supertech.csail.mit.edu/papers/debruijn.pdf}"
}*/
static UNNEEDED const unsigned char DEBRUIJN_IDX32[32]={
0, 1,28, 2,29,14,24, 3,30,22,20,15,25,17, 4, 8,
31,27,13,23,21,19,16, 7,26,12,18, 6,11, 5,10, 9
};
/* We always compile these in, in case someone takes address of function. */
#undef ilog32_nz
#undef ilog32
#undef ilog64_nz
#undef ilog64
int ilog32(uint32_t _v){
/*On a Pentium M, this branchless version tested as the fastest version without
multiplications on 1,000,000,000 random 32-bit integers, edging out a
similar version with branches, and a 256-entry LUT version.*/
# if defined(ILOG_NODEBRUIJN)
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFU)<<4;
_v>>=m;
ret|=m;
m=(_v>0xFFU)<<3;
_v>>=m;
ret|=m;
m=(_v>0xFU)<<2;
_v>>=m;
ret|=m;
m=(_v>3)<<1;
_v>>=m;
ret|=m;
ret+=_v>1;
return ret;
/*This de Bruijn sequence version is faster if you have a fast multiplier.*/
# else
int ret;
ret=_v>0;
_v|=_v>>1;
_v|=_v>>2;
_v|=_v>>4;
_v|=_v>>8;
_v|=_v>>16;
_v=(_v>>1)+1;
ret+=DEBRUIJN_IDX32[_v*0x77CB531U>>27&0x1F];
return ret;
# endif
}
int ilog32_nz(uint32_t _v)
{
return ilog32(_v);
}
int ilog64(uint64_t _v){
# if defined(ILOG_NODEBRUIJN)
uint32_t v;
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFFFFFU)<<5;
v=(uint32_t)(_v>>m);
ret|=m;
m=(v>0xFFFFU)<<4;
v>>=m;
ret|=m;
m=(v>0xFFU)<<3;
v>>=m;
ret|=m;
m=(v>0xFU)<<2;
v>>=m;
ret|=m;
m=(v>3)<<1;
v>>=m;
ret|=m;
ret+=v>1;
return ret;
# else
/*If we don't have a 64-bit word, split it into two 32-bit halves.*/
# if LONG_MAX<9223372036854775807LL
uint32_t v;
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFFFFFU)<<5;
v=(uint32_t)(_v>>m);
ret|=m;
v|=v>>1;
v|=v>>2;
v|=v>>4;
v|=v>>8;
v|=v>>16;
v=(v>>1)+1;
ret+=DEBRUIJN_IDX32[v*0x77CB531U>>27&0x1F];
return ret;
/*Otherwise do it in one 64-bit operation.*/
# else
static const unsigned char DEBRUIJN_IDX64[64]={
0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40,
5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57,
63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56,
62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58
};
int ret;
ret=_v>0;
_v|=_v>>1;
_v|=_v>>2;
_v|=_v>>4;
_v|=_v>>8;
_v|=_v>>16;
_v|=_v>>32;
_v=(_v>>1)+1;
ret+=DEBRUIJN_IDX64[_v*0x218A392CD3D5DBF>>58&0x3F];
return ret;
# endif
# endif
}
int ilog64_nz(uint64_t _v)
{
return ilog64(_v);
}

151
ccan/ilog/ilog.h Normal file
View File

@ -0,0 +1,151 @@
/* CC0 (Public domain) - see LICENSE file for details */
#if !defined(_ilog_H)
# define _ilog_H (1)
# include "config.h"
# include <stdint.h>
# include <limits.h>
# include <ccan/compiler/compiler.h>
/**
* ilog32 - Integer binary logarithm of a 32-bit value.
* @_v: A 32-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* Note that many uses will resolve to the fast macro version instead.
*
* See Also:
* ilog32_nz(), ilog64()
*
* Example:
* // Rounds up to next power of 2 (if not a power of 2).
* static uint32_t round_up32(uint32_t i)
* {
* assert(i != 0);
* return 1U << ilog32(i-1);
* }
*/
int ilog32(uint32_t _v) CONST_FUNCTION;
/**
* ilog32_nz - Integer binary logarithm of a non-zero 32-bit value.
* @_v: A 32-bit value.
* Returns floor(log2(_v))+1, or undefined if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* Note that many uses will resolve to the fast macro version instead.
* See Also:
* ilog32(), ilog64_nz()
* Example:
* // Find Last Set (ie. highest bit set, 0 to 31).
* static uint32_t fls32(uint32_t i)
* {
* assert(i != 0);
* return ilog32_nz(i) - 1;
* }
*/
int ilog32_nz(uint32_t _v) CONST_FUNCTION;
/**
* ilog64 - Integer binary logarithm of a 64-bit value.
* @_v: A 64-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* Note that many uses will resolve to the fast macro version instead.
* See Also:
* ilog64_nz(), ilog32()
*/
int ilog64(uint64_t _v) CONST_FUNCTION;
/**
* ilog64_nz - Integer binary logarithm of a non-zero 64-bit value.
* @_v: A 64-bit value.
* Returns floor(log2(_v))+1, or undefined if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* Note that many uses will resolve to the fast macro version instead.
* See Also:
* ilog64(), ilog32_nz()
*/
int ilog64_nz(uint64_t _v) CONST_FUNCTION;
/**
* STATIC_ILOG_32 - The integer logarithm of an (unsigned, 32-bit) constant.
* @_v: A non-negative 32-bit constant.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* This macro should only be used when you need a compile-time constant,
* otherwise ilog32 or ilog32_nz are just as fast and more flexible.
*
* Example:
* #define MY_PAGE_SIZE 4096
* #define MY_PAGE_BITS (STATIC_ILOG_32(PAGE_SIZE) - 1)
*/
#define STATIC_ILOG_32(_v) (STATIC_ILOG5((uint32_t)(_v)))
/**
* STATIC_ILOG_64 - The integer logarithm of an (unsigned, 64-bit) constant.
* @_v: A non-negative 64-bit constant.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* This macro should only be used when you need a compile-time constant,
* otherwise ilog64 or ilog64_nz are just as fast and more flexible.
*/
#define STATIC_ILOG_64(_v) (STATIC_ILOG6((uint64_t)(_v)))
/* Private implementation details */
/*Note the casts to (int) below: this prevents "upgrading"
the type of an entire expression to an (unsigned) size_t.*/
#if INT_MAX>=2147483647 && HAVE_BUILTIN_CLZ
#define builtin_ilog32_nz(v) \
(((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clz(v))
#elif LONG_MAX>=2147483647L && HAVE_BUILTIN_CLZL
#define builtin_ilog32_nz(v) \
(((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clzl(v))
#endif
#if INT_MAX>=9223372036854775807LL && HAVE_BUILTIN_CLZ
#define builtin_ilog64_nz(v) \
(((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clz(v))
#elif LONG_MAX>=9223372036854775807LL && HAVE_BUILTIN_CLZL
#define builtin_ilog64_nz(v) \
(((int)sizeof(unsigned long)*CHAR_BIT) - __builtin_clzl(v))
#elif HAVE_BUILTIN_CLZLL
#define builtin_ilog64_nz(v) \
(((int)sizeof(unsigned long long)*CHAR_BIT) - __builtin_clzll(v))
#endif
#ifdef builtin_ilog32_nz
#define ilog32(_v) (builtin_ilog32_nz(_v)&-!!(_v))
#define ilog32_nz(_v) builtin_ilog32_nz(_v)
#else
#define ilog32_nz(_v) ilog32(_v)
#define ilog32(_v) (IS_COMPILE_CONSTANT(_v) ? STATIC_ILOG_32(_v) : ilog32(_v))
#endif /* builtin_ilog32_nz */
#ifdef builtin_ilog64_nz
#define ilog64(_v) (builtin_ilog64_nz(_v)&-!!(_v))
#define ilog64_nz(_v) builtin_ilog64_nz(_v)
#else
#define ilog64_nz(_v) ilog64(_v)
#define ilog64(_v) (IS_COMPILE_CONSTANT(_v) ? STATIC_ILOG_64(_v) : ilog64(_v))
#endif /* builtin_ilog64_nz */
/* Macros for evaluating compile-time constant ilog. */
# define STATIC_ILOG0(_v) (!!(_v))
# define STATIC_ILOG1(_v) (((_v)&0x2)?2:STATIC_ILOG0(_v))
# define STATIC_ILOG2(_v) (((_v)&0xC)?2+STATIC_ILOG1((_v)>>2):STATIC_ILOG1(_v))
# define STATIC_ILOG3(_v) \
(((_v)&0xF0)?4+STATIC_ILOG2((_v)>>4):STATIC_ILOG2(_v))
# define STATIC_ILOG4(_v) \
(((_v)&0xFF00)?8+STATIC_ILOG3((_v)>>8):STATIC_ILOG3(_v))
# define STATIC_ILOG5(_v) \
(((_v)&0xFFFF0000)?16+STATIC_ILOG4((_v)>>16):STATIC_ILOG4(_v))
# define STATIC_ILOG6(_v) \
(((_v)&0xFFFFFFFF00000000ULL)?32+STATIC_ILOG5((_v)>>32):STATIC_ILOG5(_v))
#endif /* _ilog_H */

View File

@ -0,0 +1,65 @@
#include <ccan/ilog/ilog.h>
#include <ccan/ilog/ilog.c>
#include <stdio.h>
#include <ccan/tap/tap.h>
/*Dead simple (but slow) versions to compare against.*/
static int test_ilog32(uint32_t _v){
int ret;
for(ret=0;_v;ret++)_v>>=1;
return ret;
}
static int test_ilog64(uint64_t _v){
int ret;
for(ret=0;_v;ret++)_v>>=1;
return ret;
}
#define NTRIALS (64)
int main(int _argc,const char *_argv[]){
int i;
int j;
int (*il32)(uint32_t) = ilog32;
int (*il64)(uint64_t) = ilog64;
int (*il32_nz)(uint32_t) = ilog32_nz;
int (*il64_nz)(uint64_t) = ilog64_nz;
/*This is how many tests you plan to run.*/
plan_tests(33 * NTRIALS * 3 + 65 * NTRIALS * 3);
for(i=0;i<=32;i++){
uint32_t v;
/*Test each bit in turn (and 0).*/
v=i?(uint32_t)1U<<(i-1):0;
for(j=0;j<NTRIALS;j++){
int l;
l=test_ilog32(v);
ok1(STATIC_ILOG_32(v)==l);
ok1(il32(v)==l);
ok1(il32_nz(v) == l || v == 0);
/*Also try a few more pseudo-random values with at most the same number
of bits.*/
v=(1103515245U*v+12345U)&0xFFFFFFFFU>>((33-i)>>1)>>((32-i)>>1);
}
}
for(i=0;i<=64;i++){
uint64_t v;
/*Test each bit in turn (and 0).*/
v=i?(uint64_t)1U<<(i-1):0;
for(j=0;j<NTRIALS;j++){
int l;
l=test_ilog64(v);
ok1(STATIC_ILOG_64(v)==l);
ok1(il64(v)==l);
ok1(il64_nz(v) == l || v == 0);
/*Also try a few more pseudo-random values with at most the same number
of bits.*/
v=(uint64_t)((2862933555777941757ULL*v+3037000493ULL)
&0xFFFFFFFFFFFFFFFFULL>>((65-i)>>1)>>((64-i)>>1));
}
}
return exit_status();
}

60
ccan/ilog/test/run.c Normal file
View File

@ -0,0 +1,60 @@
#include <ccan/ilog/ilog.h>
#include <ccan/ilog/ilog.c>
#include <stdio.h>
#include <ccan/tap/tap.h>
/*Dead simple (but slow) versions to compare against.*/
static int test_ilog32(uint32_t _v){
int ret;
for(ret=0;_v;ret++)_v>>=1;
return ret;
}
static int test_ilog64(uint64_t _v){
int ret;
for(ret=0;_v;ret++)_v>>=1;
return ret;
}
#define NTRIALS (64)
int main(int _argc,const char *_argv[]){
int i;
int j;
/*This is how many tests you plan to run.*/
plan_tests(33 * NTRIALS * 3 + 65 * NTRIALS * 3);
for(i=0;i<=32;i++){
uint32_t v;
/*Test each bit in turn (and 0).*/
v=i?(uint32_t)1U<<(i-1):0;
for(j=0;j<NTRIALS;j++){
int l;
l=test_ilog32(v);
ok1(STATIC_ILOG_32(v)==l);
ok1(ilog32(v)==l);
ok1(ilog32_nz(v) == l || v == 0);
/*Also try a few more pseudo-random values with at most the same number
of bits.*/
v=(1103515245U*v+12345U)&0xFFFFFFFFU>>((33-i)>>1)>>((32-i)>>1);
}
}
for(i=0;i<=64;i++){
uint64_t v;
/*Test each bit in turn (and 0).*/
v=i?(uint64_t)1U<<(i-1):0;
for(j=0;j<NTRIALS;j++){
int l;
l=test_ilog64(v);
ok1(STATIC_ILOG_64(v)==l);
ok1(ilog64(v)==l);
ok1(ilog64_nz(v) == l || v == 0);
/*Also try a few more pseudo-random values with at most the same number
of bits.*/
v=(uint64_t)((2862933555777941757ULL*v+3037000493ULL)
&0xFFFFFFFFFFFFFFFFULL>>((65-i)>>1)>>((64-i)>>1));
}
}
return exit_status();
}

0
config.h Normal file
View File

View File

@ -1,5 +1,5 @@
/*
* Author: Kent Overstreet <kmo@daterainc.com>
* Author: Kent Overstreet <kent.overstreet@gmail.com>
*
* GPLv2
*/
@ -66,7 +66,7 @@ int main(int argc, char **argv)
continue;
}
if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb))
if (pread(fd, &sb, sizeof(sb), SB_SECTOR << 9) != sizeof(sb))
continue;
if (memcmp(&sb.magic, &BCACHE_MAGIC, sizeof(sb.magic)))

489
util.c Normal file
View File

@ -0,0 +1,489 @@
#include <alloca.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <linux/fs.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <blkid.h>
#include <uuid/uuid.h>
#include "ccan/crc/crc.h"
#include "util.h"
/* Integer stuff: */
u64 rounddown_pow_of_two(u64 n)
{
u64 ret;
do {
ret = n;
n &= n - 1;
} while (n);
return ret;
}
unsigned ilog2(u64 n)
{
unsigned ret = 0;
while (n) {
ret++;
n >>= 1;
}
return ret;
}
char *skip_spaces(const char *str)
{
while (isspace(*str))
++str;
return (char *)str;
}
char *strim(char *s)
{
size_t size;
char *end;
s = skip_spaces(s);
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';
return s;
}
/* Argument parsing stuff: */
long strtoul_or_die(const char *p, size_t max, const char *msg)
{
errno = 0;
long v = strtol(p, NULL, 10);
if (errno || v < 0 || v >= max)
die("Invalid %s %zi", msg, v);
return v;
}
u64 hatoi(const char *s)
{
char *e;
long long i = strtoll(s, &e, 10);
switch (*e) {
case 't':
case 'T':
i *= 1024;
case 'g':
case 'G':
i *= 1024;
case 'm':
case 'M':
i *= 1024;
case 'k':
case 'K':
i *= 1024;
}
return i;
}
unsigned hatoi_validate(const char *s, const char *msg)
{
u64 v = hatoi(s);
if (v & (v - 1))
die("%s must be a power of two", msg);
v /= 512;
if (v > USHRT_MAX)
die("%s too large\n", msg);
if (!v)
die("%s too small\n", msg);
return v;
}
unsigned nr_args(char * const *args)
{
unsigned i;
for (i = 0; args[i]; i++)
;
return i;
}
/* File parsing (i.e. sysfs) */
char *read_file_str(int dirfd, const char *path)
{
int fd = openat(dirfd, path, O_RDONLY);
if (fd < 0)
die("Unable to open %s\n", path);
struct stat statbuf;
if (fstat(fd, &statbuf) < 0)
die("fstat error\n");
char *buf = malloc(statbuf.st_size + 1);
int len = read(fd, buf, statbuf.st_size);
if (len < 0)
die("read error while reading from file %s\n", path);
buf[len] = '\0';
if (len && buf[len - 1] == '\n')
buf[len - 1] = '\0';
close(fd);
return buf;
}
u64 read_file_u64(int dirfd, const char *path)
{
char *buf = read_file_str(dirfd, path);
u64 ret = strtoll(buf, NULL, 10);
free(buf);
return ret;
}
/* String list options: */
ssize_t read_string_list(const char *buf, const char * const list[])
{
size_t i;
char *s, *d = strdup(buf);
if (!d)
return -ENOMEM;
s = strim(d);
for (i = 0; list[i]; i++)
if (!strcmp(list[i], s))
break;
free(d);
if (!list[i])
return -EINVAL;
return i;
}
ssize_t read_string_list_or_die(const char *opt, const char * const list[],
const char *msg)
{
ssize_t v = read_string_list(opt, list);
if (v < 0)
die("Bad %s %s", msg, opt);
return v;
}
void print_string_list(const char * const list[], size_t selected)
{
size_t i;
for (i = 0; list[i]; i++) {
if (i)
putchar(' ');
printf(i == selected ? "[%s] ": "%s", list[i]);
}
}
/* Returns size of file or block device, in units of 512 byte sectors: */
u64 get_size(const char *path, int fd)
{
struct stat statbuf;
if (fstat(fd, &statbuf))
die("Error statting %s: %s", path, strerror(errno));
if (!S_ISBLK(statbuf.st_mode))
return statbuf.st_size >> 9;
u64 ret;
if (ioctl(fd, BLKGETSIZE64, &ret))
die("Error getting block device size on %s: %s\n",
path, strerror(errno));
return ret >> 9;
}
/* Returns blocksize in units of 512 byte sectors: */
unsigned get_blocksize(const char *path, int fd)
{
struct stat statbuf;
if (fstat(fd, &statbuf))
die("Error statting %s: %s", path, strerror(errno));
if (!S_ISBLK(statbuf.st_mode))
return statbuf.st_blksize >> 9;
unsigned ret;
if (ioctl(fd, BLKPBSZGET, &ret))
die("Error getting blocksize on %s: %s\n",
path, strerror(errno));
return ret >> 9;
}
/* Open a block device, do magic blkid stuff: */
int dev_open(const char *dev)
{
blkid_probe pr;
int fd;
if ((fd = open(dev, O_RDWR|O_EXCL)) == -1)
die("Can't open dev %s: %s\n", dev, strerror(errno));
if (!(pr = blkid_new_probe()))
die("Failed to create a new probe");
if (blkid_probe_set_device(pr, fd, 0, 0))
die("failed to set probe to device");
/* enable ptable probing; superblock probing is enabled by default */
if (blkid_probe_enable_partitions(pr, true))
die("Failed to enable partitions on probe");
if (!blkid_do_probe(pr))
/* XXX wipefs doesn't know how to remove partition tables */
die("Device %s already has a non-bcache superblock, "
"remove it using wipefs and wipefs -a\n", dev);
return fd;
}
/* Checksums: */
/*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group (Any
* use permitted, subject to terms of PostgreSQL license; see.)
* If we have a 64-bit integer type, then a 64-bit CRC looks just like the
* usual sort of implementation. (See Ross Williams' excellent introduction
* A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from
* ftp://ftp.rocksoft.com/papers/crc_v3.txt or several other net sites.)
* If we have no working 64-bit type, then fake it with two 32-bit registers.
*
* The present implementation is a normal (not "reflected", in Williams'
* terms) 64-bit CRC, using initial all-ones register contents and a final
* bit inversion. The chosen polynomial is borrowed from the DLT1 spec
* (ECMA-182, available from http://www.ecma.ch/ecma1/STAND/ECMA-182.HTM):
*
* x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 +
* x^40 + x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 +
* x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 +
* x^7 + x^4 + x + 1
*/
static const u64 crc_table[256] = {
0x0000000000000000ULL, 0x42F0E1EBA9EA3693ULL, 0x85E1C3D753D46D26ULL,
0xC711223CFA3E5BB5ULL, 0x493366450E42ECDFULL, 0x0BC387AEA7A8DA4CULL,
0xCCD2A5925D9681F9ULL, 0x8E224479F47CB76AULL, 0x9266CC8A1C85D9BEULL,
0xD0962D61B56FEF2DULL, 0x17870F5D4F51B498ULL, 0x5577EEB6E6BB820BULL,
0xDB55AACF12C73561ULL, 0x99A54B24BB2D03F2ULL, 0x5EB4691841135847ULL,
0x1C4488F3E8F96ED4ULL, 0x663D78FF90E185EFULL, 0x24CD9914390BB37CULL,
0xE3DCBB28C335E8C9ULL, 0xA12C5AC36ADFDE5AULL, 0x2F0E1EBA9EA36930ULL,
0x6DFEFF5137495FA3ULL, 0xAAEFDD6DCD770416ULL, 0xE81F3C86649D3285ULL,
0xF45BB4758C645C51ULL, 0xB6AB559E258E6AC2ULL, 0x71BA77A2DFB03177ULL,
0x334A9649765A07E4ULL, 0xBD68D2308226B08EULL, 0xFF9833DB2BCC861DULL,
0x388911E7D1F2DDA8ULL, 0x7A79F00C7818EB3BULL, 0xCC7AF1FF21C30BDEULL,
0x8E8A101488293D4DULL, 0x499B3228721766F8ULL, 0x0B6BD3C3DBFD506BULL,
0x854997BA2F81E701ULL, 0xC7B97651866BD192ULL, 0x00A8546D7C558A27ULL,
0x4258B586D5BFBCB4ULL, 0x5E1C3D753D46D260ULL, 0x1CECDC9E94ACE4F3ULL,
0xDBFDFEA26E92BF46ULL, 0x990D1F49C77889D5ULL, 0x172F5B3033043EBFULL,
0x55DFBADB9AEE082CULL, 0x92CE98E760D05399ULL, 0xD03E790CC93A650AULL,
0xAA478900B1228E31ULL, 0xE8B768EB18C8B8A2ULL, 0x2FA64AD7E2F6E317ULL,
0x6D56AB3C4B1CD584ULL, 0xE374EF45BF6062EEULL, 0xA1840EAE168A547DULL,
0x66952C92ECB40FC8ULL, 0x2465CD79455E395BULL, 0x3821458AADA7578FULL,
0x7AD1A461044D611CULL, 0xBDC0865DFE733AA9ULL, 0xFF3067B657990C3AULL,
0x711223CFA3E5BB50ULL, 0x33E2C2240A0F8DC3ULL, 0xF4F3E018F031D676ULL,
0xB60301F359DBE0E5ULL, 0xDA050215EA6C212FULL, 0x98F5E3FE438617BCULL,
0x5FE4C1C2B9B84C09ULL, 0x1D14202910527A9AULL, 0x93366450E42ECDF0ULL,
0xD1C685BB4DC4FB63ULL, 0x16D7A787B7FAA0D6ULL, 0x5427466C1E109645ULL,
0x4863CE9FF6E9F891ULL, 0x0A932F745F03CE02ULL, 0xCD820D48A53D95B7ULL,
0x8F72ECA30CD7A324ULL, 0x0150A8DAF8AB144EULL, 0x43A04931514122DDULL,
0x84B16B0DAB7F7968ULL, 0xC6418AE602954FFBULL, 0xBC387AEA7A8DA4C0ULL,
0xFEC89B01D3679253ULL, 0x39D9B93D2959C9E6ULL, 0x7B2958D680B3FF75ULL,
0xF50B1CAF74CF481FULL, 0xB7FBFD44DD257E8CULL, 0x70EADF78271B2539ULL,
0x321A3E938EF113AAULL, 0x2E5EB66066087D7EULL, 0x6CAE578BCFE24BEDULL,
0xABBF75B735DC1058ULL, 0xE94F945C9C3626CBULL, 0x676DD025684A91A1ULL,
0x259D31CEC1A0A732ULL, 0xE28C13F23B9EFC87ULL, 0xA07CF2199274CA14ULL,
0x167FF3EACBAF2AF1ULL, 0x548F120162451C62ULL, 0x939E303D987B47D7ULL,
0xD16ED1D631917144ULL, 0x5F4C95AFC5EDC62EULL, 0x1DBC74446C07F0BDULL,
0xDAAD56789639AB08ULL, 0x985DB7933FD39D9BULL, 0x84193F60D72AF34FULL,
0xC6E9DE8B7EC0C5DCULL, 0x01F8FCB784FE9E69ULL, 0x43081D5C2D14A8FAULL,
0xCD2A5925D9681F90ULL, 0x8FDAB8CE70822903ULL, 0x48CB9AF28ABC72B6ULL,
0x0A3B7B1923564425ULL, 0x70428B155B4EAF1EULL, 0x32B26AFEF2A4998DULL,
0xF5A348C2089AC238ULL, 0xB753A929A170F4ABULL, 0x3971ED50550C43C1ULL,
0x7B810CBBFCE67552ULL, 0xBC902E8706D82EE7ULL, 0xFE60CF6CAF321874ULL,
0xE224479F47CB76A0ULL, 0xA0D4A674EE214033ULL, 0x67C58448141F1B86ULL,
0x253565A3BDF52D15ULL, 0xAB1721DA49899A7FULL, 0xE9E7C031E063ACECULL,
0x2EF6E20D1A5DF759ULL, 0x6C0603E6B3B7C1CAULL, 0xF6FAE5C07D3274CDULL,
0xB40A042BD4D8425EULL, 0x731B26172EE619EBULL, 0x31EBC7FC870C2F78ULL,
0xBFC9838573709812ULL, 0xFD39626EDA9AAE81ULL, 0x3A28405220A4F534ULL,
0x78D8A1B9894EC3A7ULL, 0x649C294A61B7AD73ULL, 0x266CC8A1C85D9BE0ULL,
0xE17DEA9D3263C055ULL, 0xA38D0B769B89F6C6ULL, 0x2DAF4F0F6FF541ACULL,
0x6F5FAEE4C61F773FULL, 0xA84E8CD83C212C8AULL, 0xEABE6D3395CB1A19ULL,
0x90C79D3FEDD3F122ULL, 0xD2377CD44439C7B1ULL, 0x15265EE8BE079C04ULL,
0x57D6BF0317EDAA97ULL, 0xD9F4FB7AE3911DFDULL, 0x9B041A914A7B2B6EULL,
0x5C1538ADB04570DBULL, 0x1EE5D94619AF4648ULL, 0x02A151B5F156289CULL,
0x4051B05E58BC1E0FULL, 0x87409262A28245BAULL, 0xC5B073890B687329ULL,
0x4B9237F0FF14C443ULL, 0x0962D61B56FEF2D0ULL, 0xCE73F427ACC0A965ULL,
0x8C8315CC052A9FF6ULL, 0x3A80143F5CF17F13ULL, 0x7870F5D4F51B4980ULL,
0xBF61D7E80F251235ULL, 0xFD913603A6CF24A6ULL, 0x73B3727A52B393CCULL,
0x31439391FB59A55FULL, 0xF652B1AD0167FEEAULL, 0xB4A25046A88DC879ULL,
0xA8E6D8B54074A6ADULL, 0xEA16395EE99E903EULL, 0x2D071B6213A0CB8BULL,
0x6FF7FA89BA4AFD18ULL, 0xE1D5BEF04E364A72ULL, 0xA3255F1BE7DC7CE1ULL,
0x64347D271DE22754ULL, 0x26C49CCCB40811C7ULL, 0x5CBD6CC0CC10FAFCULL,
0x1E4D8D2B65FACC6FULL, 0xD95CAF179FC497DAULL, 0x9BAC4EFC362EA149ULL,
0x158E0A85C2521623ULL, 0x577EEB6E6BB820B0ULL, 0x906FC95291867B05ULL,
0xD29F28B9386C4D96ULL, 0xCEDBA04AD0952342ULL, 0x8C2B41A1797F15D1ULL,
0x4B3A639D83414E64ULL, 0x09CA82762AAB78F7ULL, 0x87E8C60FDED7CF9DULL,
0xC51827E4773DF90EULL, 0x020905D88D03A2BBULL, 0x40F9E43324E99428ULL,
0x2CFFE7D5975E55E2ULL, 0x6E0F063E3EB46371ULL, 0xA91E2402C48A38C4ULL,
0xEBEEC5E96D600E57ULL, 0x65CC8190991CB93DULL, 0x273C607B30F68FAEULL,
0xE02D4247CAC8D41BULL, 0xA2DDA3AC6322E288ULL, 0xBE992B5F8BDB8C5CULL,
0xFC69CAB42231BACFULL, 0x3B78E888D80FE17AULL, 0x7988096371E5D7E9ULL,
0xF7AA4D1A85996083ULL, 0xB55AACF12C735610ULL, 0x724B8ECDD64D0DA5ULL,
0x30BB6F267FA73B36ULL, 0x4AC29F2A07BFD00DULL, 0x08327EC1AE55E69EULL,
0xCF235CFD546BBD2BULL, 0x8DD3BD16FD818BB8ULL, 0x03F1F96F09FD3CD2ULL,
0x41011884A0170A41ULL, 0x86103AB85A2951F4ULL, 0xC4E0DB53F3C36767ULL,
0xD8A453A01B3A09B3ULL, 0x9A54B24BB2D03F20ULL, 0x5D45907748EE6495ULL,
0x1FB5719CE1045206ULL, 0x919735E51578E56CULL, 0xD367D40EBC92D3FFULL,
0x1476F63246AC884AULL, 0x568617D9EF46BED9ULL, 0xE085162AB69D5E3CULL,
0xA275F7C11F7768AFULL, 0x6564D5FDE549331AULL, 0x279434164CA30589ULL,
0xA9B6706FB8DFB2E3ULL, 0xEB46918411358470ULL, 0x2C57B3B8EB0BDFC5ULL,
0x6EA7525342E1E956ULL, 0x72E3DAA0AA188782ULL, 0x30133B4B03F2B111ULL,
0xF7021977F9CCEAA4ULL, 0xB5F2F89C5026DC37ULL, 0x3BD0BCE5A45A6B5DULL,
0x79205D0E0DB05DCEULL, 0xBE317F32F78E067BULL, 0xFCC19ED95E6430E8ULL,
0x86B86ED5267CDBD3ULL, 0xC4488F3E8F96ED40ULL, 0x0359AD0275A8B6F5ULL,
0x41A94CE9DC428066ULL, 0xCF8B0890283E370CULL, 0x8D7BE97B81D4019FULL,
0x4A6ACB477BEA5A2AULL, 0x089A2AACD2006CB9ULL, 0x14DEA25F3AF9026DULL,
0x562E43B4931334FEULL, 0x913F6188692D6F4BULL, 0xD3CF8063C0C759D8ULL,
0x5DEDC41A34BBEEB2ULL, 0x1F1D25F19D51D821ULL, 0xD80C07CD676F8394ULL,
0x9AFCE626CE85B507ULL
};
static u64 bch_crc64_update(u64 crc, const void *_data, size_t len)
{
const unsigned char *data = _data;
while (len--) {
int i = ((int) (crc >> 56) ^ *data++) & 0xFF;
crc = crc_table[i] ^ (crc << 8);
}
return crc;
}
static u64 bch_checksum_update(unsigned type, u64 crc, const void *data, size_t len)
{
switch (type) {
case BCH_CSUM_NONE:
return 0;
case BCH_CSUM_CRC32C:
return crc32c(crc, data, len);
case BCH_CSUM_CRC64:
return bch_crc64_update(crc, data, len);
default:
die("Unknown checksum type %u", type);
}
}
u64 bch_checksum(unsigned type, const void *data, size_t len)
{
u64 crc = 0xffffffffffffffffULL;
crc = bch_checksum_update(type, crc, data, len);
return crc ^ 0xffffffffffffffffULL;
}
/* Global control device: */
int bcachectl_open(void)
{
int fd = open("/dev/bcache-ctl", O_RDWR);
if (fd < 0)
die("Can't open bcache device: %s", strerror(errno));
return fd;
}
/* Filesystem handles (ioctl, sysfs dir): */
#define SYSFS_BASE "/sys/fs/bcache/"
struct bcache_handle bcache_fs_open(const char *path)
{
struct bcache_handle ret;
uuid_t tmp;
if (!uuid_parse(path, tmp)) {
/* It's a UUID, look it up in sysfs: */
char *sysfs = alloca(strlen(SYSFS_BASE) + strlen(path) + 1);
sprintf(sysfs, "%s%s", SYSFS_BASE, path);
ret.sysfs = opendir(sysfs);
if (!ret.sysfs)
die("Unable to open %s\n", path);
char *minor = read_file_str(dirfd(ret.sysfs), "minor");
char *ctl = alloca(20 + strlen(minor));
sprintf(ctl, "/dev/bcache%s-ctl", minor);
free(minor);
ret.fd = open(ctl, O_RDWR);
if (ret.fd < 0)
die("Error opening control device: %s\n",
strerror(errno));
} else {
/* It's a path: */
ret.fd = open(path, O_RDONLY);
if (ret.fd < 0)
die("Error opening %s: %s\n",
path, strerror(errno));
struct bch_ioctl_query_uuid uuid;
if (ioctl(ret.fd, BCH_IOCTL_QUERY_UUID, &uuid))
die("ioctl error (not a bcache fs?): %s\n",
strerror(errno));
char uuid_str[40];
uuid_unparse(uuid.uuid.b, uuid_str);
char *sysfs = alloca(strlen(SYSFS_BASE) + strlen(uuid_str) + 1);
sprintf(sysfs, "%s%s", SYSFS_BASE, uuid_str);
ret.sysfs = opendir(sysfs);
if (!ret.sysfs)
die("Unable to open sysfs dir %s: %s\n",
sysfs, strerror(errno));
}
return ret;
}

94
util.h Normal file
View File

@ -0,0 +1,94 @@
#ifndef _UTIL_H
#define _UTIL_H
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
/* linux kernel style types: */
#include <asm/types.h>
typedef __u8 u8;
typedef __u16 u16;
typedef __u32 u32;
typedef __u64 u64;
typedef __s8 s8;
typedef __s16 s16;
typedef __s32 s32;
typedef __s64 s64;
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#define die(arg, ...) \
do { \
fprintf(stderr, arg "\n", ##__VA_ARGS__); \
exit(EXIT_FAILURE); \
} while (0)
u64 rounddown_pow_of_two(u64);
unsigned ilog2(u64);
char *skip_spaces(const char *str);
char *strim(char *s);
long strtoul_or_die(const char *, size_t, const char *);
u64 hatoi(const char *);
unsigned hatoi_validate(const char *, const char *);
unsigned nr_args(char * const *);
char *read_file_str(int, const char *);
u64 read_file_u64(int, const char *);
ssize_t read_string_list(const char *, const char * const[]);
ssize_t read_string_list_or_die(const char *, const char * const[],
const char *);
void print_string_list(const char * const[], size_t);
u64 get_size(const char *, int);
unsigned get_blocksize(const char *, int);
int dev_open(const char *);
#include "bcache-ondisk.h"
#include "bcache-ioctl.h"
u64 bch_checksum(unsigned, const void *, size_t);
#define __bkey_idx(_set, _offset) \
((_set)->_data + (_offset))
#define __bset_bkey_last(_set) \
__bkey_idx((_set), (_set)->u64s)
#define csum_set(i, type) \
({ \
void *start = ((void *) (i)) + sizeof(uint64_t); \
void *end = __bset_bkey_last(i); \
\
bch_checksum(type, start, end - start); \
})
int bcachectl_open(void);
#include <dirent.h>
struct bcache_handle {
DIR *sysfs;
int fd;
};
struct bcache_handle bcache_fs_open(const char *);
#endif /* _UTIL_H */