]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/main_header_exists.c
b6150dc844c8232e3e32528e8e01f49fc672bf37
[ccan] / tools / ccanlint / tests / main_header_exists.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <limits.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <err.h>
11 #include <ccan/str/str.h>
12 #include <ccan/talloc/talloc.h>
13 #include <ccan/noerr/noerr.h>
14
15 static void check_has_main_header(struct manifest *m,
16                                   bool keep,
17                                   unsigned int *timeleft, struct score *score)
18 {
19         struct ccan_file *f;
20
21         list_for_each(&m->h_files, f, list) {
22                 if (strstarts(f->name, m->basename)
23                     && strlen(f->name) == strlen(m->basename) + 2) {
24                         score->pass = true;
25                         score->score = score->total;
26                         return;
27                 }
28         }
29         score->error = talloc_asprintf(score,
30         "You have no %s/%s.h header file.\n\n"
31         "CCAN modules have a name, the same as the directory name.  They're\n"
32         "expected to have an interface in the header of the same name.\n",
33                                        m->basename, m->basename);
34 }
35
36 struct ccanlint main_header_exists = {
37         .key = "main_header_exists",
38         .name = "Module has main header file",
39         .check = check_has_main_header,
40         .needs = ""
41 };
42
43 REGISTER_TEST(main_header_exists);