Specify which filename is causing an error if the filename is a
authorDavid Kimdon <dwhedon@gordian.com>
Wed, 10 Jun 2026 06:16:33 +0000 (08:16 +0200)
committerMatthias Klose <doko@debian.org>
Wed, 10 Jun 2026 06:16:33 +0000 (08:16 +0200)
directory. (#45832)

Gbp-Pq: Name 006_better_file_error.patch

bfd/opncls.c

index a8fa6ebbf17add58dfe96d5877c05b8eb45e7cba..c168ca7195c1b2d0058fca0e70224ec110cbe572 100644 (file)
@@ -233,6 +233,13 @@ bfd_fopen (const char *filename, const char *target, const char *mode, int fd)
 {
   bfd *nbfd;
   const bfd_target *target_vec;
+  struct stat s;
+
+  if (stat (filename, &s) == 0)
+    if (S_ISDIR(s.st_mode)) {
+      bfd_set_error (bfd_error_file_not_recognized);
+      return NULL;
+    }
 
   nbfd = _bfd_new_bfd ();
   if (nbfd == NULL)