eeb6079fdb51f66c92a8607aca1e527c03312205
[deliverable/binutils-gdb.git] / sim / testsuite / sim / cris / c / freopen1.c
1 /* Check that basic freopen functionality works.
2 #xfail: *-*-*
3 Currently doesn't work, because syscall.c:cb_syscall case
4 CB_SYS_write intercepts writes to fd 1 and 2. */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 int
11 main (void)
12 {
13 FILE *old_stderr;
14 FILE *f;
15 const char fname[] = "sk1test.dat";
16 const char tsttxt[]
17 = "A random line of text, used to test correct freopen etc.\n";
18 char buf[sizeof tsttxt] = "";
19
20 /* Like the freopen call in flex. */
21 old_stderr = freopen (fname, "w+", stderr);
22 if (old_stderr == NULL
23 || fwrite (tsttxt, 1, strlen (tsttxt), stderr) != strlen (tsttxt)
24 || fclose (stderr) != 0)
25 {
26 printf ("fail\n");
27 exit (1);
28 }
29
30 /* Using "rb" to make this test similar to the use in genconf.c in
31 GhostScript. */
32 f = fopen (fname, "rb");
33 if (f == NULL
34 || fseek (f, 0L, SEEK_END) != 0
35 || ftell (f) != strlen (tsttxt))
36 {
37 printf ("fail\n");
38 exit (1);
39 }
40
41 rewind (f);
42 if (fread (buf, 1, strlen (tsttxt), f) != strlen (tsttxt)
43 || strcmp (buf, tsttxt) != 0
44 || fclose (f) != 0)
45 {
46 printf ("fail\n");
47 exit (1);
48 }
49
50 printf ("pass\n");
51 exit (0);
52 }
This page took 0.030066 seconds and 3 git commands to generate.