Commit 58774026 authored by Rusty Russell's avatar Rusty Russell

cast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc

This avoids the warning about it being unused with -Wunused.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent e7e57cbf
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* #include <ccan/cast/cast.h> * #include <ccan/cast/cast.h>
* #include <stdint.h> * #include <stdint.h>
* #include <stdio.h> * #include <stdio.h>
* #include <stdlib.h>
* *
* // Find char @orig in @str, if @repl, replace them. Return number. * // Find char @orig in @str, if @repl, replace them. Return number.
* static size_t find_chars(char *str, char orig, char repl) * static size_t find_chars(char *str, char orig, char repl)
...@@ -53,6 +54,9 @@ ...@@ -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 * // find_chars wants a non-const string, but doesn't
* // need it if repl == 0. * // need it if repl == 0.
* printf("%zu %c's in 'test string'\n", * printf("%zu %c's in 'test string'\n",
......
...@@ -26,11 +26,11 @@ ...@@ -26,11 +26,11 @@
* *
* 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"); * printf("Magic option set\n");
* return 0; * return 0;
* } * }
......
...@@ -37,7 +37,7 @@ ...@@ -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])); * b = base(take(argv[1]));
* else * else
* b = base("test/string"); * b = base("test/string");
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
* { * {
* char *file; * char *file;
* *
* if (argc > 2)
* err(1, "Takes 0 or 1 arguments");
* file = grab_file(NULL, argv[1]); * file = grab_file(NULL, argv[1]);
* if (!file) * if (!file)
* err(1, "Could not read file %s", argv[1]); * err(1, "Could not read file %s", argv[1]);
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
* char *textfile; * char *textfile;
* char **lines; * char **lines;
* *
* if (argc > 2)
* errx(1, "Takes 0 or 1 arguments");
* // Grab lines in file. * // Grab lines in file.
* textfile = grab_file(NULL, argv[1]); * textfile = grab_file(NULL, argv[1]);
* if (!textfile) * if (!textfile)
......
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
* // Silly game to find the longest chain of values. * // Silly game to find the longest chain of values.
* int main(int argc, char *argv[]) * 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;) { * for (i = 1; i < 1024;) {
* // Since run is an int, compiler checks "add" does too. * // Since run is an int, compiler checks "add" does too.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment