2 #include <talloc/talloc.h>
3 #include <string/string.h>
15 static const char explain[]
16 = "Headers usually start with the C preprocessor lines to prevent multiple\n"
17 "inclusions. These look like the following:\n"
18 "#ifndef MY_HEADER_H\n"
19 "#define MY_HEADER_H\n"
21 "#endif /* MY_HEADER_H */\n";
23 static char *report_idem(struct ccan_file *f, char *sofar)
28 lines = get_ccan_file_lines(f);
30 /* FIXME: We assume small headers probably uninteresting. */
33 if (!strstarts(lines[0], "#ifndef "))
34 return talloc_asprintf_append(sofar,
35 "%s:1:expect first line to be #ifndef.\n", f->name);
37 secondline = talloc_asprintf(f, "#define %s",
38 lines[0] + strlen("#ifndef "));
39 if (!streq(lines[1], secondline))
40 return talloc_asprintf_append(sofar,
41 "%s:2:expect second line to be '%s'.\n",
47 static void *check_idempotent(struct manifest *m)
52 list_for_each(&m->h_files, f, list)
53 report = report_idem(f, report);
58 static const char *describe_idempotent(struct manifest *m, void *check_result)
60 return talloc_asprintf(check_result,
61 "Some headers not idempotent:\n"
62 "%s\n%s", (char *)check_result,
66 struct ccanlint idempotent = {
67 .name = "Headers are #ifndef/#define idempotent wrapped",
69 .check = check_idempotent,
70 .describe = describe_idempotent,