Menu

#230 Tcl_(FS)OpenFileChannel and 'rb'

closed-accepted
None
5
2005-04-27
2002-07-03
No

The standard 'fopen()' C function allows the
optional "b" mode specifier alongside "rwa+" to
specify that the file to be opened is binary.

Tcl's Tcl_(FS)OpenFileChannel commands do not
support "b" and throw an error if it is given. It
would be quite easy to parse out the "b" and do call
Tcl_SetChannelOption(NULL, chan, "-
translation", "binary") after the channel is opened.

Should this be added to Tcl?

I don't know enough about generic channels in Tcl
to know if it is possible for that action to fail or
otherwise cause problems (bear in mind that, with
VFS, the channel may not be a file, but could be a
memchan, for example).

Discussion

  • Andreas Kupries

    Andreas Kupries - 2002-07-03
    • summary: Tcl_(FS)OpenFileChannel and "rb" --> Tcl_(FS)OpenFileChannel and "rb"
     
  • Andreas Kupries

    Andreas Kupries - 2002-07-03

    Logged In: YES
    user_id=75003

    What is the behaviour of 8.3 when using a "b" specifier ?
    If it is the same I would consider this a feature request, and
    not a bug.

     
  • Vince Darley

    Vince Darley - 2002-07-04
    • labels: 104242 -->
    • summary: Tcl_(FS)OpenFileChannel and "rb" --> Tcl_(FS)OpenFileChannel and "rb"
    • assigned_to: andreas_kupries --> nobody
    • milestone: 187914 -->
     
  • Vince Darley

    Vince Darley - 2002-07-04

    Logged In: YES
    user_id=32170

    The behaviour hasn't changed since 8.3, so I guess this
    is indeed a feature request. One could even imagine a
    hookable mechanism in the future which allowed other
    (arbitrary) actions to be taken on open. (Set
    the 'encoding' automatically might be nice, then
    perhaps 'source' could deal with unicode files).

     
  • Donal K. Fellows

    • summary: Tcl_(FS)OpenFileChannel and "rb" --> Tcl_(FS)OpenFileChannel and 'rb'
     
  • Don Porter

    Don Porter - 2003-11-12
    • assigned_to: nobody --> vincentdarley
     
  • Don Porter

    Don Porter - 2005-03-23

    Logged In: YES
    user_id=80530

    This is TIP 183.

     
  • Don Porter

    Don Porter - 2005-03-24

    Logged In: YES
    user_id=80530

    Actually this is a bit different from
    TIP 183, which proposes the change
    only for [open]. That's simpler to do
    than changing for Tcl_FSOpenFileChannel()
    since the latter raises questions about
    what changes each Tcl_Filesystem's
    Tcl_FSOpenFileChannelProc might
    have to handle in its "mode" argument.

     
  • Don Porter

    Don Porter - 2005-03-31

    Logged In: YES
    user_id=80530

    Turns out doing this at the
    Tcl_FSOpenFileChannel() level
    works fine, and spares the VFS
    drivers from having to do anything.
    Here's the patch.

     
  • Vince Darley

    Vince Darley - 2005-04-01

    Logged In: YES
    user_id=32170

    I haven't had time to test right now, but the patch itself
    looks nice and clean.

    It would be good to add a new test which writes some stuff
    to a file in binary and then reads it back and check that \r
    \n line endings have not been mangled.

     
  • Don Porter

    Don Porter - 2005-04-27

    Logged In: YES
    user_id=80530

    Updated patch contains docs and tests.

     
  • Don Porter

    Don Porter - 2005-04-27

    Logged In: YES
    user_id=80530

    correction.

     
  • Don Porter

    Don Porter - 2005-04-27
     
  • Don Porter

    Don Porter - 2005-04-27

    Logged In: YES
    user_id=80530

    Committed for Tcl 8.5a3

     
  • Don Porter

    Don Porter - 2005-04-27
    • assigned_to: vincentdarley --> dgp
    • status: open --> closed-accepted