sim: frv: fix up various missing prototype warnings
[binutils-gdb.git] / binutils / bucomm.c
index 8269c8d29afe56fd03f9b37cb7cc03a2e4854f47..8ce66ab8cce7b6520ff7f3cada33fb7632c64a3f 100644 (file)
@@ -1,5 +1,5 @@
 /* bucomm.c -- Bin Utils COMmon code.
-   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   Copyright (C) 1991-2021 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
 #include "bfd.h"
 #include "libiberty.h"
 #include "filenames.h"
-
-#include <time.h>              /* ctime, maybe time_t */
+#include <time.h>
 #include <assert.h>
 #include "bucomm.h"
-
-#ifndef HAVE_TIME_T_IN_TIME_H
-#ifndef HAVE_TIME_T_IN_TYPES_H
-typedef long time_t;
-#endif
-#endif
 \f
 /* Error reporting.  */
 
@@ -44,8 +37,12 @@ void
 bfd_nonfatal (const char *string)
 {
   const char *errmsg;
+  enum bfd_error err = bfd_get_error ();
 
-  errmsg = bfd_errmsg (bfd_get_error ());
+  if (err == bfd_error_no_error)
+    errmsg = _("cause of error unknown");
+  else
+    errmsg = bfd_errmsg (err);
   fflush (stdout);
   if (string)
     fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
@@ -60,10 +57,10 @@ bfd_nonfatal (const char *string)
    bfd error message is printed.  In summary, error messages are of
    one of the following forms:
 
-   PROGRAM:file: bfd-error-message
-   PROGRAM:file[section]: bfd-error-message
-   PROGRAM:file: printf-message: bfd-error-message
-   PROGRAM:file[section]: printf-message: bfd-error-message.  */
+   PROGRAM: file: bfd-error-message
+   PROGRAM: file[section]: bfd-error-message
+   PROGRAM: file: printf-message: bfd-error-message
+   PROGRAM: file[section]: printf-message: bfd-error-message.  */
 
 void
 bfd_nonfatal_message (const char *filename,
@@ -74,8 +71,12 @@ bfd_nonfatal_message (const char *filename,
   const char *errmsg;
   const char *section_name;
   va_list args;
+  enum bfd_error err = bfd_get_error ();
 
-  errmsg = bfd_errmsg (bfd_get_error ());
+  if (err == bfd_error_no_error)
+    errmsg = _("cause of error unknown");
+  else
+    errmsg = bfd_errmsg (err);
   fflush (stdout);
   section_name = NULL;
   va_start (args, format);
@@ -86,12 +87,12 @@ bfd_nonfatal_message (const char *filename,
       if (!filename)
        filename = bfd_get_archive_filename (abfd);
       if (section)
-       section_name = bfd_get_section_name (abfd, section);
+       section_name = bfd_section_name (section);
     }
   if (section_name)
-    fprintf (stderr, ":%s[%s]", filename, section_name);
+    fprintf (stderr, ": %s[%s]", filename, section_name);
   else
-    fprintf (stderr, ":%s", filename);
+    fprintf (stderr, ": %s", filename);
 
   if (format)
     {
@@ -427,7 +428,7 @@ display_info (void)
    Mode       User\tGroup\tSize\tDate               Name */
 
 void
-print_arelt_descr (FILE *file, bfd *abfd, bfd_boolean verbose, bfd_boolean offsets)
+print_arelt_descr (FILE *file, bfd *abfd, bool verbose, bool offsets)
 {
   struct stat buf;
 
@@ -524,7 +525,7 @@ template_in_dir (const char *path)
    as FILENAME.  */
 
 char *
-make_tempname (char *filename)
+make_tempname (const char *filename, int *ofd)
 {
   char *tmpname = template_in_dir (filename);
   int fd;
@@ -542,7 +543,7 @@ make_tempname (char *filename)
       free (tmpname);
       return NULL;
     }
-  close (fd);
+  *ofd = fd;
   return tmpname;
 }
 
@@ -550,7 +551,7 @@ make_tempname (char *filename)
    directory containing FILENAME.  */
 
 char *
-make_tempdir (char *filename)
+make_tempdir (const char *filename)
 {
   char *tmpname = template_in_dir (filename);
 
@@ -615,6 +616,21 @@ get_file_size (const char * file_name)
   else if (statbuf.st_size < 0)
     non_fatal (_("Warning: '%s' has negative size, probably it is too large"),
                file_name);
+#if defined (_WIN32) && !defined (__CYGWIN__)
+  else if (statbuf.st_size == 0)
+    {
+      /* MS-Windows 'stat' reports the null device as a regular file;
+        fix that.  */
+      int fd = open (file_name, O_RDONLY | O_BINARY);
+      if (isatty (fd))
+       {
+         close (fd);
+         non_fatal (_("Warning: '%s' is not an ordinary file"),
+                    /* libtool wants to see /dev/null in the output.  */
+                    strcasecmp (file_name, "nul") ? file_name : "/dev/null");
+       }
+    }
+#endif
   else
     return statbuf.st_size;
 
@@ -654,18 +670,18 @@ bfd_get_archive_filename (const bfd *abfd)
    is valid for writing.  For security reasons absolute paths
    and paths containing /../ are not allowed.  See PR 17533.  */
 
-bfd_boolean
+bool
 is_valid_archive_path (char const * pathname)
 {
   const char * n = pathname;
 
   if (IS_ABSOLUTE_PATH (n))
-    return FALSE;
+    return false;
 
   while (*n)
     {
       if (*n == '.' && *++n == '.' && ( ! *++n || IS_DIR_SEPARATOR (*n)))
-       return FALSE;
+       return false;
 
       while (*n && ! IS_DIR_SEPARATOR (*n))
        n++;
@@ -673,5 +689,5 @@ is_valid_archive_path (char const * pathname)
        n++;
     }
 
-  return TRUE;
+  return true;
 }