Initial import
[gdb.git] / sim / testsuite / sim / cris / c / fdopen2.c
blob6a59f367a349e279ddd4ca9748cea17f77c5ad2e
1 /* Check that the syscalls implementing fdopen work trivially.
2 #output: This is the first line of this test.\npass\n
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
11 void
12 perr (const char *s)
14 perror (s);
15 exit (1);
18 int
19 main (void)
21 FILE *f;
22 int fd;
23 const char fname[] = "sk1test.dat";
24 const char tsttxt1[]
25 = "This is the first line of this test.\n";
26 char buf[sizeof (tsttxt1)] = "";
28 /* Write a line to stdout. */
29 f = fdopen (1, "w");
30 if (f == NULL
31 || fwrite (tsttxt1, 1, strlen (tsttxt1), f) != strlen (tsttxt1))
32 perr ("fdopen or fwrite");
34 #if 0
35 /* Unfortunately we can't get < /dev/null to the simulator with
36 reasonable test-framework surgery. */
38 /* Try to read from stdin. Expect EOF. */
39 f = fdopen (0, "r");
40 if (f == NULL
41 || fread (buf, 1, sizeof (buf), f) != 0
42 || feof (f) == 0
43 || ferror (f) != 0)
45 printf ("fail\n");
46 exit (1);
48 #endif
50 printf ("pass\n");
51 exit (0);