From bug-request at octave dot org Mon Dec 20 08:44:37 2004 Subject: RE: Possible Error in -ascii save/restore From: To: Cc: Date: Mon, 20 Dec 2004 02:29:04 -0600 John, I've been looking around the http://Cygwin.com site to try to find some way to report this, but there doesn't seam to be an easy way unless you are a developer yourself. However I found this in the FAQ: http://cygwin.com/faq.html ------- How is the DOS/Unix CR/LF thing handled? Let's start with some background. In UNIX, a file is a file and what the file contains is whatever the program/programmer/user told it to put into it. In Windows, a file is also a file and what the file contains depends not only on the program/programmer/user but also the file processing mode. When processing in text mode, certain values of data are treated specially. A \n (new line) written to the file will prepend a \r (carriage return) so that if you `printf("Hello\n") you in fact get "Hello\r\n". Upon reading this combination, the \r is removed and the number of bytes returned by the read is 1 less than was actually read. This tends to confuse programs dependent on ftell() and fseek(). A Ctrl-Z encountered while reading a file sets the End Of File flags even though it truly isn't the end of file. One of Cygwin's goals is to make it possible to easily mix Cygwin-ported Unix programs with generic Windows programs. As a result, Cygwin opens files in text mode as is normal under Windows. In the accompanying tools, tools that deal with binaries (e.g. objdump) operate in Unix binary mode and tools that deal with text files (e.g. bash) operate in text mode. Some people push the notion of globally setting the default processing mode to binary via mount point options or by setting the CYGWIN environment variable. But that creates a different problem. In binary mode, the program receives all of the data in the file, including a \r. Since the programs will no longer deal with these properly for you, you would have to remove the \r from the relevant text files, especially scripts and startup resource files. This is a porter "cop out", forcing the user to deal with the \r for the porter. It is rather easy for the porter to fix the source code by supplying the appropriate file processing mode switches to the open/fopen functions. Treat all text files as text and treat all binary files as binary. To be specific, you can select binary mode by adding O_BINARY to the second argument of an open call, or "b" to second argument of an fopen call. You can also call setmode (fd, O_BINARY). Note that because the open/fopen switches are defined by ANSI, they exist under most flavors of Unix; open/fopen will just ignore the switch since they have no meaning to UNIX. Explanation adapted from mailing list email by Earnie Boyd . ------------ To a non programmer it looks like this says, "the porter should deal with this problem". -- Regards Hallvard ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------