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 /binutils/bucomm.c | |
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.
Diffstat (limited to 'binutils/bucomm.c')
-rw-r--r-- | binutils/bucomm.c | 25 |
1 files changed, 25 insertions, 0 deletions
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; +} |