Use consistent error messages for missing files.
Detect directories where an ordinary file is expected.
This commit is contained in:
parent
65ed7f0a33
commit
f24ddbddc5
@ -1,3 +1,18 @@
|
||||
2003-11-07 Jonathan R. Grant <jg-binutils@jguk.org>
|
||||
|
||||
* bucomm,c (get_file_size): New function. Returns the size of a
|
||||
file.
|
||||
* bucomm.h: Add prototype for get_file_size.
|
||||
* addr2line.c (process_file): Use new function.
|
||||
* ar.c (main, ranlib_only, ranlib_touch): Likewise.
|
||||
* nm.c (display_file): Likewise.
|
||||
* objcopy.c (add_specific_symbols, copy_file, strip_main,
|
||||
copy_main): Likewise.
|
||||
* objdump.c (display_file): Likewise.
|
||||
* size.c (display_file): Likewise.
|
||||
* strings.c (strings_file): Likewise.
|
||||
* readelf.c (process_file): Use similar code to get_file_size.
|
||||
|
||||
2003-11-06 Bruno Rohee <bruno@rohee.com>
|
||||
|
||||
* ieee.c: Fix "the the" typo.
|
||||
|
@ -230,6 +230,9 @@ process_file (const char *file_name, const char *target)
|
||||
bfd *abfd;
|
||||
char **matching;
|
||||
|
||||
if (get_file_size (file_name) < 1)
|
||||
return;
|
||||
|
||||
abfd = bfd_openr (file_name, target);
|
||||
if (abfd == NULL)
|
||||
bfd_fatal (file_name);
|
||||
|
@ -1305,7 +1305,9 @@ replace_members (bfd *arch, char **files_to_move, bfd_boolean quick)
|
||||
|
||||
/* Add to the end of the archive. */
|
||||
after_bfd = get_pos_bfd (&arch->next, pos_end, NULL);
|
||||
if (ar_emul_append (after_bfd, *files_to_move, verbose))
|
||||
|
||||
if (get_file_size (* files_to_move) > 0
|
||||
&& ar_emul_append (after_bfd, *files_to_move, verbose))
|
||||
changed = TRUE;
|
||||
|
||||
next_file:;
|
||||
@ -1324,6 +1326,8 @@ ranlib_only (const char *archname)
|
||||
{
|
||||
bfd *arch;
|
||||
|
||||
if (get_file_size (archname) < 1)
|
||||
return;
|
||||
write_armap = 1;
|
||||
arch = open_inarch (archname, (char *) NULL);
|
||||
if (arch == NULL)
|
||||
@ -1344,6 +1348,8 @@ ranlib_touch (const char *archname)
|
||||
bfd *arch;
|
||||
char **matching;
|
||||
|
||||
if (get_file_size (archname) < 1)
|
||||
return;
|
||||
f = open (archname, O_RDWR | O_BINARY, 0);
|
||||
if (f < 0)
|
||||
{
|
||||
|
@ -450,3 +450,28 @@ parse_vma (const char *s, const char *arg)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Returns the size of the named file. If the file does not
|
||||
exist, or if it is not a real file, then a suitable non-fatal
|
||||
error message is printed and zero is returned. */
|
||||
|
||||
off_t
|
||||
get_file_size (const char * file_name)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat (file_name, &statbuf) < 0)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
non_fatal (_("'%s': No such file"), file_name);
|
||||
else
|
||||
non_fatal (_("Warning: could not locate '%s'. reason: %s"),
|
||||
file_name, strerror (errno));
|
||||
}
|
||||
else if (! S_ISREG (statbuf.st_mode))
|
||||
non_fatal (_("Warning: '%s' is not an ordinary file"), file_name);
|
||||
else
|
||||
return statbuf.st_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -174,6 +174,8 @@ char *make_tempname (char *);
|
||||
|
||||
bfd_vma parse_vma (const char *, const char *);
|
||||
|
||||
off_t get_file_size (const char *);
|
||||
|
||||
extern char *program_name;
|
||||
|
||||
/* filemode.c */
|
||||
|
@ -602,6 +602,9 @@ display_file (char *filename)
|
||||
bfd *file;
|
||||
char **matching;
|
||||
|
||||
if (get_file_size (filename) < 1)
|
||||
return FALSE;
|
||||
|
||||
file = bfd_openr (filename, target);
|
||||
if (file == NULL)
|
||||
{
|
||||
|
@ -583,28 +583,27 @@ add_specific_symbol (const char *name, struct symlist **list)
|
||||
static void
|
||||
add_specific_symbols (const char *filename, struct symlist **list)
|
||||
{
|
||||
struct stat st;
|
||||
off_t size;
|
||||
FILE * f;
|
||||
char * line;
|
||||
char * buffer;
|
||||
unsigned int line_count;
|
||||
|
||||
if (stat (filename, & st) < 0)
|
||||
fatal (_("cannot stat: %s: %s"), filename, strerror (errno));
|
||||
if (st.st_size == 0)
|
||||
size = get_file_size (filename);
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
buffer = xmalloc (st.st_size + 2);
|
||||
buffer = xmalloc (size + 2);
|
||||
f = fopen (filename, FOPEN_RT);
|
||||
if (f == NULL)
|
||||
fatal (_("cannot open: %s: %s"), filename, strerror (errno));
|
||||
fatal (_("cannot open '%s': %s"), filename, strerror (errno));
|
||||
|
||||
if (fread (buffer, 1, st.st_size, f) == 0 || ferror (f))
|
||||
if (fread (buffer, 1, size, f) == 0 || ferror (f))
|
||||
fatal (_("%s: fread failed"), filename);
|
||||
|
||||
fclose (f);
|
||||
buffer [st.st_size] = '\n';
|
||||
buffer [st.st_size + 1] = '\0';
|
||||
buffer [size] = '\n';
|
||||
buffer [size + 1] = '\0';
|
||||
|
||||
line_count = 1;
|
||||
|
||||
@ -1571,6 +1570,12 @@ copy_file (const char *input_filename, const char *output_filename,
|
||||
char **obj_matching;
|
||||
char **core_matching;
|
||||
|
||||
if (get_file_size (input_filename) < 1)
|
||||
{
|
||||
status = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* To allow us to do "strip *" without dying on the first
|
||||
non-object file, failures are nonfatal. */
|
||||
ibfd = bfd_openr (input_filename, input_target);
|
||||
@ -2246,14 +2251,13 @@ strip_main (int argc, char *argv[])
|
||||
struct stat statbuf;
|
||||
char *tmpname;
|
||||
|
||||
if (get_file_size (argv[i]) < 1)
|
||||
continue;
|
||||
|
||||
if (preserve_dates)
|
||||
{
|
||||
if (stat (argv[i], &statbuf) < 0)
|
||||
{
|
||||
non_fatal (_("%s: cannot stat: %s"), argv[i], strerror (errno));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* No need to check the return value of stat().
|
||||
It has already been checked in get_file_size(). */
|
||||
stat (argv[i], &statbuf);
|
||||
|
||||
if (output_file != NULL)
|
||||
tmpname = output_file;
|
||||
@ -2416,7 +2420,7 @@ copy_main (int argc, char *argv[])
|
||||
case OPTION_ADD_SECTION:
|
||||
{
|
||||
const char *s;
|
||||
struct stat st;
|
||||
off_t size;
|
||||
struct section_add *pa;
|
||||
int len;
|
||||
char *name;
|
||||
@ -2427,8 +2431,9 @@ copy_main (int argc, char *argv[])
|
||||
if (s == NULL)
|
||||
fatal (_("bad format for %s"), "--add-section");
|
||||
|
||||
if (stat (s + 1, & st) < 0)
|
||||
fatal (_("cannot stat: %s: %s"), s + 1, strerror (errno));
|
||||
size = get_file_size (s + 1);
|
||||
if (size < 1)
|
||||
break;
|
||||
|
||||
pa = xmalloc (sizeof (struct section_add));
|
||||
|
||||
@ -2439,10 +2444,9 @@ copy_main (int argc, char *argv[])
|
||||
pa->name = name;
|
||||
|
||||
pa->filename = s + 1;
|
||||
pa->size = size;
|
||||
pa->contents = xmalloc (size);
|
||||
|
||||
pa->size = st.st_size;
|
||||
|
||||
pa->contents = xmalloc (pa->size);
|
||||
f = fopen (pa->filename, FOPEN_RB);
|
||||
|
||||
if (f == NULL)
|
||||
@ -2800,7 +2804,8 @@ copy_main (int argc, char *argv[])
|
||||
|
||||
if (preserve_dates)
|
||||
if (stat (input_filename, & statbuf) < 0)
|
||||
fatal (_("Cannot stat: %s: %s"), input_filename, strerror (errno));
|
||||
fatal (_("warning: could not locate '%s'. System error message: %s"),
|
||||
input_filename, strerror (errno));
|
||||
|
||||
/* If there is no destination file, or the source and destination files
|
||||
are the same, then create a temp and rename the result into the input. */
|
||||
|
@ -2623,7 +2623,11 @@ display_bfd (bfd *abfd)
|
||||
static void
|
||||
display_file (char *filename, char *target)
|
||||
{
|
||||
bfd *file, *arfile = NULL;
|
||||
bfd *file;
|
||||
bfd *arfile = NULL;
|
||||
|
||||
if (get_file_size (filename) < 1)
|
||||
return;
|
||||
|
||||
file = bfd_openr (filename, target);
|
||||
if (file == NULL)
|
||||
|
@ -10457,14 +10457,24 @@ process_file (char *file_name)
|
||||
|
||||
if (stat (file_name, &statbuf) < 0)
|
||||
{
|
||||
error (_("Cannot stat input file %s.\n"), file_name);
|
||||
if (errno == ENOENT)
|
||||
error (_("'%s': No such file\n"), file_name);
|
||||
else
|
||||
error (_("Could not locate '%s'. System error message: %s\n"),
|
||||
file_name, strerror (errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! S_ISREG (statbuf.st_mode))
|
||||
{
|
||||
error (_("'%s' is not an ordinary file\n"), file_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = fopen (file_name, "rb");
|
||||
if (file == NULL)
|
||||
{
|
||||
error (_("Input file %s not found.\n"), file_name);
|
||||
error (_("Input file '%s' is not readable.\n"), file_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -341,8 +341,12 @@ display_archive (bfd *file)
|
||||
static void
|
||||
display_file (char *filename)
|
||||
{
|
||||
bfd *file = bfd_openr (filename, target);
|
||||
bfd *file;
|
||||
|
||||
if (get_file_size (filename) < 1)
|
||||
return;
|
||||
|
||||
file = bfd_openr (filename, target);
|
||||
if (file == NULL)
|
||||
{
|
||||
bfd_nonfatal (filename);
|
||||
|
@ -370,6 +370,9 @@ strings_object_file (const char *file)
|
||||
static bfd_boolean
|
||||
strings_file (char *file)
|
||||
{
|
||||
if (get_file_size (file) < 1)
|
||||
return FALSE;
|
||||
|
||||
/* If we weren't told to scan the whole file,
|
||||
try to open it as an object file and only look at
|
||||
initialized data sections. If that fails, fall back to the
|
||||
|
@ -1,3 +1,8 @@
|
||||
2003-11-07 Jonathan R. Grant <jg-binutils@jguk.org>
|
||||
|
||||
* input-file.c (input_file_open): Use "No such file" error
|
||||
message.
|
||||
|
||||
2003-11-06 Pete Gonzalez <pgonzalez@bluel.com>
|
||||
|
||||
* config/tc-arm.texi (struct reg_entry): Add new field 'builtin'.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* input_file.c - Deal with Input Files -
|
||||
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001
|
||||
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GAS, the GNU Assembler.
|
||||
@ -26,6 +26,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include "as.h"
|
||||
#include "input-file.h"
|
||||
#include "safe-ctype.h"
|
||||
@ -135,15 +136,31 @@ input_file_open (filename, pre)
|
||||
|
||||
assert (filename != 0); /* Filename may not be NULL. */
|
||||
if (filename[0])
|
||||
{ /* We have a file name. Suck it and see. */
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{ /* use stdin for the input file. */
|
||||
{
|
||||
/* Use stdin for the input file. */
|
||||
f_in = stdin;
|
||||
file_name = _("{standard input}"); /* For error messages. */
|
||||
/* For error messages. */
|
||||
file_name = _("{standard input}");
|
||||
}
|
||||
|
||||
if (f_in == (FILE *) 0)
|
||||
{
|
||||
as_bad (_("can't open %s for reading"), file_name);
|
||||
|
@ -1,3 +1,7 @@
|
||||
2003-11-07 Jonathan R. Grant <jg-binutils@jguk.org>
|
||||
|
||||
* ldfile.c (ldfile_open_file): Use "No such file" error message.
|
||||
|
||||
2003-11-06 Bruno Rohee <bruno@rohee.com>
|
||||
|
||||
* ls.texinfo: Fix "the the" typo.
|
||||
|
@ -374,10 +374,10 @@ ldfile_open_file (lang_input_statement_type *entry)
|
||||
if (ldfile_try_open_bfd (entry->filename, entry))
|
||||
return;
|
||||
if (strcmp (entry->filename, entry->local_sym_name) != 0)
|
||||
einfo (_("%F%P: cannot open %s for %s: %E\n"),
|
||||
einfo (_("%F%P: %s (%s): No such file: %E\n"),
|
||||
entry->filename, entry->local_sym_name);
|
||||
else
|
||||
einfo (_("%F%P: cannot open %s: %E\n"), entry->local_sym_name);
|
||||
einfo (_("%F%P: %s: No such file: %E\n"), entry->local_sym_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user