]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/main_header_exists.c
cdb01149d97f245a86262e0d7094b3568fe8adc2
[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                                   unsigned int *timeleft, struct score *score)
17 {
18         struct ccan_file *f;
19
20         list_for_each(&m->h_files, f, list) {
21                 if (strstarts(f->name, m->basename)
22                     && strlen(f->name) == strlen(m->basename) + 2) {
23                         score->pass = true;
24                         score->score = score->total;
25                         return;
26                 }
27         }
28         score->error = talloc_asprintf(score,
29         "You have no %s/%s.h header file.\n\n"
30         "CCAN modules have a name, the same as the directory name.  They're\n"
31         "expected to have an interface in the header of the same name.\n",
32                                        m->modname, m->basename);
33 }
34
35 struct ccanlint main_header_exists = {
36         .key = "main_header_exists",
37         .name = "Module has main header file",
38         .check = check_has_main_header,
39         .needs = ""
40 };
41
42 REGISTER_TEST(main_header_exists);