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 Ian,

> On those systems where fopen() of a directory will succeed, I still 
> don't see any reason why we need to have the assembler check for it.
> It's no different than running the assembler on any other file which
> happens to not be an assembler source file.  No special harm will be
> done by trying to assemble a directory.  The user will just get an
> error message.  I don't see any reason to make the assembler watch out
> for a rather unlikely error case, when that error case will not cause
> any significant damage.

Ok then, how about this patch ?  It removes the call to stat() and adds
a code to detect an for an attempt to read a directory, but only if
the read of the first character in the file fails.  I think that this
extra check is helpful, since otherwise an attempt to assemble a
directory would produce these error messages (on a RH9 box anyway):

  Error: can't open <name-of-directory> for reading
  <name-of-directory>: No error

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

	* input-file.c (input_file_open): Remove call to stat().
        Add a check for getc() failing, and catch the case where the
        failure is due to an attempt to read a directory.

Index: input-file.c
===================================================================
RCS file: /cvs/src/src/gas/input-file.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 input-file.c
*** input-file.c	24 Nov 2003 03:37:58 -0000	1.13
--- input-file.c	18 Dec 2003 11:02:29 -0000
***************
*** 26,32 ****
  
  #include <stdio.h>
  #include <string.h>
! #include <sys/stat.h>
  #include "as.h"
  #include "input-file.h"
  #include "safe-ctype.h"
--- 26,32 ----
  
  #include <stdio.h>
  #include <string.h>
! #include <errno.h>
  #include "as.h"
  #include "input-file.h"
  #include "safe-ctype.h"
*************** input_file_open (char *filename, /* "" m
*** 135,153 ****
    assert (filename != 0);	/* Filename may not be NULL.  */
    if (filename[0])
      {
-       struct stat statbuf;
- 
-       if (stat (filename, &statbuf) < 0)
- 	{
- 	  as_bad (_("%s: No such file"), filename);
- 	  return;
- 	}
-       else if (! S_ISREG (statbuf.st_mode))
- 	{
- 	  as_bad (_("'%s' is not an ordinary file"), filename);
- 	  return;
- 	}
- 
        f_in = fopen (filename, FOPEN_RT);
        file_name = filename;
      }
--- 135,140 ----
*************** input_file_open (char *filename, /* "" m
*** 159,172 ****
        file_name = _("{standard input}");
      }
  
!   if (f_in == (FILE *) 0)
      {
!       as_bad (_("can't open %s for reading"), file_name);
!       as_perror ("%s", file_name);
        return;
      }
  
-   c = getc (f_in);
    if (c == '#')
      {
        /* Begins with comment, may not want to preprocess.  */
--- 146,177 ----
        file_name = _("{standard input}");
      }
  
!   if (f_in)
!     c = getc (f_in);
! 
!   if (f_in == NULL || c == EOF)
      {
!       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)
! 	{
! 	  fclose (f_in);
! 	  f_in = NULL;
! 	}
        return;
      }
  
    if (c == '#')
      {
        /* Begins with comment, may not want to preprocess.  */


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