tunables: Use direct syscall for access (BZ#21744)
[glibc.git] / stdio-common / tst-fwrite.c
blob2986c8932a8c06bf71b5472ed64a44dadff84d81
1 /* Derived from the test case in
2 http://sourceware.org/bugzilla/show_bug.cgi?id=1078. */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 #define OUT_SIZE 10000
10 static int fd;
12 static void prepare (void);
13 #define PREPARE(argc, argv) prepare ()
15 static int do_test (void);
16 #define TEST_FUNCTION do_test ()
18 #include "../test-skeleton.c"
21 static void
22 prepare (void)
24 fd = create_temp_file ("tst-fwrite.", NULL);
25 if (fd == -1)
27 puts ("cannot create temporary file");
28 exit (1);
33 static int
34 do_test (void)
36 FILE* f = fdopen (fd, "w+");
37 if (f == NULL) {
38 puts ("cannot create stream");
39 return 1;
41 puts ("Opened temp file");
43 if (fwrite ("a", 1, 1, f) != 1)
45 puts ("1st fwrite failed");
46 return 1;
48 puts ("Wrote a byte");
49 fflush (f);
51 char buffer[10000];
52 size_t i = fread (buffer, 1, sizeof (buffer), f);
53 printf ("Read %zu bytes\n", i);
55 for (i = 0; i < OUT_SIZE; i++)
57 if (fwrite ("n", 1, 1, f) != 1)
59 printf ("fwrite in loop round %zu failed\n", i);
60 return 1;
63 if ((i + 1) % 1000 == 0)
64 printf ("wrote %zu bytes ...\n", i + 1);
67 printf ("Wrote %i bytes [done]\n", OUT_SIZE);
69 return 0;