/* bucomm.c -- Bin Utils COMmon code.
- Copyright (C) 1991-2020 Free Software Foundation, Inc.
+ Copyright (C) 1991-2023 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. */
{
const char *errmsg;
const char *section_name;
- va_list args;
enum bfd_error err = bfd_get_error ();
if (err == bfd_error_no_error)
errmsg = bfd_errmsg (err);
fflush (stdout);
section_name = NULL;
- va_start (args, format);
fprintf (stderr, "%s", program_name);
if (abfd)
if (format)
{
+ va_list args;
+ va_start (args, format);
fprintf (stderr, ": ");
vfprintf (stderr, format, args);
+ va_end (args);
}
fprintf (stderr, ": %s\n", errmsg);
- va_end (args);
}
void
va_end (args);
}
+/* Like xmalloc except that ABFD's objalloc memory is returned.
+ Use objalloc_free_block to free this memory and all more recently
+ allocated, or more usually, leave it to bfd_close to free. */
+
+void *
+bfd_xalloc (bfd *abfd, size_t size)
+{
+ void *ret = bfd_alloc (abfd, size);
+ if (ret == NULL)
+ bfd_fatal (NULL);
+ return ret;
+}
+
/* Set the default BFD target based on the configured target. Doing
this permits the binutils to be configured for a particular target,
and linked against a shared BFD library which was configured for a
/* After a FALSE return from bfd_check_format_matches with
bfd_get_error () == bfd_error_file_ambiguously_recognized, print
- the possible matching targets. */
+ the possible matching targets and free the list of targets. */
void
-list_matching_formats (char **p)
+list_matching_formats (char **matching)
{
fflush (stdout);
fprintf (stderr, _("%s: Matching formats:"), program_name);
+ char **p = matching;
while (*p)
fprintf (stderr, " %s", *p++);
+ free (matching);
fputc ('\n', stderr);
}
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;
char timebuf[40];
time_t when = buf.st_mtime;
const char *ctime_result = (const char *) ctime (&when);
- bfd_size_type size;
/* PR binutils/17605: Check for corrupt time values. */
if (ctime_result == NULL)
mode_string (buf.st_mode, modebuf);
modebuf[10] = '\0';
- size = buf.st_size;
/* POSIX 1003.2/D11 says to skip first character (entry type). */
- fprintf (file, "%s %ld/%ld %6" BFD_VMA_FMT "u %s ", modebuf + 1,
+ fprintf (file, "%s %ld/%ld %6" PRIu64 " %s ", modebuf + 1,
(long) buf.st_uid, (long) buf.st_gid,
- size, timebuf);
+ (uint64_t) buf.st_size, timebuf);
}
}
as FILENAME. */
char *
-make_tempname (const char *filename)
+make_tempname (const char *filename, int *ofd)
{
char *tmpname = template_in_dir (filename);
int fd;
#else
tmpname = mktemp (tmpname);
if (tmpname == NULL)
- return NULL;
- fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
+ fd = -1;
+ else
+ fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
#endif
if (fd == -1)
{
free (tmpname);
+ bfd_set_error (bfd_error_system_call);
return NULL;
}
- close (fd);
+ *ofd = fd;
return tmpname;
}
make_tempdir (const char *filename)
{
char *tmpname = template_in_dir (filename);
+ char *ret;
#ifdef HAVE_MKDTEMP
- return mkdtemp (tmpname);
+ ret = mkdtemp (tmpname);
#else
- tmpname = mktemp (tmpname);
- if (tmpname == NULL)
- return NULL;
+ ret = mktemp (tmpname);
#if defined (_WIN32) && !defined (__CYGWIN32__)
if (mkdir (tmpname) != 0)
- return NULL;
+ ret = NULL;
#else
if (mkdir (tmpname, 0700) != 0)
- return NULL;
+ ret = NULL;
#endif
- return tmpname;
#endif
+ if (ret == NULL)
+ {
+ free (tmpname);
+ bfd_set_error (bfd_error_system_call);
+ }
+ return ret;
}
/* Parse a string into a VMA, with a fatal error if it can't be
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;
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++;
n++;
}
- return TRUE;
+ return true;
}