From: gallant AT iro DOT umontreal DOT ca (Jean-Francois Gallant) Date: Sat, 3 Oct 1992 11:05:18 EDT To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Some patches to the C++ i/o library... Here are some patches to files cplusinc/streambu.h, libsrc/gcc/io/streambu.cc and libsrc/gcc/io/filebuf.cc. Those will: 1- eliminate a bug in streambu.cc which caused "istream::read" to return the first character of the stream twice (i.e. a file containing "abc" was read as "aabc"... quite catastrophic especially when reading binary files!); 2- define a new flag "ios::binary" for opening DOS file streams in binary format. Bug #1 is so obvious that I can't believe it has not already been fixed by someone else... Well, if such is the case, let me know! Flag "ios::binary" is not defined in GNU C (Unix version), so avoid using it if you plan to port your application to Unix. If you don't want to define this flag in DJGPP, don't patch files streambu.h and filebuf.cc. Miscellaneous: Somebody (sorry: I forget the name!) reported a bug, some weeks ago, about "cerr" (cerr << "String" << "\n" in a loop would cause a "swap space full" error to occur after 30 or so iterations). Was this problem solved? I tried it with (of course) the same results on my PC, but it works when compiled with GNU C (Unix). I expected it to produce similar results on Unix, because the C++ I/O library sources are the very same (at least is streambu.cc: the bug #1 above was present in the Unix version as well!). Can someone explain why it does work on Unix, and not on PC? About malloc: an application I wrote was issuing an "Out of memory" error when loading a (binary) data file in memory. The C++ "new" operator was used to allocate memory space to store the loaded objects (small ones: 30 bytes each...). Since the same unmodified application worked perfectly well when compiled with Borland C++, I had no reason to think that it was a bad pointer assignment problem. I replaced libsrc/c/lib/malloc.c with the alternate malloc.c that you can find in PATCHSRC.ZIP. This solved my problem. So I suggest you do the same if you have similar problems. Note that DJ added the function "calloc" to the version of malloc.c which is in the library, and that you should copy it to the replacing file, or the linker will complain about "undefined symbol _calloc" when compiling an application. J-F. *** streambu.cc Mon Mar 30 12:23:24 1992 --- libsrc/gcc/io/streambu.cc Fri Oct 2 15:47:00 1992 *************** *** 78,83 **** --- 78,84 ---- if (c == EOF) break; *s++ = c; + _gptr++; more--; } return n - more; *** streambu.h Sun Mar 29 23:19:40 1992 --- cplusinc/streambu.h Fri Oct 2 15:58:16 1992 *************** *** 14,19 **** --- 14,26 ---- // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + // + // NOTE: + // This file was modified for DOS compatibility: Flag "ios::binary" + // was defined so that file streams can be opened in binary mode. + // + // J-F Gallant, + // October 1st, 1992. #ifndef _STREAMBUF_H #define _STREAMBUF_H *************** *** 62,67 **** --- 69,75 ---- #define _IOS_TRUNC 16 #define _IOS_NOCREATE 32 #define _IOS_NOREPLACE 64 + #define _IOS_BINARY 128 #ifdef _STREAM_COMPAT enum state_value { *************** *** 73,79 **** input = _IOS_INPUT, output = _IOS_OUTPUT, atend = _IOS_ATEND, ! append = _IOS_APPEND }; #endif class ios : public _ios_fields { --- 81,88 ---- input = _IOS_INPUT, output = _IOS_OUTPUT, atend = _IOS_ATEND, ! append = _IOS_APPEND, ! binary = _IOS_BINARY }; #endif class ios : public _ios_fields { *************** *** 90,96 **** app = _IOS_APPEND, trunc = _IOS_TRUNC, nocreate = _IOS_NOCREATE, ! noreplace = _IOS_NOREPLACE }; enum seek_dir { beg, cur, end}; enum { skipws=01, left=02, right=04, internal=010, dec=020, oct=040, hex=0100, --- 99,106 ---- app = _IOS_APPEND, trunc = _IOS_TRUNC, nocreate = _IOS_NOCREATE, ! noreplace = _IOS_NOREPLACE, ! binary = _IOS_BINARY }; enum seek_dir { beg, cur, end}; enum { skipws=01, left=02, right=04, internal=010, dec=020, oct=040, hex=0100, *** filebuf.cc Mon Mar 30 12:37:42 1992 --- libsrc/gcc/io/filebuf.cc Fri Oct 2 15:50:24 1992 *************** *** 150,155 **** --- 150,157 ---- posix_mode |= O_CREAT; if (mode & (int)ios::noreplace) posix_mode |= O_EXCL; + if (mode & (int)ios::binary) + posix_mode |= O_BINARY; int fd = ::open(filename, posix_mode, prot); if (fd < 0) return NULL; -- Jean-Francois Gallant Informatique et Recherche Operationnelle Universite de Montreal email: gallant AT iro DOT umontreal DOT ca