This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Gas vs irregular files


Hi Andreas,

>>   Error: can't open <name-of-directory> for reading
>>   <name-of-directory>: No error
>
> But only because the handling of errno is flawed.  as_bad makes
> library calls that may alter errno, so the original value is lost
> when as_perror is called.

Are you sure ?  Which library calls ?  [I am assuming that fprintf and
friends do not set errno.  Is this correct ?]

> This continues to be a problem even with your patch, because
> as_perror is also broken in this regard.

I think that the real problem is that as_perror() uses the bfd error
number in preference to errno if BFD_ASSEMBLER is defined.  So I would
like to offer the following patch to fix this behaviour and to
simplify the code in input_file_open() as a result.

What do you think ?

Cheers
        Nick
        
2003-12-19  Nick Clifton  <nickc@redhat.com>

	* messages.c (as_perror): (For BFD_ASSEMBLER:) if no bfd error
	has been set, then use errno instead.
	* input-scrub.c (input_file_open): (For BFD_ASSEMBLER:) reset
	the bfd error value before performing system calls.
        Simplify the error reporting code to just use as_perror().

Index: gas/messages.c
===================================================================
RCS file: /cvs/src/src/gas/messages.c,v
retrieving revision 1.7
diff -c -3 -p -r1.7 messages.c
*** gas/messages.c	24 Nov 2003 17:52:33 -0000	1.7
--- gas/messages.c	19 Dec 2003 09:47:35 -0000
*************** as_perror (const char *gripe,		/* Unpunc
*** 147,157 ****
  
    as_show_where ();
    fprintf (stderr, gripe, filename);
  #ifdef BFD_ASSEMBLER
!   errtxt = bfd_errmsg (bfd_get_error ());
! #else
!   errtxt = xstrerror (errno);
  #endif
    fprintf (stderr, ": %s\n", errtxt);
    errno = 0;
  #ifdef BFD_ASSEMBLER
--- 147,160 ----
  
    as_show_where ();
    fprintf (stderr, gripe, filename);
+ 
  #ifdef BFD_ASSEMBLER
!   if (bfd_get_error () != bfd_error_no_error)
!     errtxt = bfd_errmsg (bfd_get_error ());
!   else
  #endif
+     errtxt = xstrerror (errno);
+ 
    fprintf (stderr, ": %s\n", errtxt);
    errno = 0;
  #ifdef BFD_ASSEMBLER

Index: gas/input-file.c
===================================================================
RCS file: /cvs/src/src/gas/input-file.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 input-file.c
*** gas/input-file.c	18 Dec 2003 18:03:08 -0000	1.14
--- gas/input-file.c	19 Dec 2003 09:47:35 -0000
*************** input_file_open (char *filename, /* "" m
*** 132,137 ****
--- 132,140 ----
  
    preprocess = pre;
  
+ #ifdef BFD_ASSEMBLER
+   bfd_set_error (bfd_error_no_error);
+ #endif
    assert (filename != 0);	/* Filename may not be NULL.  */
    if (filename[0])
      {
*************** input_file_open (char *filename, /* "" m
*** 151,168 ****
  
    if (f_in == NULL || ferror (f_in))
      {
!       switch (errno)
! 	{
! 	case ENOENT:
! 	  as_bad (_("%s: no such file"), filename);
! 	  break;
! 	case EISDIR:
! 	  as_bad (_("%s: is a directory"), filename);
! 	  break;
! 	default:
!           as_bad (_("can't open %s for reading"), file_name);
!           as_perror ("%s", file_name);
!         }
  
        if (f_in)
  	{
--- 154,160 ----
  
    if (f_in == NULL || ferror (f_in))
      {
!       as_perror (_("Can't open %s for reading"), file_name);
  
        if (f_in)
  	{


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]