Loading ...
Sorry, an error occurred while loading the content.

xxd on cygwin - text vs binary mode

Expand Messages
  • Andrej Borsenkow
    The purpose of xxd should be to examine raw contents of the file. Unfortunately, under Cygwin it does not force binary mode on opens that rresults in incorrect
    Message 1 of 9 , Oct 18, 2000
    • 0 Attachment
      The purpose of xxd should be to examine raw contents of the file.
      Unfortunately, under Cygwin it does not force binary mode on opens that
      rresults in incorrect display (and, possibly, writeback):

      mw1g017@MW1G17C% ll /cygdrive/c/foo
      -rw-r--r-- 1 mw1g017 ITS 6 Oct 18 18:43 /cygdrive/c/foo
      mw1g017@MW1G17C% xxd /cygdrive/c/foo
      0000000: 3132 3334 0a 1234.

      The foo has CR-LF line ending, bur xxd believes it is just LF.

      This is xxd from official Cygwin vim package.

      What do you think?

      -andrej

      Have a nice DOS!
      B >>
    • Bram Moolenaar
      ... xxd should read the file in binary mode. If you look in the source file, you can see that it tries to do this. Apperently it doesn t work for cygwin. So
      Message 2 of 9 , Oct 18, 2000
      • 0 Attachment
        Andrej Borsenkow wrote:

        > The purpose of xxd should be to examine raw contents of the file.
        > Unfortunately, under Cygwin it does not force binary mode on opens that
        > rresults in incorrect display (and, possibly, writeback):
        >
        > mw1g017@MW1G17C% ll /cygdrive/c/foo
        > -rw-r--r-- 1 mw1g017 ITS 6 Oct 18 18:43 /cygdrive/c/foo
        > mw1g017@MW1G17C% xxd /cygdrive/c/foo
        > 0000000: 3132 3334 0a 1234.
        >
        > The foo has CR-LF line ending, bur xxd believes it is just LF.
        >
        > This is xxd from official Cygwin vim package.
        >
        > What do you think?

        xxd should read the file in binary mode. If you look in the source file, you
        can see that it tries to do this. Apperently it doesn't work for cygwin.

        So how do you open a file in binary mode on cygwin?

        --
        FIRST GUARD: Ah! Now ... we're not allowed to ...
        SIR LAUNCELOT runs him through, grabs his spear and stabs the other
        guard who collapses in a heap. Hiccoughs quietly.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
        \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
      • raf
        ... are your drives mounted as text or binary? this might be causing it. ... in the standard ansi fashion but xxd might get it wrong. it only uses fopen(...,
        Message 3 of 9 , Oct 18, 2000
        • 0 Attachment
          Bram Moolenaar wrote:

          >
          > Andrej Borsenkow wrote:
          >
          > > The purpose of xxd should be to examine raw contents of the file.
          > > Unfortunately, under Cygwin it does not force binary mode on opens that
          > > rresults in incorrect display (and, possibly, writeback):
          > >
          > > mw1g017@MW1G17C% ll /cygdrive/c/foo
          > > -rw-r--r-- 1 mw1g017 ITS 6 Oct 18 18:43 /cygdrive/c/foo
          > > mw1g017@MW1G17C% xxd /cygdrive/c/foo
          > > 0000000: 3132 3334 0a 1234.
          > >
          > > The foo has CR-LF line ending, bur xxd believes it is just LF.

          are your drives mounted as text or binary?
          this might be causing it.

          > > This is xxd from official Cygwin vim package.
          > >
          > > What do you think?
          >
          > xxd should read the file in binary mode. If you look in the source file, you
          > can see that it tries to do this. Apperently it doesn't work for cygwin.
          >
          > So how do you open a file in binary mode on cygwin?

          in the standard ansi fashion but xxd might get it wrong.
          it only uses fopen(..., "rb") if defined(MSDOS) ||
          defined(WIN32) || defined(OS2). CYGWIN32/CYGWIN is missing.
          so maybe it thinks it's unix and doesn't bother adding the "b".
          mind you, it doesn't seem to matter. i just checked my cygwin xxd
          and it works fine (maybe because my drives are mounted binary):

          http://www.zip.com.au/~raf2/vim/

          if that doesn't work, and you have text mounted drives,
          and you want to keep it that way, try the following patch:

          --- xxd.c.orig Thu Oct 19 11:30:48 2000
          +++ xxd.c Thu Oct 19 11:32:25 2000
          @@ -134,12 +134,16 @@ char osver[] = "";
          # endif
          #endif

          -#if defined(MSDOS) || defined(WIN32) || defined(OS2)
          +#if defined(MSDOS) || defined(WIN32) || defined(OS2) || defined(CYGWIN) || defined(CYGWIN32)
          # define BIN_READ(yes) ((yes) ? "rb" : "rt")
          # define BIN_WRITE(yes) ((yes) ? "wb" : "wt")
          # define BIN_CREAT(yes) ((yes) ? (O_CREAT|O_BINARY) : O_CREAT)
          # define BIN_ASSIGN(fp, yes) setmode(fileno(fp), (yes) ? O_BINARY : O_TEXT)
          -# define PATH_SEP '\\'
          +# if defined(CYGWIN) || defined(CYGWIN32)
          +# define PATH_SEP '/'
          +# else
          +# define PATH_SEP '\\'
          +# endif
          #else
          # ifdef VMS
          # define BIN_READ(dummy) "r"

          raf
        • Pablo Ariel Kohan (a.k.a. merKur)
          ... I ve been beaten by this some years ago, while cross-developing on Unix and NT. The default as per M$, for file opens is text-mode, so you have to use rb
          Message 4 of 9 , Oct 18, 2000
          • 0 Attachment
            Bram Moolenaar wrote:

            > So how do you open a file in binary mode on cygwin?

            I've been beaten by this some years ago, while cross-developing on Unix
            and NT.
            The default as per M$, for file opens is text-mode, so you have to use
            "rb" or "wb" for it to be binary...

            Not bad for a "Posix-compliant" OS, eh ? :)

            --
            ©2000 Pablo Ariel Kohan | All opinions expressed herein are my own,
            ---------------------------+ and not my employer's, unless explicitly
            mailto:pablo@... | stated. Permission hereby granted for use
            http://Surf.To/PKohan | in follow-up articles, FAQ's and digests.
          • raf
            ... i think you have to blame the influence of dos on ansi c :( raf
            Message 5 of 9 , Oct 18, 2000
            • 0 Attachment
              Pablo Ariel Kohan (a.k.a. merKur) wrote:

              > Bram Moolenaar wrote:
              >
              > > So how do you open a file in binary mode on cygwin?
              >
              > I've been beaten by this some years ago, while cross-developing on Unix
              > and NT.
              > The default as per M$, for file opens is text-mode, so you have to use
              > "rb" or "wb" for it to be binary...
              >
              > Not bad for a "Posix-compliant" OS, eh ? :)

              i think you have to blame the influence of dos on ansi c :(

              raf
            • Andrej Borsenkow
              ... In this particular case it is text mode. ... Ah! That s it! Thank you! -andrej
              Message 6 of 9 , Oct 18, 2000
              • 0 Attachment
                >
                > Bram Moolenaar wrote:
                >
                > >
                > > Andrej Borsenkow wrote:
                > >
                > > > The purpose of xxd should be to examine raw contents of the file.
                > > > Unfortunately, under Cygwin it does not force binary mode on opens that
                > > > rresults in incorrect display (and, possibly, writeback):
                > > >
                > > > mw1g017@MW1G17C% ll /cygdrive/c/foo
                > > > -rw-r--r-- 1 mw1g017 ITS 6 Oct 18 18:43 /cygdrive/c/foo
                > > > mw1g017@MW1G17C% xxd /cygdrive/c/foo
                > > > 0000000: 3132 3334 0a 1234.
                > > >
                > > > The foo has CR-LF line ending, bur xxd believes it is just LF.
                >
                > are your drives mounted as text or binary?
                > this might be causing it.
                >

                In this particular case it is text mode.

                > > > This is xxd from official Cygwin vim package.
                > > >
                > > > What do you think?
                > >
                > > xxd should read the file in binary mode. If you look in the
                > source file, you
                > > can see that it tries to do this. Apperently it doesn't work for cygwin.
                > >
                > > So how do you open a file in binary mode on cygwin?
                >
                > in the standard ansi fashion but xxd might get it wrong.
                > it only uses fopen(..., "rb") if defined(MSDOS) ||
                > defined(WIN32) || defined(OS2). CYGWIN32/CYGWIN is missing.
                > so maybe it thinks it's unix and doesn't bother adding the "b".
                > mind you, it doesn't seem to matter. i just checked my cygwin xxd
                > and it works fine (maybe because my drives are mounted binary):
                >

                Ah! That's it! Thank you!

                -andrej
              • Craig Barkhouse
                ... Out of curiosity, is there any reason not to just use rb irrespective of platform? It is portable C, and should work everywhere.
                Message 7 of 9 , Oct 19, 2000
                • 0 Attachment
                  > > it only uses fopen(..., "rb") if defined(MSDOS) ||
                  > > defined(WIN32) || defined(OS2).

                  Out of curiosity, is there any reason not to just use "rb" irrespective of
                  platform? It is portable C, and should work everywhere.
                • raf
                  ... i agree but not everyone has an ansi compiler. i think they should get one, though :) raf
                  Message 8 of 9 , Oct 19, 2000
                  • 0 Attachment
                    Craig Barkhouse wrote:

                    > > > it only uses fopen(..., "rb") if defined(MSDOS) ||
                    > > > defined(WIN32) || defined(OS2).
                    >
                    > Out of curiosity, is there any reason not to just use "rb" irrespective of
                    > platform? It is portable C, and should work everywhere.

                    i agree but not everyone has an ansi compiler.
                    i think they should get one, though :)

                    raf
                  • Bram Moolenaar
                    ... Some older compilers/libraries won t accept this. My manpage says that b is an ISO C thing, thus compilers that don t confirm to this may generate an
                    Message 9 of 9 , Oct 20, 2000
                    • 0 Attachment
                      Craig Barkhouse wrote:

                      > > > it only uses fopen(..., "rb") if defined(MSDOS) ||
                      > > > defined(WIN32) || defined(OS2).
                      >
                      > Out of curiosity, is there any reason not to just use "rb" irrespective of
                      > platform? It is portable C, and should work everywhere.

                      Some older compilers/libraries won't accept this. My manpage says that "b" is
                      an ISO C thing, thus compilers that don't confirm to this may generate an
                      error.

                      --
                      ARTHUR: Well, I can't just call you `Man'.
                      DENNIS: Well, you could say `Dennis'.
                      ARTHUR: Well, I didn't know you were called `Dennis.'
                      DENNIS: Well, you didn't bother to find out, did you?
                      The Quest for the Holy Grail (Monty Python)

                      /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
                      \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
                    Your message has been successfully submitted and would be delivered to recipients shortly.