Mail Archives: djgpp-workers/2002/05/08/11:54:26
On Wednesday 08 May 2002 18:33, Zack Weinberg wrote:
> On Wed, May 08, 2002 at 05:09:20PM +0300, Eli Zaretskii wrote:
> > On Wed, 8 May 2002, Andris Pavenis wrote:
> > > Original message (and patch) was due to a different reason: use of
> > > source files originated from DOS under other systems (unfortunatelly
> > > read initial message not too carefully ...)
> >
> > For other systems, I guess a warning under -W is okay.
>
> With or without truncating the input file?
I don't know. For DJGPP one needs that as I have seen source files ending ^Z
generated while building some packages. Also some text editors writes it at
the end of file. I don't know what GCC should do on other systems
>
> Is ^Z to be honored wherever it appears, or only immediately after a
> newline sequence?
Here is what I have in patchset for DJGPP
--- cppfiles.c.orig Fri Jan 18 15:40:28 2002
+++ cppfiles.c Tue May 7 12:24:48 2002
@@ -414,6 +414,12 @@
{
buf = (U_CHAR *) xmalloc (size + 1);
offset = 0;
+#ifdef __DJGPP__
+ /* For DJGPP redirected input is opened with O_TEXT by default
+ change it to O_BINARY */
+ if (inc->fd==0)
+ setmode (inc->fd, O_BINARY);
+#endif
while (offset < size)
{
count = read (inc->fd, buf + offset, size - offset);
@@ -469,6 +475,20 @@
inc->st.st_size = offset;
}
+#ifdef __DJGPP__
+/* For DOS we should handle DOS EOF character (0x1A, ^Z) */
+ do {
+ U_CHAR * dos_eof = memchr (buf, 0x1A, offset);
+ if (dos_eof) {
+ offset = dos_eof - buf;
+ buf = xrealloc (buf, offset + 1);
+ /* The lexer requires that the buffer be NUL-terminated. */
+ buf[offset] = '\0';
+ inc->st.st_size = offset;
+ }
+ } while (0);
+#endif
+
inc->buffer = buf;
return 0;
>
> > > It reads in binary mode.
> >
> > I hope only when the input comes from a file, not from a terminal.
>
> It makes no distinction. What goes wrong when one reads from a
> terminal in binary mode under DOS?
>
> (I'm not sure how to open a file in text mode using open(),
> incidentally)
Andris
- Raw text -