[PATCH] Implement run_command_to_buf (spawn a process and reads its stdout)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 diff.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/diff.c b/diff.c
index 1c8dd19..6917981 100644
--- a/diff.c
+++ b/diff.c
@@ -260,6 +260,10 @@ static struct diff_tempfile {
 	char tmp_path[PATH_MAX];
 } diff_temp[2];
 
+/* Forward declarations */
+static int run_command_to_buf(const char **argv, char **buf, size_t * size);
+/* End forward declarations */
+
 static int count_lines(const char *data, int size)
 {
 	int count, ch, completely_empty = 1, nl_just_seen = 0;
@@ -1487,6 +1491,26 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
 		options->b_prefix = b;
 }
 
+static int run_command_to_buf(const char **argv, char **buf, size_t * size)
+{
+	struct child_process cmd;
+	struct strbuf buffer = STRBUF_INIT;
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.argv = argv;
+	cmd.out = -1;
+
+	if (start_command(&cmd))
+		return -1;
+	strbuf_read(&buffer, cmd.out, 1024);
+	close(cmd.out);
+
+	if (finish_command(&cmd))
+		return -1;
+
+	*buf = strbuf_detach(&buffer, size);
+	return 0;
+}
+
 static void builtin_diff(const char *name_a,
 			 const char *name_b,
 			 struct diff_filespec *one,
-- 
1.6.0.2.312.g1ef81a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux