]> git.ozlabs.org Git - ccan/commitdiff
compiler, list, noerr, sparse_bsearch, str, str_talloc, stringmap, talloc_link, tdb...
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Oct 2010 03:29:42 +0000 (13:59 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Oct 2010 03:29:42 +0000 (13:59 +1030)
Phew, now they call compile!

12 files changed:
ccan/compiler/compiler.h
ccan/list/list.h
ccan/noerr/_info
ccan/sparse_bsearch/_info
ccan/sparse_bsearch/sparse_bsearch.h
ccan/str/str.h
ccan/str_talloc/str_talloc.h
ccan/stringmap/_info
ccan/talloc_link/_info
ccan/tdb/_info
ccan/tdb2/_info
ccan/typesafe_cb/_info

index 7adcc8ca1a4ea521cb11069d3dce4dff062ecb14..49088ac799e6f0ba9772afde55d8a9fdd421f71d 100644 (file)
  *
  * Example:
  * // buf param may be freed by this; need return value!
- * static char *WARN_UNUSED_RESULT enlarge(const char *buf, unsigned *size)
+ * static char *WARN_UNUSED_RESULT enlarge(char *buf, unsigned *size)
  * {
  *     return realloc(buf, (*size) *= 2);
  * }
index d47e13253b56596d83fac64cf7fef1b907b9dc40..9cb41abd8a339ba3880b5997390c4908aafe9020 100644 (file)
@@ -56,7 +56,7 @@ struct list_head
  *     {
  *             struct child *c;
  *
- *             printf("%s (%u children):\n", p->name, parent->num_children);
+ *             printf("%s (%u children):\n", p->name, p->num_children);
  *             list_check(&p->children, "bad child list");
  *             list_for_each(&p->children, c, list)
  *                     printf(" -> %s\n", c->name);
@@ -70,11 +70,27 @@ struct list_head *list_check(const struct list_head *h, const char *abortstr);
 #define debug_list(h) (h)
 #endif
 
+/**
+ * LIST_HEAD - define and initalize an empty list_head
+ * @name: the name of the list.
+ *
+ * The LIST_HEAD macro defines a list_head and initializes it to an empty
+ * list.  It can be prepended by "static" to define a static list_head.
+ *
+ * Example:
+ *     static LIST_HEAD(my_global_list);
+ */
+#define LIST_HEAD(name) \
+       struct list_head name = { { &name.n, &name.n } }
+
 /**
  * list_head_init - initialize a list_head
  * @h: the list_head to set to the empty list
  *
  * Example:
+ *     ...
+ *     struct parent *parent = malloc(sizeof(*parent));
+ *
  *     list_head_init(&parent->children);
  *     parent->num_children = 0;
  */
@@ -83,23 +99,6 @@ static inline void list_head_init(struct list_head *h)
        h->n.next = h->n.prev = &h->n;
 }
 
-/**
- * LIST_HEAD - define and initalized empty list_head
- * @name: the name of the list.
- *
- * The LIST_HEAD macro defines a list_head and initializes it to an empty
- * list.  It can be prepended by "static" to define a static list_head.
- *
- * Example:
- *     // Header:
- *     extern struct list_head my_list;
- *
- *     // C file:
- *     LIST_HEAD(my_list);
- */
-#define LIST_HEAD(name) \
-       struct list_head name = { { &name.n, &name.n } }
-
 /**
  * list_add - add an entry at the start of a linked list.
  * @h: the list_head to add the node to
@@ -107,6 +106,8 @@ static inline void list_head_init(struct list_head *h)
  *
  * The list_node does not need to be initialized; it will be overwritten.
  * Example:
+ *     struct child *child;
+ *
  *     list_add(&parent->children, &child->list);
  *     parent->num_children++;
  */
@@ -179,9 +180,11 @@ static inline bool list_empty(const struct list_head *h)
  * @member: the list_node member of the type
  *
  * Example:
- *     struct child *c;
  *     // First list entry is children.next; convert back to child.
- *     c = list_entry(parent->children.next, struct child, list);
+ *     child = list_entry(parent->children.n.next, struct child, list);
+ *
+ * See Also:
+ *     list_top(), list_for_each()
  */
 #define list_entry(n, type, member) container_of(n, type, member)
 
@@ -225,9 +228,8 @@ static inline bool list_empty(const struct list_head *h)
  * a for loop, so you can break and continue as normal.
  *
  * Example:
- *     struct child *c;
- *     list_for_each(&parent->children, c, list)
- *             printf("Name: %s\n", c->name);
+ *     list_for_each(&parent->children, child, list)
+ *             printf("Name: %s\n", child->name);
  */
 #define list_for_each(h, i, member)                                    \
        for (i = container_of_var(debug_list(h)->n.next, i, member);    \
@@ -246,9 +248,9 @@ static inline bool list_empty(const struct list_head *h)
  * @nxt is used to hold the next element, so you can delete @i from the list.
  *
  * Example:
- *     struct child *c, *n;
- *     list_for_each_safe(&parent->children, c, n, list) {
- *             list_del(&c->list);
+ *     struct child *next;
+ *     list_for_each_safe(&parent->children, child, next, list) {
+ *             list_del(&child->list);
  *             parent->num_children--;
  *     }
  */
index 9f852957b5f344cd411d31837a2ebe67931c137e..c5d8768f61e666154947df29d9b2344ba842f5b8 100644 (file)
@@ -19,7 +19,7 @@
  *     #include <errno.h>
  *     #include <ccan/noerr/noerr.h>
  *
- *     bool write_string_to_file(const char *file, const char *string)
+ *     static bool write_string_to_file(const char *file, const char *string)
  *     {
  *             int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
  *             if (fd < 0)
index 7d7164f04dff4a22bf9fbae2f94f5365ab4733ca..b0bcb2f075edbf875f05e1a92a3986aa6c2f3ab0 100644 (file)
@@ -26,7 +26,7 @@
  *     static unsigned int values[] = { 1, 7, 11, 1235, 99999 };
  *
  *     // Return true if this value is in set, and remove it.
- *     bool remove_from_values(unsigned int val)
+ *     static bool remove_from_values(unsigned int val)
  *     {
  *             unsigned int *p;
  *             // We use 5 here, but ccan/array_size.h is better!
index 5317dbf849841a2a05a35f9c0a1ccb1edf3a8c9e..731f9a4f05f9ec199d6f5cacbf8f4adbcd46544a 100644 (file)
@@ -27,7 +27,7 @@
  *     static unsigned int values[] = { 1, 7, 11, 1235, 99999 };
  *
  *     // Return true if this value is in set, and remove it.
- *     bool remove_from_values(unsigned int val)
+ *     static bool remove_from_values(unsigned int val)
  *     {
  *             unsigned int *p;
  *             p = sparse_bsearch(&val, values, 5, val_cmp, val_valid);
index 70fe26c74fad3905b3acf2efd8ac0b792ba766a5..8cfd7f29a5626cb7ca3a3196e545f35c3a74c0be 100644 (file)
@@ -11,7 +11,7 @@
  * This macro is arguably more readable than "!strcmp(a, b)".
  *
  * Example:
- *     if (streq(str, ""))
+ *     if (streq(somestring, ""))
  *             printf("String is empty!\n");
  */
 #define streq(a,b) (strcmp((a),(b)) == 0)
@@ -22,8 +22,8 @@
  * @prefix: prefix to look for at start of str
  *
  * Example:
- *     if (strstarts(str, "foo"))
- *             printf("String %s begins with 'foo'!\n", str);
+ *     if (strstarts(somestring, "foo"))
+ *             printf("String %s begins with 'foo'!\n", somestring);
  */
 #define strstarts(str,prefix) (strncmp((str),(prefix),strlen(prefix)) == 0)
 
@@ -33,8 +33,8 @@
  * @postfix: postfix to look for at end of str
  *
  * Example:
- *     if (strends(str, "foo"))
- *             printf("String %s end with 'foo'!\n", str);
+ *     if (strends(somestring, "foo"))
+ *             printf("String %s end with 'foo'!\n", somestring);
  */
 static inline bool strends(const char *str, const char *postfix)
 {
index 9828cd85d00aa2fc27f695786bfe03cfdabeb02a..50cea2dcb3b4ce6db7d3bcd968b41215a1a475e6 100644 (file)
  * @nump to find the array length.
  *
  * Example:
- *     unsigned int count_long_lines(const char *text)
+ *     #include <ccan/talloc/talloc.h>
+ *     #include <ccan/str_talloc/str_talloc.h>
+ *     ...
+ *     static unsigned int count_long_lines(const char *string)
  *     {
  *             char **lines;
  *             unsigned int i, long_lines = 0;
@@ -49,10 +52,9 @@ char **strsplit(const void *ctx, const char *string, const char *delims,
  *
  * Example:
  *     // Append the string "--EOL" to each line.
- *     char *append_to_all_lines(const char *string)
+ *     static char *append_to_all_lines(const char *string)
  *     {
  *             char **lines, *ret;
- *             unsigned int i, num, newnum;
  *
  *             lines = strsplit(NULL, string, "\n", NULL);
  *             ret = strjoin(NULL, lines, "-- EOL\n");
index 5ad40cac2d5d9847f3adb961f0491da592b2dccb..b5e78755e12cf6daf25bbe4ea4483e0106f24c93 100644 (file)
  *
  * Example:
  *
- * #include <ccan/stringmap/stringmap.h>                                                                                                                                        
+ * #include <ccan/stringmap/stringmap.h>
  *
- * static const char *get_string(void) {                                                                                                                                        
- *      static char buffer[4096];                                                                                                                                               
- *      char *tail;                                                                                                                                                             
- *      if (!fgets(buffer, sizeof(buffer), stdin))                                                                                                                              
- *              return NULL;                                                                                                                                                    
- *      tail = strchr(buffer, 0);                                                                                                                                               
- *      if (tail>buffer && tail[-1]=='\n')                                                                                                                                      
- *              *--tail = 0;                                                                                                                                                    
- *      if (!*buffer)                                                                                                                                                           
- *              return NULL;                                                                                                                                                    
- *      return buffer;                                                                                                                                                          
- * }                                                                                                                                                                            
+ * static const char *get_string(void) {
+ *      static char buffer[4096];
+ *      char *tail;
+ *      if (!fgets(buffer, sizeof(buffer), stdin))
+ *              return NULL;
+ *      tail = strchr(buffer, 0);
+ *      if (tail>buffer && tail[-1]=='\n')
+ *              *--tail = 0;
+ *      if (!*buffer)
+ *              return NULL;
+ *      return buffer;
+ * }
  *
- * int main(void) {                                                                                                                                                             
+ * int main(void) {
  *      stringmap(int) map = stringmap_new(NULL);
  *      const char *string;
  *
@@ -49,8 +49,8 @@
  *    return 0;
  * }
  *
- *     Authors: Joey Adams, Anders Magnusson
- *     License: BSD
+ * Authors: Joey Adams, Anders Magnusson
+ * License: BSD
  */
 int main(int argc, char *argv[])
 {
index 8758e07342b2c73296122587a6223701f484a970..dd25c201bc9c080b609cee168c89f808c55f9875 100644 (file)
@@ -29,7 +29,7 @@
  *     static struct upcache *cache;
  *     static unsigned int cache_hits = 0;
  *     #define CACHE_SIZE 4
- *     void init_upcase(void)
+ *     static void init_upcase(void)
  *     {
  *             cache = talloc_zero_array(NULL, struct upcache, CACHE_SIZE);
  *     }
@@ -70,7 +70,7 @@
  *     }
  *
  *     // If you want to keep the result, talloc_link it.
- *     const char *get_upcase(const char *str)
+ *     static const char *get_upcase(const char *str)
  *     {
  *             struct upcache *uc = lookup_upcase(str);
  *             if (!uc)
@@ -80,7 +80,7 @@
  *             return uc->upstr;
  *     }
  *
- *     void exit_upcase(void)
+ *     static void exit_upcase(void)
  *     {
  *             talloc_free(cache);
  *             printf("Cache hits: %u\n", cache_hits);
index 8c1e5dc47459dcc2aa0093168ee849d5b1befbbf..10d02b9657ad90bc16a7da0957c48367ee66c441 100644 (file)
  *     #include <err.h>
  *     #include <stdio.h>
  *     
- *     static void usage(void)
+ *     static void usage(const char *argv0)
  *     {
  *             errx(1, "Usage: %s fetch <dbfile> <key>\n"
- *                  "OR %s store <dbfile> <key> <data>");
+ *                  "OR %s store <dbfile> <key> <data>", argv0, argv0);
  *     }
  *     
  *     int main(int argc, char *argv[])
@@ -26,7 +26,7 @@
  *             TDB_DATA key, value;
  *     
  *             if (argc < 4)
- *                     usage();
+ *                     usage(argv[0]);
  *     
  *             tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
  *                             0600);
@@ -38,7 +38,7 @@
  *     
  *             if (streq(argv[1], "fetch")) {
  *                     if (argc != 4)
- *                             usage();
+ *                             usage(argv[0]);
  *                     value = tdb_fetch(tdb, key);
  *                     if (!value.dptr)
  *                             errx(1, "fetch %s: %s",
  *                     free(value.dptr);
  *             } else if (streq(argv[1], "store")) {
  *                     if (argc != 5)
- *                             usage();
+ *                             usage(argv[0]);
  *                     value.dptr = (void *)argv[4];
  *                     value.dsize = strlen(argv[4]);
  *                     if (tdb_store(tdb, key, value, 0) != 0)
  *                             errx(1, "store %s: %s",
  *                                  argv[3], tdb_errorstr(tdb));
  *             } else
- *                     usage();
+ *                     usage(argv[0]);
  *     
  *             return 0;
  *     }
index 66d3cb8bacf139100e5ef2b40b37ca094fa22161..35e32b729116cfd199ae3d87c83ab947bd5f931e 100644 (file)
  *     #include <err.h>
  *     #include <stdio.h>
  *     
- *     static void usage(void)
+ *     static void usage(const char *argv0)
  *     {
  *             errx(1, "Usage: %s fetch <dbfile> <key>\n"
- *                  "OR %s store <dbfile> <key> <data>");
+ *                  "OR %s store <dbfile> <key> <data>", argv0, argv0);
  *     }
  *     
  *     int main(int argc, char *argv[])
  *             TDB_DATA key, value;
  *     
  *             if (argc < 4)
- *                     usage();
+ *                     usage(argv[0]);
  *     
- *             tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
- *                             0600);
+ *             tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
  *             if (!tdb)
  *                     err(1, "Opening %s", argv[2]);
  *     
@@ -38,7 +37,7 @@
  *     
  *             if (streq(argv[1], "fetch")) {
  *                     if (argc != 4)
- *                             usage();
+ *                             usage(argv[0]);
  *                     value = tdb_fetch(tdb, key);
  *                     if (!value.dptr)
  *                             errx(1, "fetch %s: %s",
  *                     free(value.dptr);
  *             } else if (streq(argv[1], "store")) {
  *                     if (argc != 5)
- *                             usage();
+ *                             usage(argv[0]);
  *                     value.dptr = (void *)argv[4];
  *                     value.dsize = strlen(argv[4]);
  *                     if (tdb_store(tdb, key, value, 0) != 0)
  *                             errx(1, "store %s: %s",
  *                                  argv[3], tdb_errorstr(tdb));
  *             } else
- *                     usage();
+ *                     usage(argv[0]);
  *     
  *             return 0;
  *     }
index 2d8f68483a5b333ac086fa6d87a42e4debe0c57c..fea27116263c1a6ba52fbc5175a4c65c56772777 100644 (file)
@@ -87,7 +87,7 @@
  *
  *     // Define several silly callbacks.  Note they don't use void *!
  *     #define DEF_CALLBACK(name, op)                  \
- *             static int name(int val, const int *arg)\
+ *             static int name(int val, int *arg)      \
  *             {                                       \
  *                     printf("%s", #op);              \
  *                     return val op *arg;             \