_info 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. /**
  5. * stringbuilder - join lists of strings
  6. *
  7. * This is a small set of functions for building up strings from a list.
  8. * The destination buffer is bounds-checked, the functions return failure
  9. * if the concatenated strings overflow the buffer.
  10. *
  11. * Example:
  12. * #include <stdio.h>
  13. * #include <string.h>
  14. * #include <errno.h>
  15. * #include <ccan/stringbuilder/stringbuilder.h>
  16. *
  17. * int main(int argc, char *argv[])
  18. * {
  19. * char mystring[128];
  20. * int res;
  21. *
  22. * res = stringbuilder_array(mystring, 128, "', '",
  23. * argc, (const char**)argv);
  24. * if (!res)
  25. * printf("My arguments: '%s'\n", mystring);
  26. * else
  27. * printf("Failed to join arguments: %s\n",
  28. * strerror(res));
  29. * if (!res) {
  30. * res = stringbuilder(mystring, 128, ", ",
  31. * "This", "Is", "A", "Test");
  32. * if (!res)
  33. * printf("My string: '%s'\n", mystring);
  34. * else
  35. * printf("Failed to join strings: %s\n",
  36. * strerror(res));
  37. * }
  38. * return 0;
  39. * }
  40. *
  41. * License: CC0 (Public domain)
  42. * Author: Stuart Longland <stuartl@longlandclan.yi.org>
  43. */
  44. int main(int argc, char *argv[])
  45. {
  46. if (argc != 2)
  47. return 1;
  48. if (strcmp(argv[1], "depends") == 0) {
  49. /*
  50. * This triggers a circular dependency!
  51. * printf("ccan/str\n");
  52. */
  53. return 0;
  54. }
  55. return 1;
  56. }