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/] [truncate1.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
/* Check that the truncate syscall works trivially.
2
#notarget: cris*-*-elf
3
*/
4
 
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <string.h>
8
 
9
#ifndef PREFIX
10
#define PREFIX
11
#endif
12
int
13
main (void)
14
{
15
  FILE *f;
16
  const char fname[] = PREFIX "sk1test.dat";
17
  const char tsttxt1[]
18
    = "This is the first and only line of this file.\n";
19
  const char tsttxt2[] = "Now there is a second line.\n";
20
  char buf[sizeof (tsttxt1) + sizeof (tsttxt2) - 1] = "";
21
 
22
  f = fopen (fname, "w+");
23
  if (f == NULL
24
      || fwrite (tsttxt1, 1, strlen (tsttxt1), f) != strlen (tsttxt1)
25
      || fclose (f) != 0)
26
    {
27
      printf ("fail\n");
28
      exit (1);
29
    }
30
 
31
  if (truncate (fname, strlen(tsttxt1) - 10) != 0)
32
    {
33
      perror ("truncate");
34
      exit (1);
35
    }
36
 
37
  f = fopen (fname, "r");
38
  if (f == NULL
39
      || fread (buf, 1, sizeof (buf), f) != strlen (tsttxt1) - 10
40
      || strncmp (buf, tsttxt1, strlen (tsttxt1) - 10) != 0
41
      || fclose (f) != 0)
42
    {
43
      printf ("fail\n");
44
      exit (1);
45
    }
46
 
47
  printf ("pass\n");
48
  exit (0);
49
}

powered by: WebSVN 2.1.0

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