[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Text tools, line endings, and O_TEXT
From: |
Eric Blake |
Subject: |
Re: Text tools, line endings, and O_TEXT |
Date: |
Thu, 6 Sep 2007 16:27:08 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
John Cowan <cowan <at> ccil.org> writes:
> Are you saying that an O_TEXT open under Cygwin, given a binary mount,
> will cause newline translation? I had assumed that O_TEXT would be
> ignored under Cygwin just as it is under Linux.
Yes. The cygwin behavior is as follows:
open(O_RDONLY), fopen("r") - open the file using the mount point rules to
decide whether the file is text or binary
open(O_RDONLY|O_BINARY), fopen("rb") - open the file forced in binary,
regardless of mount point
open(O_RDONLY|O_TEXT), fopen("rt") - open the file forced in text, regardless
of mount point
pipe() - create pipe with mode determined by CYGWIN env variable (default setup
is binary, but if $CYGWIN includes "nobinmode", pipe becomes binary)
binary mode reads the file as is, text mode strips all \r and ends the file at
the first ^z.
freopen(NULL, mode, stream) - works to swap existing mode of an open fd-based
stream between text and binary (but currently fails on special streams, such as
from fmemopen)
#include <io.h>
setmode(fd, <0, O_BINARY, or O_TEXT>) - works to swap existing mode of an open
fd, as well as any open stream based on that fd (using 0 restores mount point
default mode)
>
> That said, I believe it is good for portability to use O_TEXT
> and O_BINARY (and their stdio equivalents) in all software intended
> to be portable.
Using O_BINARY is important, however, I claim that using O_TEXT in portable
code should be a very rare circumstance. There's a reason that C99 only calls
out fopen("r") and fopen("rb"), but not fopen("rt").
--
Eric Blake
- Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Graig, 2007/09/05
- Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Bob Proulx, 2007/09/05
- Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, John Cowan, 2007/09/05
- Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Bob Proulx, 2007/09/06
- Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Eric Blake, 2007/09/06
- Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Jim Meyering, 2007/09/06
- Text tools, line endings, and O_TEXT, John Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT,
Eric Blake <=
- Re: Text tools, line endings, and O_TEXT, Micah Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, Eric Blake, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, John Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, Eric Blake, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, John Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, Micah Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, John Cowan, 2007/09/06
- Re: Text tools, line endings, and O_TEXT, Bob Proulx, 2007/09/06
Re: Problem with -i ignore-file option in version 6.9 ptx in cygwin environment, Jim Meyering, 2007/09/06