File: yorn.c

package info (click to toggle)
libite 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,188 kB
  • sloc: sh: 4,665; ansic: 4,165; makefile: 141
file content (32 lines) | stat: -rw-r--r-- 442 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

#include "check.h"

int main(void)
{
	int chan[2];
	int status;

	pipe(chan);

	if (fork() > 0) {
		dup2(chan[0], STDIN_FILENO);
		if (yorn("Do you really wanna do this (y/N)? ")) {
			printf("Affirmative!\n");
			_exit(0);
		}

		printf("OK, aborting!\n");
		_exit(1);
	}

	sleep(1);
	if (write(chan[1], "Y", 1) != 1)
		return 1;

	wait(&status);

	return WEXITSTATUS(status);
}