_info 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. /**
  5. * tal/grab_file - file helper routines
  6. *
  7. * This contains simple functions for getting the contents of a file.
  8. *
  9. * Example:
  10. * #include <err.h>
  11. * #include <stdio.h>
  12. * #include <string.h>
  13. * #include <ccan/tal/grab_file/grab_file.h>
  14. * #include <ccan/tal/tal.h> // for tal_free
  15. *
  16. * int main(int argc, char *argv[])
  17. * {
  18. * char *file;
  19. *
  20. * if (argc > 2)
  21. * err(1, "Takes 0 or 1 arguments");
  22. * file = grab_file(NULL, argv[1]);
  23. * if (!file)
  24. * err(1, "Could not read file %s", argv[1]);
  25. * if (strlen(file)+1 != tal_count(file))
  26. * printf("File contains NUL characters\n");
  27. * else if (tal_count(file) == 1)
  28. * printf("File contains nothing\n");
  29. * else if (strchr(file, '\n'))
  30. * printf("File contains multiple lines\n");
  31. * else
  32. * printf("File contains one line\n");
  33. * tal_free(file);
  34. *
  35. * return 0;
  36. * }
  37. *
  38. * License: LGPL (v2.1 or any later version)
  39. * Author: Rusty Russell <rusty@rustcorp.com.au>
  40. */
  41. int main(int argc, char *argv[])
  42. {
  43. if (argc != 2)
  44. return 1;
  45. if (strcmp(argv[1], "depends") == 0) {
  46. printf("ccan/tal\n");
  47. printf("ccan/noerr\n");
  48. return 0;
  49. }
  50. if (strcmp(argv[1], "testdepends") == 0) {
  51. printf("ccan/tal/str\n");
  52. return 0;
  53. }
  54. return 1;
  55. }