Update release-README after completing the 2.43 release.
[binutils-gdb.git] / sim / testsuite / cris / c / fdopen1.c
blobcdfe19af7d70bcdf4e28e576da73c05d8240d9d9
1 /* Check that the syscalls implementing fdopen work trivially. */
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
9 void
10 perr (const char *s)
12 perror (s);
13 exit (1);
16 int
17 main (void)
19 FILE *f;
20 int fd;
21 const char fname[] = "sk1test.dat";
22 const char tsttxt1[]
23 = "This is the first and only line of this file.\n";
24 char buf[sizeof (tsttxt1)] = "";
26 fd = open (fname, O_WRONLY|O_TRUNC|O_CREAT, S_IRWXU);
27 if (fd <= 0)
28 perr ("open-w");
30 f = fdopen (fd, "w");
31 if (f == NULL
32 || fwrite (tsttxt1, 1, strlen (tsttxt1), f) != strlen (tsttxt1))
33 perr ("fdopen or fwrite");
35 if (fclose (f) != 0)
36 perr ("fclose");
38 fd = open (fname, O_RDONLY);
39 if (fd <= 0)
40 perr ("open-r");
42 f = fdopen (fd, "r");
43 if (f == NULL
44 || fread (buf, 1, sizeof (buf), f) != strlen (tsttxt1)
45 || strcmp (buf, tsttxt1) != 0
46 || fclose (f) != 0)
48 printf ("fail\n");
49 exit (1);
52 printf ("pass\n");
53 exit (0);