has_main_header.c 1018 B

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