]> git.ozlabs.org Git - ccan/blobdiff - ccan/string/string.h
test case for grab_file
[ccan] / ccan / string / string.h
index 3b6367479783aba3c0dfa78965872af7d192bb72..14a9c2c8fdba86eedbb4c0845c5cd24d69035b34 100644 (file)
@@ -54,7 +54,8 @@ static inline bool strends(const char *str, const char *postfix)
  * This function splits a single string into multiple strings.  The
  * original string is untouched: an array is allocated (using talloc)
  * pointing to copies of each substring.  Multiple delimiters result
- * in empty substrings.
+ * in empty substrings.  By definition, no delimiters will appear in
+ * the substrings.
  *
  * The final char * in the array will be NULL, so you can use this or
  * @nump to find the array length.
@@ -76,4 +77,33 @@ static inline bool strends(const char *str, const char *postfix)
  */
 char **strsplit(const void *ctx, const char *string, const char *delims,
                 unsigned int *nump);
+
+/**
+ * strjoin - Join an array of substrings into one long string
+ * @ctx: the context to tallocate from (often NULL)
+ * @strings: the NULL-terminated array of strings to join
+ * @delim: the delimiter to insert between the strings
+ *
+ * This function joins an array of strings into a single string.  The
+ * return value is allocated using talloc.  Each string in @strings is
+ * followed by a copy of @delim.
+ *
+ * Example:
+ *     // Append the string "--EOL" to each line.
+ *     char *append_to_all_lines(const char *string)
+ *     {
+ *             char **lines, *ret;
+ *             unsigned int i, num, newnum;
+ *
+ *             lines = strsplit(NULL, string, "\n", NULL);
+ *             ret = strjoin(NULL, lines, "-- EOL\n");
+ *             talloc_free(lines);
+ *             return ret;
+ *     }
+ */
+char *strjoin(const void *ctx, char *strings[], const char *delim);
+
+void *grab_fd(const void *ctx, int fd);
+
+void *grab_file(const void *ctx, const char *filename);
 #endif /* CCAN_STRING_H */