6 #include <support/xstdio.h>
11 static void do_prepare (void);
12 #define PREPARE(argc, argv) do_prepare ()
13 static int do_test (void);
14 #define TEST_FUNCTION do_test ()
15 #include <test-skeleton.c>
21 static const char pattern
[] = "12345678901234567890";
22 int fd
= create_temp_file ("bug-fseek.", &fname
);
25 printf ("cannot create temporary file: %m\n");
29 if (write (fd
, pattern
, sizeof (pattern
)) != sizeof (pattern
))
31 perror ("short write");
47 if ((f
= fopen (fname
, "r")) == (FILE *) NULL
)
49 perror ("fopen(\"r\")");
52 xfread (buf
, 3, 1, f
);
54 if (fseek (f
, -10, SEEK_CUR
) == 0)
56 printf ("fseek() for r to before start of file worked!\n");
59 else if (errno
!= EINVAL
)
62 fseek() for r to before start of file did not set errno to EINVAL. \
71 if ((f
= fopen (fname
, "r+")) == (FILE *) NULL
)
73 perror ("fopen(\"r+\")");
76 xfread (buf
, 3, 1, f
);
78 if (fseek (f
, -10, SEEK_CUR
) == 0)
80 printf ("fseek() for r+ to before start of file worked!\n");
83 else if (errno
!= EINVAL
)
86 fseek() for r+ to before start of file did not set errno to EINVAL. \
95 if ((f
= fopen (fname
, "r+")) == (FILE *) NULL
)
97 perror ("fopen(\"r+\")");
100 xfread (buf
, 3, 1, f
);
103 puts ("ftell failed");
107 if (fseek (f
, -10, SEEK_CUR
) == 0)
109 printf ("fseek() for r+ to before start of file worked!\n");
112 else if (errno
!= EINVAL
)
115 fseek() for r+ to before start of file did not set errno to EINVAL. \