From bd82d030011cd8b9655e5ded6b6df9343b42a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 4 Feb 2015 14:09:54 +0100 Subject: Imported Upstream version 3.22 --- src/tc-proc.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/tc-proc.c (limited to 'src/tc-proc.c') diff --git a/src/tc-proc.c b/src/tc-proc.c new file mode 100644 index 0000000..7ec982f --- /dev/null +++ b/src/tc-proc.c @@ -0,0 +1,70 @@ +/* + * Copyright Jan Engelhardt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the WTF Public License version 2 or + * (at your option) any later version. + */ +#ifdef __cplusplus +# include +# include +# include +#else +# include +# include +# include +#endif +#include +#include +#include +#include + +static const char *const t_args1[] = {"ls", "ls", "-dl", ".", NULL}; +static const char *const t_args2[] = {"ls", "ls", "-l", NULL}; +static const char *const t_args3[] = {"ls", "-l", "/proc/self/fd/", NULL}; + +static void t_async1(void) +{ + FILE *fp; + int ret; + unsigned int i = 0; + hxmc_t *line = NULL; + struct HXproc proc; + + memset(&proc, 0, sizeof(proc)); + proc.p_flags = HXPROC_A0 | HXPROC_STDOUT; + + if ((ret = HXproc_run_async(t_args2, &proc)) <= 0) { + fprintf(stderr, "%s\n", strerror(errno)); + return; + } + if ((fp = fdopen(proc.p_stdout, "r")) == NULL) { + fprintf(stderr, "%s\n", strerror(errno)); + goto out; + } + while (HX_getl(&line, fp) != NULL) + printf("\t#%u\t%s", ++i, line); + + fclose(fp); + out: + close(proc.p_stdout); + HXproc_wait(&proc); + return; +} + +int main(void) +{ + if (HX_init() <= 0) + abort(); + + /* let it fail - test verbosity */ + HXproc_run_sync(t_args1 + 2, HXPROC_VERBOSE); + HXproc_run_sync(t_args1 + 3, HXPROC_VERBOSE); + + HXproc_run_sync(t_args1 + 1, 0); + + t_async1(); + HXproc_run_sync(t_args3, HXPROC_NULL_STDIN); + HX_exit(); + return EXIT_SUCCESS; +} -- cgit v1.2.3