This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: gas attempting to assemble non-existent file
On Tue, Sep 12, 2006 at 08:55:39AM +0100, Jan Beulich wrote:
> >>> Alan Modra <amodra@bigpond.net.au> 12.09.06 09:49 >>>
> >$ gas/as-new -o foo non-existent-file.s
> >Assembler messages:
> >Can't open non-existent-file.s for reading: No such file or directory
> >$ echo $?
> >0
> >$ ls -l foo
> >-rw-r--r-- 1 alan users 441 2006-09-12 15:39 foo
> >
> >Seems to me we ought to return a non-zero exit status and delete the
> >output. Am I missing something?
>
> Yes, please - I ran into the same with .include, but hadn't had time to
> create a patch, yet.
As far as I know, the comment in input-file.h regarding EOF is wrong.
It is only when attempting to read past EOF that you get an I/O
error.
* input-file.c (input_file_open): Replace as_perror with as_bad
so that gas exits with error on file errors. Correct error
message.
(input_file_get, input_file_give_next_buffer): Likewise.
* input-file.h: Update comment.
Index: gas/input-file.c
===================================================================
RCS file: /cvs/src/src/gas/input-file.c,v
retrieving revision 1.21
diff -u -p -r1.21 input-file.c
--- gas/input-file.c 7 Jun 2006 11:27:57 -0000 1.21
+++ gas/input-file.c 12 Sep 2006 23:53:51 -0000
@@ -140,8 +140,8 @@ input_file_open (char *filename, /* "" m
if (f_in == NULL)
{
- bfd_set_error (bfd_error_system_call);
- as_perror (_("Can't open %s for reading"), file_name);
+ as_bad (_("can't open %s for reading: %s"),
+ file_name, xstrerror (errno));
return;
}
@@ -149,8 +149,8 @@ input_file_open (char *filename, /* "" m
if (ferror (f_in))
{
- bfd_set_error (bfd_error_system_call);
- as_perror (_("Can't open %s for reading"), file_name);
+ as_bad (_("can't read from %s: %s"),
+ file_name, xstrerror (errno));
fclose (f_in);
f_in = NULL;
@@ -212,8 +212,7 @@ input_file_get (char *buf, int buflen)
size = fread (buf, sizeof (char), buflen, f_in);
if (size < 0)
{
- bfd_set_error (bfd_error_system_call);
- as_perror (_("Can't read from %s"), file_name);
+ as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
size = 0;
}
return size;
@@ -239,8 +238,7 @@ input_file_give_next_buffer (char *where
size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
if (size < 0)
{
- bfd_set_error (bfd_error_system_call);
- as_perror (_("Can't read from %s"), file_name);
+ as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
size = 0;
}
if (size)
@@ -248,10 +246,8 @@ input_file_give_next_buffer (char *where
else
{
if (fclose (f_in))
- {
- bfd_set_error (bfd_error_system_call);
- as_perror (_("Can't close %s"), file_name);
- }
+ as_bad (_("can't close %s: %s"), file_name, xstrerror (errno));
+
f_in = (FILE *) 0;
return_value = 0;
}
Index: gas/input-file.h
===================================================================
RCS file: /cvs/src/src/gas/input-file.h,v
retrieving revision 1.7
diff -u -p -r1.7 input-file.h
--- gas/input-file.h 5 May 2005 09:12:45 -0000 1.7
+++ gas/input-file.h 12 Sep 2006 23:53:51 -0000
@@ -1,5 +1,6 @@
/* input_file.h header for input-file.c
- Copyright 1987, 1992, 1993, 2000, 2003 Free Software Foundation, Inc.
+ Copyright 1987, 1992, 1993, 2000, 2003, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -51,8 +52,8 @@
*
* input_file_close () Closes opened file.
*
- * All errors are reported (using as_perror) so caller doesn't have to think
- * about I/O errors. No I/O errors are fatal: an end-of-file may be faked.
+ * All errors are reported so caller doesn't have to think
+ * about I/O errors.
*/
char *input_file_give_next_buffer (char *where);
--
Alan Modra
IBM OzLabs - Linux Technology Centre