]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/has_main_header.c
e1b711983eb8c28eeda2bb623f4c01073c2bc2be
[ccan] / tools / ccanlint / has_main_header.c
1 #include "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 {
17         struct ccan_file *f;
18
19         list_for_each(&m->h_files, f, list) {
20                 if (strstarts(f->name, m->basename)
21                     && strlen(f->name) == strlen(m->basename) + 2)
22                         return NULL;
23         }
24         return m;
25 }
26
27 static const char *describe_has_main_header(struct manifest *m,
28                                             void *check_result)
29 {
30         return talloc_asprintf(m,
31         "You have no %s/%s.h header file.\n\n"
32         "CCAN modules have a name, the same as the directory name.  They're\n"
33         "expected to have an interface in the header of the same name.\n",
34                                m->basename, m->basename);
35 }
36
37 struct ccanlint has_main_header = {
38         .name = "No main header file",
39         .check = check_has_main_header,
40         .describe = describe_has_main_header,
41 };