This is everything up to the list module... now it's time for sleep.
21 files changed:
* // We currently use 32 random values.
* static unsigned int vals[32];
*
* // We currently use 32 random values.
* static unsigned int vals[32];
*
- * void init_values(void)
+ * static void init_values(void)
* {
* unsigned int i;
* for (i = 0; i < ARRAY_SIZE(vals); i++)
* {
* unsigned int i;
* for (i = 0; i < ARRAY_SIZE(vals); i++)
* #include <stdio.h>
* #include <string.h>
*
* #include <stdio.h>
* #include <string.h>
*
- * static int cmp(const char **a, const char **n, bool *casefold)
+ * static int cmp(char *const *a, char *const *n, bool *casefold)
- * return strcasecmp(*a, *b);
+ * return strcasecmp(*a, *n);
- * return strcmp(*a, *b);
+ * return strcmp(*a, *n);
* }
*
* int main(int argc, char *argv[])
* }
*
* int main(int argc, char *argv[])
* int array[] = {0,1,1,2,3,5,8,13,21,34};
* int *array_copy = block_pool_memdup(bp, array, sizeof(array));
*
* int array[] = {0,1,1,2,3,5,8,13,21,34};
* int *array_copy = block_pool_memdup(bp, array, sizeof(array));
*
+ * memset(buffer, 0xff, 4096);
+ * printf("string = %s\n", string);
+ * printf("array_copy[0] == %i\n", array_copy[0]);
* block_pool_free(bp);
* return 0;
* }
*
* block_pool_free(bp);
* return 0;
* }
*
- * Author: Joey Adams
- * License: BSD
+ * Author: Joey Adams
+ * License: BSD
*/
int main(int argc, char *argv[])
{
*/
int main(int argc, char *argv[])
{
* };
*
* //Define the ordering function order_by_letter_set
* };
*
* //Define the ordering function order_by_letter_set
- * btree_search_implement
+ * static btree_search_implement
* (
* order_by_letter_set,
* struct word *,
* (
* order_by_letter_set,
* struct word *,
* char *chomp(char *str);
* char *make_letter_set(char *str);
*
* char *chomp(char *str);
* char *make_letter_set(char *str);
*
- * void insert_word(struct btree *btree, struct word *word)
+ * static void insert_word(struct btree *btree, struct word *word)
* {
* btree_iterator iter;
*
* {
* btree_iterator iter;
*
* btree_insert_at(iter, word);
* }
*
* btree_insert_at(iter, word);
* }
*
- * void print_anagrams(struct btree *btree, char *line)
+ * static void print_anagrams(struct btree *btree, char *line)
* {
* btree_iterator iter, end;
* struct word key = {
* {
* btree_iterator iter, end;
* struct word key = {
- * int destroy_word(struct word *word, void *ctx)
+ * static int destroy_word(struct word *word, void *ctx)
- * struct btree *read_dictionary(const char *filename)
+ * static struct btree *read_dictionary(const char *filename)
* {
* FILE *f;
* char line[256];
* {
* FILE *f;
* char line[256];
* btree_delete(btree);
* fprintf(stderr, "%s: %s\n", filename, strerror(errno));
* return NULL;
* btree_delete(btree);
* fprintf(stderr, "%s: %s\n", filename, strerror(errno));
* return NULL;
- * char *foo_string(struct foo *foo)
+ * 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);
* {
* // This trick requires that the string be first in the structure
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
* by the compiler. This can only be used within a function.
*
* Example:
* by the compiler. This can only be used within a function.
*
* Example:
- * char *foo_to_char(struct foo *foo)
+ * #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);
* {
* // This code needs string to be at start of foo.
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
* #include <ccan/grab_file/grab_file.h>
* #include <err.h>
*
* #include <ccan/grab_file/grab_file.h>
* #include <err.h>
*
- * void token_list_stats(const struct token_list *tl) {
+ * static void token_list_stats(const struct token_list *tl) {
* size_t comment=0, white=0, stray=0, code=0, total=0;
* size_t count = 0;
* const struct token *i;
* size_t comment=0, white=0, stray=0, code=0, total=0;
* size_t count = 0;
* const struct token *i;
* if (!file)
* err(1, "Could not read file %s", argv[1]);
*
* if (!file)
* err(1, "Could not read file %s", argv[1]);
*
- * valid = utf8_validate(file, len));
+ * valid = utf8_validate(file, len);
* printf("File contents are %s UTF-8\n", valid ? "valid" : "invalid");
*
* talloc_free(file);
* printf("File contents are %s UTF-8\n", valid ? "valid" : "invalid");
*
* talloc_free(file);
* compiler - macros for common compiler extensions
*
* Abstracts away some compiler hints. Currently these include:
* compiler - macros for common compiler extensions
*
* Abstracts away some compiler hints. Currently these include:
- * - UNLIKELY_FUNCTION_ATTRIBUTE
* For functions not called in fast paths (aka. cold functions)
* - PRINTF_ATTRIBUTE
* For functions which take printf-style parameters.
* For functions not called in fast paths (aka. cold functions)
* - PRINTF_ATTRIBUTE
* For functions which take printf-style parameters.
* Author: Rusty Russell <rusty@rustcorp.com.au>
*
* Example:
* Author: Rusty Russell <rusty@rustcorp.com.au>
*
* Example:
- * #include <ccan/compiler/attributs.h>
+ * #include <ccan/compiler/compiler.h>
* #include <stdio.h>
* #include <stdarg.h>
*
* // Example of a (slow-path) logging function.
* static int log_threshold = 2;
* #include <stdio.h>
* #include <stdarg.h>
*
* // Example of a (slow-path) logging function.
* static int log_threshold = 2;
- * static void UNLIKELY_FUNCTION_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
+ * static void COLD_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
* logger(int level, const char *fmt, ...)
* {
* va_list ap;
* logger(int level, const char *fmt, ...)
* {
* va_list ap;
* It is usually used on logging or error routines.
*
* Example:
* It is usually used on logging or error routines.
*
* Example:
- * void COLD_ATTRIBUTE moan(const char *reason)
- * {
- * fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
- * }
+ * static void COLD_ATTRIBUTE moan(const char *reason)
+ * {
+ * fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
+ * }
*/
#define COLD_ATTRIBUTE __attribute__((cold))
#else
*/
#define COLD_ATTRIBUTE __attribute__((cold))
#else
#if HAVE_ATTRIBUTE_PRINTF
/**
* PRINTF_ATTRIBUTE - a function takes printf-style arguments
#if HAVE_ATTRIBUTE_PRINTF
/**
* PRINTF_ATTRIBUTE - 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.
+ * @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:
*
* This allows the compiler to check your parameters as it does for printf().
*
* Example:
- * void PRINTF_ATTRIBUTE(2,3) my_printf(char *prefix, char *format, ...);
+ * void PRINTF_ATTRIBUTE(2,3) my_printf(const char *prefix,
+ * const char *fmt, ...);
*/
#define PRINTF_ATTRIBUTE(nfmt, narg) \
__attribute__((format(__printf__, nfmt, narg)))
*/
#define PRINTF_ATTRIBUTE(nfmt, narg) \
__attribute__((format(__printf__, nfmt, narg)))
* the compiler that if it is unused it need not emit it into the source code.
*
* Example:
* the compiler that if it is unused it need not emit it into the source code.
*
* Example:
- * // With some config options, this is unnecessary.
- * static UNNEEDED_ATTRIBUTE int counter;
- * ...
- * #ifdef DEBUG
- * counter++;
- * #endif
- * ...
- * // With some config options, this is unnecessary.
- * static UNNEEDED_ATTRIBUTE int add_to_counter(int add)
- * {
- * counter += add;
- * }
+ * // With some preprocessor options, this is unnecessary.
+ * static UNNEEDED_ATTRIBUTE int counter;
+ *
+ * // With some preprocessor options, this is unnecessary.
+ * static UNNEEDED_ATTRIBUTE void add_to_counter(int add)
+ * {
+ * counter += add;
+ * }
*/
#define UNNEEDED_ATTRIBUTE __attribute__((unused))
*/
#define UNNEEDED_ATTRIBUTE __attribute__((unused))
* const char *greek_name(enum greek greek);
*
* // Inline version.
* const char *greek_name(enum greek greek);
*
* // Inline version.
- * static inline _greek_name(enum greek greek)
+ * static inline char *_greek_name(enum greek greek)
* {
* switch (greek) {
* case ALPHA: return "alpha";
* {
* switch (greek) {
* case ALPHA: return "alpha";
* struct timer timer;
* };
*
* struct timer timer;
* };
*
+ * static void register_timer(struct timer *timer)
+ * {
+ * //...
+ * }
+ *
* static void my_timer_callback(struct timer *timer)
* {
* struct info *info = container_of(timer, struct info, timer);
* printf("my_stuff is %u\n", info->my_stuff);
* }
*
* static void my_timer_callback(struct timer *timer)
* {
* struct info *info = container_of(timer, struct info, timer);
* printf("my_stuff is %u\n", info->my_stuff);
* }
*
* {
* struct info info = { .my_stuff = 1 };
*
* {
* struct info info = { .my_stuff = 1 };
*
* subtraction to return the pointer to the enclosing type.
*
* Example:
* subtraction to return the pointer to the enclosing type.
*
* Example:
+ * struct foo {
+ * int fielda, fieldb;
+ * // ...
+ * };
+ * struct info {
* int some_other_field;
* struct foo my_foo;
* };
*
* int some_other_field;
* struct foo my_foo;
* };
*
- * struct info *foo_to_info(struct foo *foop)
+ * static struct info *foo_to_info(struct foo *foo)
* {
* return container_of(foo, struct info, my_foo);
* }
* {
* return container_of(foo, struct info, my_foo);
* }
* subtraction to return the pointer to the enclosing type.
*
* Example:
* subtraction to return the pointer to the enclosing type.
*
* Example:
- * struct info
- * {
- * int some_other_field;
- * struct foo my_foo;
- * };
- *
- * struct info *foo_to_info(struct foo *foop)
+ * static struct info *foo_to_i(struct foo *foo)
* {
* struct info *i = container_of_var(foo, i, my_foo);
* return i;
* {
* struct info *i = container_of_var(foo, i, my_foo);
* return i;
* detect a single error burst of up to 32 bits.
*
* Example:
* detect a single error burst of up to 32 bits.
*
* Example:
- * #include <ccan/crc.h>
+ * #include <ccan/crc/crc.h>
* #include <stdio.h>
* #include <stdlib.h>
*
* #include <stdio.h>
* #include <stdlib.h>
*
* "Prints 32 bit CRC of the string\n", argv[0]);
* exit(1);
* }
* "Prints 32 bit CRC of the string\n", argv[0]);
* exit(1);
* }
- * printf("0x%08x\n", crc32c(argv[1], strlen(argv[1])));
+ * printf("0x%08x\n", crc32c(0, argv[1], strlen(argv[1])));
* as 0 the first time, and the current crc result from then on.
*
* Example:
* 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)
* // Check that iovec has the crc we expect (Castagnoli version)
- * bool check_crc(uint32_t expected, const struct iovec *iov, int iovcnt)
+ * static bool check_crc(uint32_t expected, const struct iovec *iov, int l)
- * while (iovcnt >= 0) {
* crc = crc32c(crc, iov->iov_base, iov->iov_len);
* iov++;
* }
* crc = crc32c(crc, iov->iov_base, iov->iov_len);
* iov++;
* }
*
* Example:
* // This dumb code only handles Castagnoli, so assert that here.
*
* Example:
* // This dumb code only handles Castagnoli, so assert that here.
- * void check_user_crc_table(const uint32_t *usertab)
+ * static void check_user_crc_table(const uint32_t *usertab)
* {
* const uint32_t *ctab = crc32c_table();
* if (!ctab || memcmp(ctab, usertab, 1024) != 0)
* {
* const uint32_t *ctab = crc32c_table();
* if (!ctab || memcmp(ctab, usertab, 1024) != 0)
* size_t len, used, blocksize;
* char *file;
* struct crc_context *ctx;
* size_t len, used, blocksize;
* char *file;
* struct crc_context *ctx;
* long res, i;
*
* if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
* long res, i;
*
* if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
* if (argc == 3) {
* // Short form prints CRCs of file for use in long form.
* used = (len + blocksize - 1) / blocksize;
* if (argc == 3) {
* // Short form prints CRCs of file for use in long form.
* used = (len + blocksize - 1) / blocksize;
- * crcs = malloc(used * sizeof(uint32_t));
+ * crcs = malloc(used * sizeof(crcs[0]));
* crc_of_blocks(file, len, blocksize, 32, crcs);
* for (i = 0; i < used; i++)
* crc_of_blocks(file, len, blocksize, 32, crcs);
* for (i = 0; i < used; i++)
- * printf("%i ", crcs[i]);
+ * printf("%llu ", (long long)crcs[i]);
* printf("\n");
* return 0;
* }
* printf("\n");
* return 0;
* }
* for (i = 0; i < argc-3; i++)
* crcs[i] = atoi(argv[3+i]);
*
* for (i = 0; i < argc-3; i++)
* crcs[i] = atoi(argv[3+i]);
*
- * ctx = crc_context_new(blocksize, 32, crcs, argc-3);
+ * ctx = crc_context_new(blocksize, 32, crcs, argc-3, 0);
* for (used = 0; used < len; ) {
* used += crc_read_block(ctx, &res, file+used, len-used);
* print_result(res);
* for (used = 0; used < len; ) {
* used += crc_read_block(ctx, &res, file+used, len-used);
* print_result(res);
* if (argc != 2)
* errx(1, "Usage: %s <value>", argv[0]);
*
* if (argc != 2)
* errx(1, "Usage: %s <value>", argv[0]);
*
+ * value = atoi(argv[1]);
* printf("native: %08x\n", value);
* printf("little-endian: %08x\n", cpu_to_le32(value));
* printf("big-endian: %08x\n", cpu_to_be32(value));
* printf("native: %08x\n", value);
* printf("little-endian: %08x\n", cpu_to_le32(value));
* printf("big-endian: %08x\n", cpu_to_be32(value));
* byte after the end of the content will always be NUL.
*
* Example:
* byte after the end of the content will always be NUL.
*
* Example:
+ * #include <ccan/str_talloc/str_talloc.h>
+ * #include <ccan/talloc/talloc.h>
+ * ...
* // Return all of standard input, as lines.
* // Return all of standard input, as lines.
- * char **read_as_lines(void)
+ * static char **read_stdin_as_lines(void)
* {
* char **lines, *all;
*
* {
* char **lines, *all;
*
*
* Example:
* // Return all of a given file, as lines.
*
* Example:
* // Return all of a given file, as lines.
- * char **read_as_lines(const char *filename)
+ * static char **read_file_as_lines(const char *filename)
* {
* char **lines, *all;
*
* {
* char **lines, *all;
*
* argv[i], idtree_add(idtree, argv[i], -1));
* }
* for (i = 0; i < argc; i++) {
* argv[i], idtree_add(idtree, argv[i], -1));
* }
* for (i = 0; i < argc; i++) {
- * printf("id %i -> '%s'\n", i, idtree_lookup(idtree, i));
+ * printf("id %i -> '%s'\n",
+ * i, (char *)idtree_lookup(idtree, i));
* Allocate an empty id tree. You can free it with talloc_free().
*
* Example:
* Allocate an empty id tree. You can free it with talloc_free().
*
* Example:
* static struct idtree *ids;
*
* static struct idtree *ids;
*
+ * static void init(void)
+ * {
* ids = idtree_new(NULL);
* if (!ids)
* err(1, "Failed to allocate idtree");
* ids = idtree_new(NULL);
* if (!ids)
* err(1, "Failed to allocate idtree");
*/
struct idtree *idtree_new(void *mem_ctx);
*/
struct idtree *idtree_new(void *mem_ctx);
* Example:
* struct foo {
* unsigned int id;
* Example:
* struct foo {
* unsigned int id;
* };
*
* // Create a new foo, assigning an id.
* };
*
* // Create a new foo, assigning an id.
- * struct foo *new_foo(void)
+ * static struct foo *new_foo(void)
- * foo = malloc(sizeof(*foo));
+ * struct foo *foo = malloc(sizeof(*foo));
* if (!foo)
* return NULL;
*
* if (!foo)
* return NULL;
*
*
* Example:
* static int last_id = -1;
*
* Example:
* static int last_id = -1;
- * struct foo {
- * unsigned int id;
- * ...
- * };
*
* // Create a new foo, assigning a consecutive id.
* // This maximizes the time before ids roll.
*
* // Create a new foo, assigning a consecutive id.
* // This maximizes the time before ids roll.
- * struct foo *new_foo(void)
+ * static struct foo *new_foo_inc_id(void)
- * foo = malloc(sizeof(*foo));
+ * struct foo *foo = malloc(sizeof(*foo));
* if (!foo)
* return NULL;
*
* if (!foo)
* return NULL;
*
*
* Example:
* // Look up a foo for a given ID.
*
* Example:
* // Look up a foo for a given ID.
- * struct foo *find_foo(unsigned int id)
+ * static struct foo *find_foo(unsigned int id)
* {
* return idtree_lookup(ids, id);
* }
* {
* return idtree_lookup(ids, id);
* }
* Returns false if the id was not in the tree.
*
* Example:
* Returns false if the id was not in the tree.
*
* Example:
- * #include <assert.h>
- *
* // Look up a foo for a given ID.
* // Look up a foo for a given ID.
- * void *free_foo(struct foo *foo)
+ * static void free_foo(struct foo *foo)
* {
* bool exists = idtree_remove(ids, foo->id);
* assert(exists);
* {
* bool exists = idtree_remove(ids, foo->id);
* assert(exists);
* printf("ILOG_32(0x%08X)=%i\n",0,ILOG_32(0));
* for(i=1;i<=STATIC_ILOG_32(USHRT_MAX);i++){
* uint32_t v;
* printf("ILOG_32(0x%08X)=%i\n",0,ILOG_32(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 ILOGNZ_32().
* printf("ILOG_32(0x%08X)=%i\n",v,ILOGNZ_32(v));
* }
* //Here we know v is non-zero, so we can use ILOGNZ_32().
* printf("ILOG_32(0x%08X)=%i\n",v,ILOGNZ_32(v));
* }
* // Returns false if we overflow.
* static inline bool inc_int(unsigned int *val)
* {
* // Returns false if we overflow.
* static inline bool inc_int(unsigned int *val)
* {
* if (likely(*val))
* return true;
* return false;
* if (likely(*val))
* return true;
* return false;
* // Prints a warning if we overflow.
* static inline void inc_int(unsigned int *val)
* {
* // Prints a warning if we overflow.
* static inline void inc_int(unsigned int *val)
* {
* if (unlikely(*val == 0))
* fprintf(stderr, "Overflow!");
* }
* if (unlikely(*val == 0))
* fprintf(stderr, "Overflow!");
* }