vfs: check userland buffers before reading them.
[haiku.git] / src / tests / libs / bsd / forkpty.c
blob4fb94b68d05abd8ec5b84edbab343d22aa73ce5a
1 /* from http://jwz.livejournal.com/817438.html */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <pty.h>
7 static int
8 do_fork(void)
10 int fd = -1;
11 pid_t pid;
13 if ((pid = forkpty(&fd, NULL, NULL, NULL)) < 0)
14 perror("forkpty");
15 else if (!pid)
17 printf ("0123456789\n");
19 /* #### Uncommenting this makes it work! */
20 /* sleep(20); */
22 exit (0);
25 return fd;
29 int
30 main (int argc, char **argv)
32 char s[1024];
33 int n;
34 int fd = do_fork();
36 /* On 10.4, this prints the whole 10 character line, 1 char per second.
37 On 10.5, it prints 1 character and stops.
39 do {
40 n = read (fd, s, 1);
41 if (n > 0) fprintf (stderr, "%c", *s);
42 sleep (1);
43 } while (n > 0);
45 return 0;