OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [testsuite/] [sim/] [cris/] [c/] [freopen2.c] - Blame information for rev 227

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
/* Tests that stdin can be redirected from a normal file.  */
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
 
6
int
7
main (void)
8
{
9
   const char* fname = "freopen.dat";
10
   const char tsttxt[]
11
       = "A random line of text, used to test correct freopen etc.\n";
12
   FILE* instream;
13
   FILE *old_stderr;
14
   char c1;
15
 
16
   /* Like the freopen call in flex.  */
17
   old_stderr = freopen (fname, "w+", stderr);
18
   if (old_stderr == NULL
19
      || fwrite (tsttxt, 1, strlen (tsttxt), stderr) != strlen (tsttxt)
20
      || fclose (stderr) != 0)
21
   {
22
      printf ("fail\n");
23
      exit (1);
24
   }
25
 
26
   instream = freopen(fname, "r", stdin);
27
   if (instream == NULL) {
28
      printf("fail\n");
29
      exit(1);
30
   }
31
 
32
   c1 = getc(instream);
33
   if (c1 != 'A') {
34
      printf("fail\n");
35
      exit(1);
36
   }
37
 
38
   printf ("pass\n");
39
   exit(0);
40
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.