delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/06/03/09:49:50

From: colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters)
Subject: RE: fread/fwrite problems in b18
3 Jun 1997 09:49:50 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <01BC7027.115BDE00.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Original-To: "'Bala Amavasai'" <B DOT Amavasai AT sheffield DOT ac DOT uk>
Original-Cc: "'GNU-Win32'" <gnu-win32 AT cygnus DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by cygnus.com id WAA10108
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Bala Amavasai[SMTP:B DOT Amavasai AT sheffield DOT ac DOT uk] wrote:
>Hi! I wonder if anyone can help.  I've written a short program to remove a
>fix sized header (of 512 bytes) from a raw image file. However when I
>compile it and run under gcc b18, I do not get the output I expect. That
>is the output file size is always 30 bytes. The same code compiles and
>works perfectly in Solaris 2.4 and Linux 2.0.27. The truncated version of
>the code is fowarded below.

See below, it's a binary vs. text problem.

>Another problem which I'm facing is that when I allocate a large array,
>say 1000x1000 and when I read and write data to/off it, I get junk towards
>1/4 way into the array. Once again the same code works very well in the
>platforms above. Is there a problem with memory allocation? I'll send a
>truncated piece of code later, unless the problem has been previously
>logged. 

I've never heard of this and would be interested to know the specifics.

>        /* image file */
>        if ((infile=fopen(argv[1],"r"))==NULL)
Change to fopen(argv[1],"rb"). Files are opened by default in text mode, which is, unfortunately, not the same as binary on win32 machines (and yes there has been a lot of arguing back and forth about what GNU-Win32 should do about it). If you open your files in binary mode then it should work on both UNIX and Win32.

>        /* create temp file */
>        if ((outfile=fopen("outfile","w"))==NULL)
Change to fopen("outfile","wb") as above.

-- Colin Peters - colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019