[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

text vs. binary [Re: more gcc warnings]

From: Eric Blake
Subject: text vs. binary [Re: more gcc warnings]
Date: Mon, 11 Jul 2005 20:41:32 +0000

> I've been putting off cleaning up this mess, but I found the time this
> weekend to give it a start.  I installed the following patch.  It
> avoids the use of setmode and <io.h> entirely, and it cleans up some
> of the inconsistencies in the code (in some cases, they were bugs that
> even infected the GNU/Linux version -- ouch!).

Thanks for starting this task.

> Since I don't use DOS, someone with some expertise in that area will
> have to double-check it.

I'm willing to check it on cygwin.  This is a partial review, I will probably
have more comments as I get more time to actually comple and test
some of the changes.  It would also be nice if someone could give anon
CVS a kick; it has been stuck since the 5th.

I would also like to compare your work to my email on the subject a
couple of months ago:

> I dislike all that isatty stuff -- is there some way that we could
> easily remove it from the mainline sources, and put it in config.h or
> somewhere we we don't have to see it?  For example, can we replace this:
>   if (O_BINARY && ! isatty (STDIN_FILENO))
>     freopen (NULL, "rb", stdin);
> with this:
>   if (O_BINARY)
>     freopen (NULL, "rb", stdin);

Sounds like a good candidate for a gnulib module.  Also, I've thought
more about fcntl(fd, F_SETFL, flags), where the nice gnulib behavior
would be:
neither O_BINARY nor O_TEXT: leave mode unchanged
O_BINARY: if not tty, force binary mode
O_TEXT: if not tty, force text mode
O_BINARY | O_TEXT: if not tty, swap mode

> and have a wrapper on MS-DOS that defines freopen to not do anything
> if the first argument is NULL, the second ends in "b", and the third a
> standard tty?

Since POSIX states that "w+b" and "wb+" are synonyms, for example,
we should be a little more careful than just checking for ends in 'b'.  Or
is there a coding style that states which of the two we should prefer?

> Index: src/cat.c
> @@ -553,9 +543,6 @@ main (int argc, char **argv)
>      {"show-ends", no_argument, NULL, 'E'},
>      {"show-tabs", no_argument, NULL, 'T'},
>      {"show-all", no_argument, NULL, 'A'},
> -#if O_BINARY
> -    {"binary", no_argument, NULL, 'B'},
> -#endif

I'd like to see a deprecation period rather than outright removal,
where -B is undocumented, and using it evokes a warning but
is otherwise a no-op (rather than a fatal unrecognized option).

> Index: src/tac.c
> Index: src/tee.c
> @@ -140,7 +140,10 @@ tee (int nfiles, const char **files)
>    ssize_t bytes_read;
>    int i;
>    bool ok = true;
> -  const char *mode_string = (append ? "a" : "w");
> +  char const *mode_string =
> +    (O_BINARY
> +     ? (append ? "ab" : "wb")
> +     : (append ? "a" : "w"));

Are there non-standard hosts out there that don't treat "ab" as
a synonym to "a" per POSIX, and if so, should we cater to them
with a gnulib module?  It is much more readable to write this as:

char const *mode_string = (append ? "ab" : "wb");

Eric Blake

reply via email to

[Prev in Thread] Current Thread [Next in Thread]