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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [misc/] [fdopen.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Test for fdopen bugs.  */
2
 
3
#include <stdio.h>
4
#include <unistd.h>
5
#include <fcntl.h>
6
 
7
#define assert(x) \
8
  if (!(x)) \
9
    { \
10
      fputs ("test failed: " #x "\n", stderr); \
11
      retval = 1; \
12
      goto the_end; \
13
    }
14
 
15
char buffer[256];
16
 
17
int
18
main (int argc, char *argv[])
19
{
20
  char *name;
21
  FILE *fp = NULL;
22
  int retval = 0;
23
  int fd;
24
 
25
  name = tmpnam (NULL);
26
  fp = fopen (name, "w");
27
  assert (fp != NULL)
28
  fputs ("foobar and baz", fp);
29
  fclose (fp);
30
  fp = NULL;
31
 
32
  fd = open (name, O_RDWR|O_CREAT);
33
  assert (fd != -1);
34
  assert (lseek (fd, 5, SEEK_SET) == 5);
35
 
36
  fp = fdopen (fd, "a");
37
  assert (fp != NULL);
38
  assert (ftell (fp) == 14);
39
 
40
the_end:
41
  if (fp != NULL)
42
    fclose (fp);
43
  unlink (name);
44
 
45
  return retval;
46
}

powered by: WebSVN 2.1.0

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