diff --git a/winsup/doc/ChangeLog b/winsup/doc/ChangeLog index fcb066428..4754d53e2 100644 --- a/winsup/doc/ChangeLog +++ b/winsup/doc/ChangeLog @@ -1,3 +1,11 @@ +2009-03-18 Corinna Vinschen + + * overview2.sgml: Remove reference to CYGWIN=binmode. + * textbinary.sgml: Ditto. Rephrase certain paragraphs to match + Cygwin 1.7 behaviour. Add popen(3) and pipe(2) behaviour. Make + quite clear that binmode is preferred. Add *mode.o files to + description for developers. + 2009-03-09 Corinna Vinschen * pathnames.sgml: Try to be more clear explain raw devices. diff --git a/winsup/doc/overview2.sgml b/winsup/doc/overview2.sgml index 203e32578..220cf1acb 100644 --- a/winsup/doc/overview2.sgml +++ b/winsup/doc/overview2.sgml @@ -245,7 +245,7 @@ Win32 paths containing drive letter and/or backslashes as well as UNC paths Text Mode vs. Binary Mode Interoperability with other Win32 programs such as text editors was -critical to the success of the port of the development tools. Most Red Hat +critical to the success in the early days of Cygwin. Most Red Hat customers upgrading from the older DOS-hosted toolchains expected the new Win32-hosted ones to continue to work with their old development sources. @@ -258,8 +258,8 @@ the fly by Cygwin into a single newline when reading in text mode. violating the POSIX standard that states that text and binary mode will be identical. Consequently, processes that attempt to lseek through text files can no longer rely on the number of bytes read as an accurate indicator of position -in the file. For this reason, the CYGWIN environment variable can be -set to override this behavior. +in the file. For this reason, Cygwin allows to choose the mode in which to +read a file in several ways. ANSI C Library diff --git a/winsup/doc/textbinary.sgml b/winsup/doc/textbinary.sgml index 674c39ef2..055a5e012 100644 --- a/winsup/doc/textbinary.sgml +++ b/winsup/doc/textbinary.sgml @@ -33,6 +33,7 @@ other programs (such as cat, cmp, The Cygwin system gives us some flexibility in deciding how files are to be opened when the mode is not specified explicitly. The rules are evolving, this section gives the design goals. + If the filename is specified as a POSIX path and it appears to @@ -41,22 +42,28 @@ with a directory displayed by mount), then the default is specified by the mount flag. If the file is a symbolic link, the mode of the target file system applies. + If the file is specified via a MS-DOS pathname (i.e., it contains a backslash or a colon), the default is binary. + -Pipes and non-file devices are opened in binary mode, -except if the CYGWIN environment variable contains -nobinmode. Sockets are always opened in binary -mode. +Pipes, sockets and non-file devices are opened in binary mode. +For pipes opened through the pipe() system call you can use the setmode() +function (see to switch to textmode. +For pipes opened through popen(), you can simply specify text or binary +mode just like in calls to fopen(). - When redirecting, the Cygwin shells uses rules (a-e). For -these shells the relevant value of CYGWIN is that at the time -the shell was launched and not that at the time the program is executed. +Sockets and other non-file devices are always opened in binary mode. + + + + + When redirecting, the Cygwin shells uses rules (a-d). Non-Cygwin shells always pipe and redirect with binary mode. With non-Cygwin shells the commands cat filename | program and program < filename are not equivalent when @@ -94,9 +101,8 @@ REM Remove \r from the file given as argument tr -d \r < %1 > %1.nocr ]]> - work fine. In the first case (assuming the pipes are binary) -we rely on gunzip to set its output to binary mode, -possibly overriding the mode used by the shell. + work fine. In the first case we rely on gunzip to +set its output to binary mode, possibly overriding the mode used by the shell. In the second case we rely on the DOS shell to redirect in binary mode. @@ -105,34 +111,28 @@ In the second case we rely on the DOS shell to redirect in binary mode. UNIX programs that have been written for maximum portability will know the difference between text and binary files and act -appropriately under Cygwin. For those programs, the text mode default -is a good choice. Programs included in official Cygwin distributions -should work well in the default mode. +appropriately under Cygwin. Most programs included in the official +Cygwin distributions should work well in the default mode. -Text mode makes it much easier to mix files between Cygwin and -Windows programs, since Windows programs will usually use the CRLF -format. Unfortunately you may still have some problems with text -mode. First, some of the utilities included with Cygwin do not yet -specify binary mode when they should. -Second, you will introduce CRs in text -files you write, which can cause problems when moving them back to a -UNIX system. +Binmode is the best choice usually since it's faster and +easier to handle, unless you want to exchange files with native Win32 +applications. It makes most sense to keep the Cygwin distribution +and your Cygwin home directory in binmode and generate text files in +binmode (with UNIX LF lineendings). Most Windows applications can +handle binmode files just fine. A notable exception is the mini-editor +Notepad, which handles UNIX lineendings incorrectly +and only produces output files with DOS CRLF lineendings. -If you are mounting a remote file system from a UNIX machine, -or moving files back and forth to a UNIX machine, you may want to -access the files in binary mode. The text files found there will normally -be in UNIX NL format, and you would want any files put there by Cygwin -programs to be stored in a format understood by UNIX. -Be sure to remove CRs from all Makefiles and -shell scripts and make sure that you only edit the files with -DOS/Windows editors that can cope with and preserve NL terminated lines. - +You can convert files between CRLF and LF lineendings by using +certain tools in the Cygwin distribution like d2u and +u2d from the cygutils package. You can also specify +a directory in the mount table to be mounted in textmode so you can use +that directory for exchange purposes. -Note that you can decide this on a disk by disk basis (for -example, mounting local disks in text mode and network disks in binary -mode). You can also partition a disk, for example by mounting -c: in text mode, and c:\home -in binary mode. +As application programmer you can decide on a file by file base, +or you can specify default open modes depending on the purpose for which +the application open files. See the next section for a description of +your choices. @@ -143,9 +143,10 @@ specified with the flag O_BINARY and text mode with O_TEXT. These symbols are defined in fcntl.h. -In the fopen() function call, binary mode can be -specified by adding a b to the mode string. Text mode is specified -by adding a t to the mode string. +In the fopen() and popen() +function calls, binary mode can be specified by adding a b +to the mode string. Text mode is specified by adding a t +to the mode string. The mode of a file can be changed by the call setmode(fd,mode) where fd is a file @@ -154,6 +155,55 @@ descriptor (an integer) and mode is returns O_BINARY or O_TEXT depending on the mode before the call, and EOF on error. +There's also a convenient way to set the default open modes used +in an application by just linking against various object files provided +by Cygwin. For instance, if you want to make sure that all files are +always opened in binary mode by an application, regardless of the mode +of the underlying mount point, just add the file +/lib/binmode.o to the link stage of the application +in your project, like this: + + + $ gcc my_tiny_app.c /lib/binmode.o -o my_tiny_app + + +This adds code which sets the default open mode for all files +opened by my_tiny_app to binary for reading and +writing. + +Cygwin provides the following object files to set the default open mode +just by linking an application against them: + + + + + +/lib/automode.o - Open files for reading in textmode + Open files for writing in binary mode + + + + + +/lib/binmode.o - Open files for reading and writing in binary mode + + + + + +/lib/textmode.o - Open files for reading and writing in textmode + + + + + +/lib/textreadmode.o - Open files for reading in textmode + Keep default behaviour for writing. + + + + +