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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [sim/] [testsuite/] [sim/] [cris/] [c/] [append1.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
/* Check regression of a bug uncovered by the libio tFile test (old
2
   libstdc++, pre-gcc-3.x era), where appending to a file doesn't work.
3
   The default open-flags-mapping does not match Linux/CRIS, so a
4
   specific mapping is necessary.  */
5
 
6
#include <stdio.h>
7
#include <string.h>
8
#include <stdlib.h>
9
 
10
int
11
main (void)
12
{
13
  FILE *f;
14
  const char fname[] = "sk1test.dat";
15
  const char tsttxt1[]
16
    = "This is the first and only line of this file.\n";
17
  const char tsttxt2[] = "Now there is a second line.\n";
18
  char buf[sizeof (tsttxt1) + sizeof (tsttxt2) - 1] = "";
19
 
20
  f = fopen (fname, "w+");
21
  if (f == NULL
22
      || fwrite (tsttxt1, 1, strlen (tsttxt1), f) != strlen (tsttxt1)
23
      || fclose (f) != 0)
24
    {
25
      printf ("fail\n");
26
      exit (1);
27
    }
28
 
29
  f = fopen (fname, "a+");
30
  if (f == NULL
31
      || fwrite (tsttxt2, 1, strlen (tsttxt2), f) != strlen (tsttxt2)
32
      || fclose (f) != 0)
33
    {
34
      printf ("fail\n");
35
      exit (1);
36
    }
37
 
38
  f = fopen (fname, "r");
39
  if (f == NULL
40
      || fread (buf, 1, sizeof (buf), f) != sizeof (buf) - 1
41
      || strncmp (buf, tsttxt1, strlen (tsttxt1)) != 0
42
      || strncmp (buf + strlen (tsttxt1), tsttxt2, strlen (tsttxt2)) != 0
43
      || fclose (f) != 0)
44
    {
45
      printf ("fail\n");
46
      exit (1);
47
    }
48
 
49
  printf ("pass\n");
50
  exit (0);
51
}

powered by: WebSVN 2.1.0

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