delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/02/28/03:01:49

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
X-Authentication-Warning: modi.xraylith.wisc.edu: khan owned process doing -bs
Date: Sun, 28 Feb 1999 02:00:51 -0600 (CST)
From: Mumit Khan <khan AT xraylith DOT wisc DOT edu>
To: "Pierre A. Humblet" <Pierre DOT Humblet AT eurecom DOT fr>
cc: bug-gnu-utils AT gnu DOT org, cygwin AT sourceware DOT cygnus DOT com
Subject: Re: bug in strip 2.9.4
In-Reply-To: <3.0.5.32.19990227183336.00812600@pop.ne.mediaone.net>
Message-ID: <Pine.SUN.3.93.990228014948.11378A-100000@modi.xraylith.wisc.edu>
MIME-Version: 1.0

On Sat, 27 Feb 1999, Pierre A. Humblet wrote:

> strip 2.9.4 in Binutils-2.9 has a bug when stripping a file accessed through a link, on systems that open files by default in text mode (such as cygwin).
> The new executable file has an incorrect length.
> 
> I believe the bug occurs in the file binutils/objcopy.c, in the function 
> simple_copy. The open() and creat() below will open in text mode and the
> copy won't be properly executed for binary files.
> 
>   fromfd = open (from, O_RDONLY);
>   if (fromfd < 0)
>     return -1;
>   tofd = creat (to, 0777);
> 

Good catch. We could do something like the following:
  
  int flags = O_RDONLY;
#ifdef O_BINARY
  flags |= O_BINARY;
#endif
  fromfd = open (from, flags);
  if (fromfd < 0)
    return -1;
  tofd = creat (to, 0777);

As you note, we also need to handle the descriptor returned by creat 
(which is somewhat equiv to open'ing with a few flags -- O_CREAT | 
O_TRUNC | O_WRONLY).

How about just using setmode on both the descriptors? Would that work?

  fromfd = open (from, O_RDONLY);
  if (fromfd < 0)
    return -1;
  tofd = creat (to, 0777);
#if _WIN32
  setmode (fromfd, O_BINARY);
  setmode (tofd, O_BINARY);
#endif

Regards,
Mumit



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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