open() file as binary - how???

Hello everybody

I'm porting a c/c++ applications from windows to linux, and I'm having problems with the open() function. I opened the files as binary in windows, but in linux I cannot do that. The O_BINARY flag does not exist...

When I started checking out why, I found a nice bit of information on the fopen() function that rocked my world...

(...)
The mode string can also include the letter ``b'' either as a last character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with C89 and has no effect; the ``b'' is ignored on all POSIX conforming systems, including Linux.
(...)

I have a quite large application and I'm having some problems because the files are opened as text and the read fails sometimes (other times it dosn't . don't know why )

Any ideas how I can give this problem a twist?

well, thanks for all the help I hope is coming my way

Andr

Comments

  • : Hello everybody
    :
    : I'm porting a c/c++ applications from windows to linux, and I'm
    : having problems with the open() function. I opened the files as
    : binary in windows, but in linux I cannot do that. The O_BINARY flag
    : does not exist...
    :
    : When I started checking out why, I found a nice bit of information
    : on the fopen() function that rocked my world...
    :
    : (...)
    : The mode string can also include the letter ``b'' either as a last
    : character or as a character between the characters in any of the
    : two-character strings described above. This is strictly for
    : compatibility with C89 and has no effect; the ``b'' is ignored on
    : all POSIX conforming systems, including Linux.
    : (...)

    The 'b' is ignored because all reads and writes are binary.
    There is no text-mode. Neither read() nor fread() do any special processing of
    or
    characters.

    :
    : I have a quite large application and I'm having some problems
    : because the files are opened as text and the read fails sometimes
    : (other times it dosn't . don't know why )
    :
    : Any ideas how I can give this problem a twist?

    There is no text-mode. Neither open() nor fopen() do any special processing of
    or
    characters. In a POSIX world, files are not opened as text.
    It's possible that some of the processing you are doing with the data [italic]is[/italic] treating control-characters specially, which may cause you a problem, but the problem you say is with read().

    If read() is failing, it is [italic]not[/italic] because of any text-mode setting - it must be for some other reason.

    Without seeing your code, it's difficult to offer much more help, but what does errno tell you?

    Try calling [bold]strerror(errno[/bold]) after the failure to see what caused the error.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion