]> sourceware.org Git - glibc.git/blame - stdio-common/bug4.c
Avoid uninitialized result in sem_open when file does not exist
[glibc.git] / stdio-common / bug4.c
CommitLineData
28f540f4
RM
1#include <stdio.h>
2#include <unistd.h>
3#include <string.h>
4
a84dcb4b
FB
5#include <support/xstdio.h>
6
28f540f4
RM
7int stdio_block_read = 1, stdio_block_write = 1;
8
9int
1f07e617 10main (int argc, char *argv[])
28f540f4
RM
11{
12 FILE *f;
13 int i;
14 char buffer[31];
27f10a09 15 const char filename[] = OBJPFX "bug4.test";
28f540f4 16
1ef32c3d 17 while ((i = getopt (argc, argv, "rw")) != -1)
28f540f4
RM
18 switch (i)
19 {
20 case 'r':
21 stdio_block_read = 0;
22 break;
23 case 'w':
24 stdio_block_write = 0;
25 break;
26 }
27
1f07e617
UD
28 f = fopen (filename, "w+");
29 for (i = 0; i < 9000; ++i)
28f540f4 30 putc('x', f);
1f07e617
UD
31
32 fseek (f, 8180L, 0);
33 fwrite ("Where does this text come from?", 1, 31, f);
34 fseek (f, 8180L, 0);
a84dcb4b 35 xfread (buffer, 1, 31, f);
1f07e617
UD
36 fwrite (buffer, 1, 31, stdout);
37 fclose (f);
38 remove (filename);
28f540f4
RM
39
40 if (!memcmp (buffer, "Where does this text come from?", 31))
41 {
42 puts ("\nTest succeeded.");
43 return 0;
44 }
45 else
46 {
47 puts ("\nTest FAILED!");
48 return 1;
49 }
50}
This page took 0.859552 seconds and 6 git commands to generate.