delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/03/16/07:43:57

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Mon, 16 Mar 2009 13:43:34 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: peflags utility
Message-ID: <20090316124334.GU9322@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <49A9AA0C DOT 9020904 AT cwilson DOT fastmail DOT fm> <20090301102035 DOT GB10046 AT calimero DOT vinschen DOT de> <49AE18D8 DOT 3010009 AT cwilson DOT fastmail DOT fm> <49AE191D DOT 2000307 AT cwilson DOT fastmail DOT fm> <20090304084923 DOT GA10046 AT calimero DOT vinschen DOT de> <20090304111849 DOT GB10046 AT calimero DOT vinschen DOT de> <49AE9742 DOT 4070108 AT cwilson DOT fastmail DOT fm> <20090304152955 DOT GE10046 AT calimero DOT vinschen DOT de> <49AF4961 DOT 1020108 AT cwilson DOT fastmail DOT fm> <49BDF28C DOT 8030300 AT cwilson DOT fastmail DOT fm>
MIME-Version: 1.0
In-Reply-To: <49BDF28C.8030300@cwilson.fastmail.fm>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Mar 16 02:32, Charles Wilson wrote:
> Here's revision 3. I've revised the UI to be more like what was
> eventually accepted by binutils.  One difference is that the ld options
> allow only to set flags:
>   ld --tsaware
> 
> With peflags we can set, clear, or display them:
>   peflags --tsaware    : display
>   peflags --tsaware=1  : set
>   peflags --tsaware=0  : clear
> 
> If this is more-or-less ok, I'll get started on the peflagsall script,
> and send it all with updated docu as a patch for Jason to use in the
> next rebase release.
> 
> gcc -o peflags.exe -DVERSION='"2.4.5"' peflags.c

Looks good, except for three minor details I found.  Patch attached.

- The output is missing a trailing \n.

- Error output is missing an error description:

    $ ./peflags --tsaware=1 /bin/tcsh
    Error: could not update pe characteristics (/bin/tcsh)

  Yes, but... why?  The patch adds errno output, like this:

    $ ./peflags --tsaware=1 /bin/tcsh
    Error: could not update pe characteristics (/bin/tcsh): Device or resource busy

- The get/set characteristics function are calling close(fd) even
  if open failed.  This leads to wrong errno output after applying the
  above errno output.


Corinna


--- peflags.c.ORIG	2009-03-16 13:18:06.000000000 +0100
+++ peflags.c	2009-03-16 13:37:55.000000000 +0100
@@ -317,16 +317,16 @@ do_mark (const char *pathname)
         if (set_coff_characteristics (pathname,new_coff_characteristics) != 0)
           {
             fprintf (stderr,
-                     "Error: could not update coff characteristics (%s)\n",
-                      pathname);
+                     "Error: could not update coff characteristics (%s): %s\n",
+                      pathname, strerror (errno));
             return 1;
           }
       if (new_pe_characteristics != old_pe_characteristics)
         if (set_pe_characteristics (pathname,new_pe_characteristics) != 0)
           {
             fprintf (stderr,
-                     "Error: could not update pe characteristics (%s)\n",
-                      pathname);
+                     "Error: could not update pe characteristics (%s): %s\n",
+                      pathname, strerror (errno));
             return 1;
           }
     }
@@ -393,6 +393,7 @@ do_mark (const char *pathname)
           else
             printf ("pe(0x%04x) ", old_pe_characteristics);
         }
+      puts ("");
     }
 
   return 0;
@@ -704,7 +705,7 @@ get_characteristics(const char *pathname
 
   fd = open (pathname, O_RDONLY|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;
@@ -741,7 +742,7 @@ set_coff_characteristics(const char *pat
      get_characteristics already did that */
   fd = open (pathname, O_RDWR|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;
@@ -774,7 +775,7 @@ set_pe_characteristics(const char *pathn
      get_characteristics already did that */
   fd = open (pathname, O_RDWR|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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