diff options
author | Nick Clifton <nickc@redhat.com> | 2003-11-07 12:19:34 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2003-11-07 12:19:34 +0000 |
commit | f24ddbddc5177a930b867626b12d2bb8b3757223 (patch) | |
tree | fe1b8c0703b20b4e188b7c432488a7e2f8874ab1 | |
parent | 65ed7f0a337f0c802f4a7c096c833f20c99dfb3e (diff) | |
download | gdb-f24ddbddc5177a930b867626b12d2bb8b3757223.zip gdb-f24ddbddc5177a930b867626b12d2bb8b3757223.tar.gz gdb-f24ddbddc5177a930b867626b12d2bb8b3757223.tar.bz2 |
Use consistent error messages for missing files.
Detect directories where an ordinary file is expected.
-rw-r--r-- | binutils/ChangeLog | 15 | ||||
-rw-r--r-- | binutils/addr2line.c | 3 | ||||
-rw-r--r-- | binutils/ar.c | 8 | ||||
-rw-r--r-- | binutils/bucomm.c | 25 | ||||
-rw-r--r-- | binutils/bucomm.h | 2 | ||||
-rw-r--r-- | binutils/nm.c | 3 | ||||
-rw-r--r-- | binutils/objcopy.c | 51 | ||||
-rw-r--r-- | binutils/objdump.c | 6 | ||||
-rw-r--r-- | binutils/readelf.c | 14 | ||||
-rw-r--r-- | binutils/size.c | 6 | ||||
-rw-r--r-- | binutils/strings.c | 3 | ||||
-rw-r--r-- | gas/ChangeLog | 5 | ||||
-rw-r--r-- | gas/input-file.c | 25 | ||||
-rw-r--r-- | ld/ChangeLog | 4 | ||||
-rw-r--r-- | ld/ldfile.c | 4 |
15 files changed, 140 insertions, 34 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index f683369..315a4d4 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -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. diff --git a/binutils/addr2line.c b/binutils/addr2line.c index b5f5a0c..354153e 100644 --- a/binutils/addr2line.c +++ b/binutils/addr2line.c @@ -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); diff --git a/binutils/ar.c b/binutils/ar.c index 1724171..77fa467 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -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) { diff --git a/binutils/bucomm.c b/binutils/bucomm.c index a6bb6e4..6573e2d 100644 --- a/binutils/bucomm.c +++ b/binutils/bucomm.c @@ -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; +} diff --git a/binutils/bucomm.h b/binutils/bucomm.h index 9b17791..f604053 100644 --- a/binutils/bucomm.h +++ b/binutils/bucomm.h @@ -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 */ diff --git a/binutils/nm.c b/binutils/nm.c index d2d38c4..bac7d38 100644 --- a/binutils/nm.c +++ b/binutils/nm.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) { diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 8a1a67a..8796dd6 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -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. */ diff --git a/binutils/objdump.c b/binutils/objdump.c index b1222d2..723a28c 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -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) diff --git a/binutils/readelf.c b/binutils/readelf.c index fb8d80f..9b8b12e 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -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; } diff --git a/binutils/size.c b/binutils/size.c index 02f0972..9875493 100644 --- a/binutils/size.c +++ b/binutils/size.c @@ -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); diff --git a/binutils/strings.c b/binutils/strings.c index 67c601f..68c244c 100644 --- a/binutils/strings.c +++ b/binutils/strings.c @@ -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 diff --git a/gas/ChangeLog b/gas/ChangeLog index 57cf9ff..fadb9c3 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -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'. diff --git a/gas/input-file.c b/gas/input-file.c index b6c91ed..8e73615 100644 --- a/gas/input-file.c +++ b/gas/input-file.c @@ -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); diff --git a/ld/ChangeLog b/ld/ChangeLog index db08d59..8c96799 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -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. diff --git a/ld/ldfile.c b/ld/ldfile.c index cdec8ee..cb0a3c3 100644 --- a/ld/ldfile.c +++ b/ld/ldfile.c @@ -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 { |