3 static void do_prepare (void);
4 #define PREPARE(argc, argv) do_prepare ()
5 static int do_test (void);
6 #define TEST_FUNCTION do_test()
7 #include "../test-skeleton.c"
16 fd
= create_temp_file ("bug-fclose1.", NULL
);
19 printf ("cannot create temporary file: %m\n");
28 static const char pattern
[] = "hello world";
30 /* Prepare a seekable file. */
31 if (write (fd
, pattern
, sizeof pattern
) != sizeof pattern
)
33 printf ("cannot write pattern: %m\n");
36 if (lseek (fd
, 1, SEEK_SET
) != 1)
38 printf ("cannot seek after write: %m\n");
42 /* Create an output stream visiting the file; when it is closed, all
43 other file descriptors visiting the file must see the new file
48 printf ("cannot duplicate descriptor for writing: %m\n");
51 FILE *f
= fdopen (fd2
, "w");
54 printf ("first fdopen failed: %m\n");
57 if (fputc (pattern
[1], f
) != pattern
[1])
59 printf ("fputc failed: %m\n");
64 printf ("first fclose failed: %m\n");
68 if (lseek (fd2
, 0, SEEK_CUR
) != -1)
70 printf ("lseek after fclose after write did not fail\n");
75 printf ("lseek after fclose after write did not fail with EBADF: %m\n");
78 off_t o
= lseek (fd
, 0, SEEK_CUR
);
82 lseek on original descriptor after first fclose returned %ld, expected 2\n",
87 /* Likewise for an input stream. */
91 printf ("cannot duplicate descriptor for reading: %m\n");
94 f
= fdopen (fd2
, "r");
97 printf ("second fdopen failed: %m\n");
103 printf ("getc returned %c, expected %c\n", c
, pattern
[2]);
108 printf ("second fclose failed: %m\n");
112 if (lseek (fd2
, 0, SEEK_CUR
) != -1)
114 printf ("lseek after fclose after read did not fail\n");
119 printf ("lseek after fclose after read did not fail with EBADF: %m\n");
122 o
= lseek (fd
, 0, SEEK_CUR
);
126 lseek on original descriptor after second fclose returned %ld, expected 3\n",