Be a little more careful with const.
#include <ccan/opt/opt.h>
#include <ccan/foreach/foreach.h>
#include <ccan/grab_file/grab_file.h>
+#include <ccan/cast/cast.h>
int verbose = 0;
static LIST_HEAD(compulsory_tests);
static unsigned int timeout;
/* These are overridden at runtime if we can find config.h */
-char *compiler = NULL;
-char *cflags = NULL;
+const char *compiler = NULL;
+const char *cflags = NULL;
const char *config_header;
}
}
-static int show_tmpdir(char *dir)
+static int show_tmpdir(const char *dir)
{
printf("You can find ccanlint working files in '%s'\n", dir);
return 0;
compiler = CCAN_CFLAGS;
}
+static char *opt_set_const_charp(const char *arg, const char **p)
+{
+ return opt_set_charp(arg, cast_const2(char **, p));
+}
+
int main(int argc, char *argv[])
{
bool summary = false;
opt_register_arg("--target <testname>", opt_set_charp,
NULL, &target,
"only run one test (and its prerequisites)");
- opt_register_arg("--compiler <compiler>", opt_set_charp,
+ opt_register_arg("--compiler <compiler>", opt_set_const_charp,
NULL, &compiler, "set the compiler");
- opt_register_arg("--cflags <flags>", opt_set_charp,
+ opt_register_arg("--cflags <flags>", opt_set_const_charp,
NULL, &cflags, "set the compiler flags");
opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
"\nA program for checking and guiding development"
extern const char *ccan_dir;
/* Compiler and CFLAGS, from config.h if available. */
-extern char *compiler, *cflags;
+extern const char *compiler, *cflags;
/* Contents of config.h (or NULL if not found) */
extern const char *config_header;
#include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
+#include <ccan/cast/cast.h>
#include <ccan/str/str.h>
#include <sys/types.h>
#include <sys/stat.h>
/* The winners. */
if (strstarts(line, "if") && len == 2) {
- *why = "starts with if";
+ *why = cast_const(char *, "starts with if");
return true;
}
if (strstarts(line, "for") && len == 3) {
- *why = "starts with for";
+ *why = cast_const(char *, "starts with for");
return true;
}
if (strstarts(line, "while") && len == 5) {
- *why = "starts with while";
+ *why = cast_const(char *, "starts with while");
return true;
}
if (strstarts(line, "do") && len == 2) {
- *why = "starts with do";
+ *why = cast_const(char *, "starts with do");
return true;
}
/* The losers. */
if (strstarts(line, "#include")) {
- *why = "starts with #include";
+ *why = cast_const(char *, "starts with #include");
return false;
}
if (last_ended && strchr(line, '(')) {
if (strstarts(line, "static")) {
- *why = "starts with static and contains (";
+ *why = cast_const(char *,
+ "starts with static"
+ " and contains (");
return false;
}
if (strends(line, ")")) {
- *why = "contains ( and ends with )";
+ *why = cast_const(char *,
+ "contains ( and ends with )");
return false;
}
}
/* Single identifier then operator == inside function. */
if (last_ended && len
&& cispunct(line[len+strspn(line+len, " ")])) {
- *why = "starts with identifier then punctuation";
+ *why = cast_const(char *, "starts with identifier"
+ " then punctuation");
return true;
}
}
/* No idea... Say yes? */
- *why = "gave no clues";
+ *why = cast_const(char *, "gave no clues");
return true;
}
bool res[3];
unsigned num, j;
char **lines[3];
- char *error;
+ const char *error;
score->total++;
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h>
+#include <ccan/cast/cast.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
!= strlen(example->lines[i])
|| write(fd, "\n", 1) != 1) {
close(fd);
- return "Failure writing to temporary file";
+ return cast_const(char *,
+ "Failure writing to temporary file");
}
}
close(fd);
#include <ccan/talloc/talloc.h>
#include <ccan/foreach/foreach.h>
#include <ccan/str/str.h>
+#include <ccan/cast/cast.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
foreach_ptr(fmt, "outputs '%s'", "outputs \"%s\"") {
if (scan_for(file, p, fmt, &expect)) {
- *input = "";
+ *input = cast_const(char *, "");
*exact = true;
return expect;
}
"outputs \"%s\"",
"outputs %s") {
if (scan_for(file, p, fmt, &expect)) {
- *input = "";
+ *input = cast_const(char *, "");
*exact = true;
return expect;
}
"output contains \"%s\"",
"output contains %s") {
if (scan_for(file, p, fmt, &expect)) {
- *input = "";
+ *input = cast_const(char *, "");
*exact = false;
return expect;
}
{ "HAVE_BYTESWAP_H", OUTSIDE_MAIN, NULL,
"#include <byteswap.h>\n" },
{ "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL,
- "char **foo = (char *[]) { \"x\", \"y\", \"z\" };\n"
+ "int *foo = (int[]) { 1, 2, 3, 4 };\n"
"return foo[0] ? 0 : 1;" },
{ "HAVE_FOR_LOOP_DECLARATION", INSIDE_MAIN, NULL,
"for (int i = 0; i < argc; i++) { return 0; };\n"
return ret;
}
-static char *connect_args(char *argv[], const char *extra)
+static char *connect_args(const char *argv[], const char *extra)
{
unsigned int i, len = strlen(extra) + 1;
char *ret;
return test->answer;
}
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
{
char *cmd;
- char *default_args[] = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
unsigned int i;
+ const char *default_args[]
+ = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
if (argc > 1) {
if (strcmp(argv[1], "--help") == 0) {
#include <errno.h>
static char ** __attribute__((format(printf, 2, 3)))
-lines_from_cmd(const void *ctx, char *format, ...)
+lines_from_cmd(const void *ctx, const char *format, ...)
{
va_list ap;
char *cmd, *buffer;
#include <assert.h>
#include "tools.h"
-static char *tmpdir = NULL;
+static const char *tmpdir = NULL;
bool tools_verbose = false;
/* Ten minutes. */
return false;
}
-static int unlink_all(char *dir)
+static int unlink_all(const char *dir)
{
char cmd[strlen(dir) + sizeof("rm -rf ")];
sprintf(cmd, "rm -rf %s", dir);
return 0;
}
-char *temp_dir(const void *ctx)
+const char *temp_dir(const void *ctx)
{
/* For first call, create dir. */
while (!tmpdir) {
const char *fmt, ...);
char *run_with_timeout(const void *ctx, const char *cmd,
bool *ok, unsigned *timeout_ms);
-char *temp_dir(const void *ctx);
+const char *temp_dir(const void *ctx);
bool move_file(const char *oldname, const char *newname);
/* From compile.c.