Date: Thu, 10 Jun 1999 10:46:24 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: "Mark E." cc: djgpp-workers AT delorie DOT com Subject: Re: enhancements to fcntl.c In-Reply-To: <199906072202.WAA44782@out5.ibm.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Mon, 7 Jun 1999, Mark E. wrote: > From looking over the source and the interrupt list, I don't think even > O_APPEND can be set with F_SETFL since it's only used when the file > is open and it isn't stored in the SFT. This actually means we have a bug in the library, as the attached two test programs will demonstrate: `open' with O_APPEND and `fopen' with "a" do NOT position the file pointer at EOF prior to every write, contrary to what ANSI and Posix say. I'm not sure whether this will be fixed in v2.03 or postponed till 2.04 (after all, this bug probably goes back to v2.0, and AFAIK nobody complained until now), but in any case it *will* be solved before the improved `fcntl' hits the street. A simple way to fix it would be to record the O_APPEND bit in the __file_handle_modes[] array, where currently we only record the binary/text bit, and force lseek/fseek on every write. So I think `fcntl' can use __file_handle_modes[] for peeking at O_APPEND and poking it. ------------------------------------------------------------------- #include #include #include int main (void) { static char line_1[] = "This is the first line\n"; static char line_2[] = "And this is the second line\n"; int fd = open ("open.dat", O_RDWR | O_APPEND, 0666); if (fd > 2) { write (fd, line_1, sizeof (line_1) - 1); lseek (fd, 0L, SEEK_SET); write (fd, line_2, sizeof (line_2) - 1); if (close (fd)) perror ("closing file"); } return 0; } #include int main (void) { static char line_1[] = "This is the first line\n"; static char line_2[] = "And this is the second line\n"; FILE *fp = fopen ("fopen.dat", "a+"); if (fp) { fwrite (line_1, 1, sizeof (line_1) - 1, fp); fseek (fp, 0L, SEEK_SET); fwrite (line_2, 1, sizeof (line_2) - 1, fp); if (fclose (fp)) perror ("closing file"); } return 0; }