Files
lightning/ccan/ccan/pipecmd/_info
Rusty Russell 74d471d4e4 ccan: update.
This gives us a slew of -Wextra fixes (not all of them though!) but
we're actually doing it for the monotonic version of timers.

This breaks some stuff, so we fix that up next.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:55:15 +10:30

60 lines
1.3 KiB
Plaintext

#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* pipecmd - code to fork and run a command in a pipe.
*
* This code is a classic example of how to run a command in a child, while
* handling the case where the exec fails.
*
* License: CC0 (Public domain)
* Author: Rusty Russell <rusty@rustcorp.com.au>
*
* Example:
* // Outputs HELLO WORLD
* #include <ccan/pipecmd/pipecmd.h>
* #include <ccan/err/err.h>
* #include <sys/types.h>
* #include <sys/wait.h>
* #include <unistd.h>
* #include <ctype.h>
*
* // Runs ourselves with an argument, upcases output.
* int main(int argc, char **argv)
* {
* pid_t child;
* int outputfd, i, status;
* char input[12];
*
* if (argc == 2) {
* if (write(STDOUT_FILENO, "hello world\n", 12) != 12)
* exit(1);
* exit(0);
* }
* child = pipecmd(&outputfd, NULL, NULL, argv[0], "ignoredarg", NULL);
* if (child < 0)
* err(1, "Creating child");
* if (read(outputfd, input, sizeof(input)) != sizeof(input))
* err(1, "Reading input");
* if (waitpid(child, &status, 0) != child)
* err(1, "Waiting for child");
* for (i = 0; i < sizeof(input); i++)
* printf("%c", toupper(input[i]));
* exit(0);
* }
*/
int main(int argc, char *argv[])
{
/* Expect exactly one argument */
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/noerr\n");
return 0;
}
return 1;
}