]> git.ozlabs.org Git - ccan/commitdiff
cast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 4 Nov 2016 20:56:47 +0000 (07:26 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 4 Nov 2016 20:56:47 +0000 (07:26 +1030)
This avoids the warning about it being unused with -Wunused.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/cast/_info
ccan/str/_info
ccan/take/_info
ccan/tal/grab_file/_info
ccan/tal/str/_info
ccan/typesafe_cb/_info

index b09e0344e49d6ee570e9b70dbbe98e75393d8847..29128b8d5cf7cff915b07fa01783c2c44727073f 100644 (file)
@@ -24,6 +24,7 @@
  *     #include <ccan/cast/cast.h>
  *     #include <stdint.h>
  *     #include <stdio.h>
  *     #include <ccan/cast/cast.h>
  *     #include <stdint.h>
  *     #include <stdio.h>
+ *     #include <stdlib.h>
  *
  *     // Find char @orig in @str, if @repl, replace them.  Return number.
  *     static size_t find_chars(char *str, char orig, char repl)
  *
  *     // Find char @orig in @str, if @repl, replace them.  Return number.
  *     static size_t find_chars(char *str, char orig, char repl)
@@ -53,6 +54,9 @@
  *     {
  *             uint64_t hash;
  *
  *     {
  *             uint64_t hash;
  *
+ *             if (argc != 2) {
+ *                     fprintf(stderr, "Needs argument\n"); exit(1);
+ *             }
  *             // find_chars wants a non-const string, but doesn't
  *             // need it if repl == 0.
  *             printf("%zu %c's in 'test string'\n",
  *             // find_chars wants a non-const string, but doesn't
  *             // need it if repl == 0.
  *             printf("%zu %c's in 'test string'\n",
index 251d999a83f47328ead2ca8720d9859f59f43d03..b579525faac18e1fa52096b2e9b6eff34a70b404 100644 (file)
  *
  *     int main(int argc, char *argv[])
  *     {
  *
  *     int main(int argc, char *argv[])
  *     {
- *             if (argv[1] && streq(argv[1], "--verbose"))
+ *             if (argc > 1 && streq(argv[1], "--verbose"))
  *                     printf("verbose set\n");
  *                     printf("verbose set\n");
- *             if (argv[1] && strstarts(argv[1], "--"))
+ *             if (argc > 1 && strstarts(argv[1], "--"))
  *                     printf("Some option set\n");
  *                     printf("Some option set\n");
- *             if (argv[1] && strends(argv[1], "cow-powers"))
+ *             if (argc > 1 && strends(argv[1], "cow-powers"))
  *                     printf("Magic option set\n");
  *             return 0;
  *     }
  *                     printf("Magic option set\n");
  *             return 0;
  *     }
index 693824664802aebdeef970c4de29f23fb4fc0efb..fcb4f318a36ad77fdf1e7e8440de463b4f2d51cf 100644 (file)
@@ -37,7 +37,7 @@
  *     {
  *             char *b;
  *
  *     {
  *             char *b;
  *
- *             if (argv[1]) // Mangle in place.
+ *             if (argc > 1) // Mangle in place.
  *                     b = base(take(argv[1]));
  *             else
  *                     b = base("test/string");
  *                     b = base(take(argv[1]));
  *             else
  *                     b = base("test/string");
index 68ad089b06f23d59e4ef318f0f107c76a9e50e87..056f10990b08111ce1ebdc6c66541c445d87c7d0 100644 (file)
@@ -18,6 +18,8 @@
  *     {
  *             char *file;
  *
  *     {
  *             char *file;
  *
+ *             if (argc > 2)
+ *                     err(1, "Takes 0 or 1 arguments");
  *             file = grab_file(NULL, argv[1]);
  *             if (!file)
  *                     err(1, "Could not read file %s", argv[1]);
  *             file = grab_file(NULL, argv[1]);
  *             if (!file)
  *                     err(1, "Could not read file %s", argv[1]);
index cb81c9e19df33a64eb0e6323810d3d3129d9ff7e..3037cfde2fba99fcf1e817c0117ed8b89909fee3 100644 (file)
@@ -20,6 +20,8 @@
  *             char *textfile;
  *             char **lines;
  *
  *             char *textfile;
  *             char **lines;
  *
+ *             if (argc > 2)
+ *                     errx(1, "Takes 0 or 1 arguments");
  *             // Grab lines in file.
  *             textfile = grab_file(NULL, argv[1]);
  *             if (!textfile)
  *             // Grab lines in file.
  *             textfile = grab_file(NULL, argv[1]);
  *             if (!textfile)
index 165852a3be2a1a4dd7c884dfbe48084991292ae1..b4f379dd48b020c29bf8f27c8da88a37831e619a 100644 (file)
  *     // Silly game to find the longest chain of values.
  *     int main(int argc, char *argv[])
  *     {
  *     // Silly game to find the longest chain of values.
  *     int main(int argc, char *argv[])
  *     {
- *             int i, run = 1, num = argv[1] ? atoi(argv[1]) : 0;
+ *             int i, run = 1, num = argc > 1 ? atoi(argv[1]) : 0;
  *     
  *             for (i = 1; i < 1024;) {
  *                     // Since run is an int, compiler checks "add" does too.
  *     
  *             for (i = 1; i < 1024;) {
  *                     // Since run is an int, compiler checks "add" does too.