_info 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. /**
  5. * 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/grab_file/grab_file.h>
  14. * #include <ccan/talloc/talloc.h> // For talloc_free()
  15. *
  16. * int main(int argc, char *argv[])
  17. * {
  18. * size_t len;
  19. * char *file;
  20. *
  21. * file = grab_file(NULL, argv[1], &len);
  22. * if (!file)
  23. * err(1, "Could not read file %s", argv[1]);
  24. * if (strlen(file) != len)
  25. * printf("File contains NUL characters\n");
  26. * else if (len == 0)
  27. * printf("File contains nothing\n");
  28. * else if (strchr(file, '\n'))
  29. * printf("File contains multiple lines\n");
  30. * else
  31. * printf("File contains one line\n");
  32. * talloc_free(file);
  33. *
  34. * return 0;
  35. * }
  36. *
  37. * License: LGPL (v2.1 or any later version)
  38. * Author: Rusty Russell <rusty@rustcorp.com.au>
  39. */
  40. int main(int argc, char *argv[])
  41. {
  42. if (argc != 2)
  43. return 1;
  44. if (strcmp(argv[1], "depends") == 0) {
  45. printf("ccan/talloc\n");
  46. printf("ccan/noerr\n");
  47. return 0;
  48. }
  49. return 1;
  50. }