*/
#undef HAVE_DCGETTEXT
-/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
- don't. */
-#undef HAVE_DECL_ASPRINTF
-
/* Define to 1 if you have the declaration of `environ', and to 0 if you
don't. */
#undef HAVE_DECL_ENVIRON
fi
-ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" "$ac_includes_default"
-if test "x$ac_cv_have_decl_asprintf" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_ASPRINTF $ac_have_decl
-_ACEOF
ac_fn_c_check_decl "$LINENO" "environ" "ac_cv_have_decl_environ" "$ac_includes_default"
if test "x$ac_cv_have_decl_environ" = xyes; then :
ac_have_decl=1
AC_DEFINE(HAVE_GOOD_UTIME_H, 1, [Does <utime.h> define struct utimbuf?])
fi
-AC_CHECK_DECLS([asprintf, environ, getc_unlocked, stpcpy, strnlen])
+AC_CHECK_DECLS([environ, getc_unlocked, stpcpy, strnlen])
# Link in zlib/zstd if we can. This allows us to read compressed debug
# sections. This is used only by readelf.c (objdump uses bfd for
}
if (filename[0] != '/' && strchr (main_filename, '/'))
- {
- char * new_name;
- int new_len;
-
- new_len = asprintf (& new_name, "%.*s/%s",
+ filename = xasprintf ("%.*s/%s",
(int) (strrchr (main_filename, '/') - main_filename),
main_filename,
filename);
- if (new_len < 3)
- {
- warn (_("unable to construct path for supplementary debug file\n"));
- if (new_len > -1)
- free (new_name);
- return;
- }
- filename = new_name;
- }
else
- {
- /* PR 27796: Make sure that we pass a filename that can be free'd to
- add_separate_debug_file(). */
- filename = strdup (filename);
- if (filename == NULL)
- {
- warn (_("out of memory constructing filename for .debug_sup link\n"));
- return;
- }
- }
+ /* PR 27796: Make sure that we pass a filename that can be free'd to
+ add_separate_debug_file(). */
+ filename = xstrdup (filename);
void * handle = open_debug_file (filename);
if (handle == NULL)
get_elf_symbol_type (unsigned int type)
{
static char *bufp;
- int n;
switch (type)
{
free (bufp);
if (type >= STT_LOPROC && type <= STT_HIPROC)
- n = asprintf (&bufp, _("<processor specific>: %d"), type);
+ bufp = xasprintf (_("<processor specific>: %d"), type);
else if (type >= STT_LOOS && type <= STT_HIOS)
- n = asprintf (&bufp, _("<OS specific>: %d"), type);
+ bufp = xasprintf (_("<OS specific>: %d"), type);
else
- n = asprintf (&bufp, _("<unknown>: %d"), type);
- if (n < 0)
- fatal ("%s", xstrerror (errno));
+ bufp = xasprintf (_("<unknown>: %d"), type);
return bufp;
}
get_coff_symbol_type (const struct internal_syment *sym)
{
static char *bufp;
- int n;
switch (sym->n_sclass)
{
}
free (bufp);
- n = asprintf (&bufp, _("<unknown>: %d/%d"), sym->n_sclass, sym->n_type);
- if (n < 0)
- fatal ("%s", xstrerror (errno));
+ bufp = xasprintf (_("<unknown>: %d/%d"), sym->n_sclass, sym->n_type);
return bufp;
}
\f
char *s, void *arg)
{
const char *blanks = arg;
- char *new_s;
-
- if (asprintf (&new_s, "%s%s", blanks, s) < 0)
- return s;
- return new_s;
+ return xasprintf ("%s%s", blanks, s);
}
/* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
return false;
/* Look for extended data for the symbol table. */
- Elf_Internal_Shdr * ext = NULL;
void * ext_data_orig = NULL;
char * ext_data = NULL;
char * ext_data_end = NULL;
- char * ext_name = NULL;
-
- if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s",
- (section_name (filedata, section)
- + sizeof (".gnu.lto_.symtab.") - 1)) > 0
- && ext_name != NULL /* Paranoia. */
- && (ext = find_section (filedata, ext_name)) != NULL)
+ char *ext_name = xasprintf (".gnu.lto_.ext_symtab.%s",
+ (section_name (filedata, section)
+ + sizeof (".gnu.lto_.symtab.")));
+ Elf_Internal_Shdr *ext = find_section (filedata, ext_name);
+ if (ext != NULL)
{
if (ext->sh_size < 3)
error (_("LTO Symbol extension table '%s' is empty!\n"),
char *s, void *arg)
{
const char *blanks = arg;
- char *new_s;
-
- if (asprintf (&new_s, "%s%s", blanks, s) < 0)
- return s;
- return new_s;
+ return xasprintf ("%s%s", blanks, s);
}
/* Dump CTF errors/warnings. */
case OPTION_PREPROCESSOR:
if (strchr (optarg, ' '))
- {
- if (asprintf (& preprocessor, "\"%s\"", optarg) == -1)
- preprocessor = optarg;
- }
+ preprocessor = xasprintf ("\"%s\"", optarg);
else
preprocessor = optarg;
break;
*/
#undef HAVE_DCGETTEXT
-/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
- don't. */
-#undef HAVE_DECL_ASPRINTF
-
/* Is the prototype for getopt in <unistd.h> in the expected format? */
#undef HAVE_DECL_GETOPT
void
kvx_emit_single_noop (void)
{
- char *nop;
- char *end_of_bundle;
-
- if (asprintf (&nop, "nop") < 0)
- as_fatal ("%s", xstrerror (errno));
-
- if (asprintf (&end_of_bundle, "be") < 0)
- as_fatal ("%s", xstrerror (errno));
+ char nop[] = "nop";
+ char end_of_bundle[] = "be";
char *saved_ilp = input_line_pointer;
md_assemble (nop);
md_assemble (end_of_bundle);
input_line_pointer = saved_ilp;
- free (nop);
- free (end_of_bundle);
}
/* edit out some syntactic sugar that confuses GAS */
static void
md_assemblef (const char *format, ...)
{
- char *buf = NULL;
+ char *buf;
va_list ap;
- int r;
va_start (ap, format);
- r = vasprintf (&buf, format, ap);
-
- if (r < 0)
- as_fatal (_("internal: vasprintf failed"));
-
+ buf = xvasprintf (format, ap);
md_assemble (buf);
free(buf);
fi
-ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" "$ac_includes_default"
-if test "x$ac_cv_have_decl_asprintf" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_ASPRINTF $ac_have_decl
-_ACEOF
ac_fn_c_check_decl "$LINENO" "mempcpy" "ac_cv_have_decl_mempcpy" "$ac_includes_default"
if test "x$ac_cv_have_decl_mempcpy" = xyes; then :
ac_have_decl=1
GAS_CHECK_DECL_NEEDED(environ, f, char **f, $gas_test_headers)
GAS_CHECK_DECL_NEEDED(ffs, f, int (*f)(int), $gas_test_headers)
-AC_CHECK_DECLS([asprintf, mempcpy, stpcpy])
+AC_CHECK_DECLS([mempcpy, stpcpy])
BFD_BINARY_FOPEN
#endif
/* md_assemble might modify its argument, so
we must pass it a string that is writable. */
- if (asprintf (&nop, "%s", md_single_noop_insn) < 0)
- as_fatal ("%s", xstrerror (errno));
+ nop = xasprintf ("%s", md_single_noop_insn);
/* Some targets assume that they can update input_line_pointer
inside md_assemble, and, worse, that they can leave it
if (*input_line_pointer != ',')
{
if (default_prefix)
- {
- if (asprintf (&label, "%s%s", default_prefix, name) == -1)
- as_fatal ("%s", xstrerror (errno));
- }
+ label = xasprintf ("%s%s", default_prefix, name);
else
{
char leading_char = bfd_get_symbol_leading_char (stdoutput);
/* Missing entry point, use function's name with the leading
char prepended. */
if (leading_char)
- {
- if (asprintf (&label, "%c%s", leading_char, name) == -1)
- as_fatal ("%s", xstrerror (errno));
- }
+ label = xasprintf ("%c%s", leading_char, name);
else
label = xstrdup (name);
}
}
as_where (&lineno);
- if (asprintf (&buf, "\"%s:F1\",%d,0,%d,%s",
- funcname, N_FUN, lineno + 1, startlabname) == -1)
- as_fatal ("%s", xstrerror (errno));
-
+ buf = xasprintf ("\"%s:F1\",%d,0,%d,%s",
+ funcname, N_FUN, lineno + 1, startlabname);
temp_ilp (buf);
s_stab ('s');
restore_ilp ();
++endfunc_label_count;
colon (sym);
- if (asprintf (&buf, "\"\",%d,0,0,%s-%s", N_FUN, sym, startlabname) == -1)
- as_fatal ("%s", xstrerror (errno));
-
+ buf = xasprintf ("\"\",%d,0,0,%s-%s", N_FUN, sym, startlabname);
temp_ilp (buf);
s_stab ('s');
restore_ilp ();
*/
#undef HAVE_DCGETTEXT
-/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
- don't. */
-#undef HAVE_DECL_ASPRINTF
-
/* Define to 1 if you have the declaration of `environ', and to 0 if you
don't. */
#undef HAVE_DECL_ENVIRON
;;
esac
-ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" "$ac_includes_default"
-if test "x$ac_cv_have_decl_asprintf" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_ASPRINTF $ac_have_decl
-_ACEOF
ac_fn_c_check_decl "$LINENO" "environ" "ac_cv_have_decl_environ" "$ac_includes_default"
if test "x$ac_cv_have_decl_environ" = xyes; then :
ac_have_decl=1
BFD_BINARY_FOPEN
-AC_CHECK_DECLS([asprintf, environ, stpcpy])
+AC_CHECK_DECLS([environ, stpcpy])
GCC_AC_FUNC_MMAP
lang_leave_overlay_section (fill_type *fill,
lang_output_section_phdr_list *phdrs)
{
- const char *name;
- char *clean, *s2;
- const char *s1;
- char *buf;
-
- name = current_section->name;
+ const char *name = current_section->name;;
/* For now, assume that DEFAULT_MEMORY_REGION is the run-time memory
region and that no load-time region has been specified. It doesn't
/* Define the magic symbols. */
- clean = (char *) xmalloc (strlen (name) + 1);
- s2 = clean;
- for (s1 = name; *s1 != '\0'; s1++)
+ char *clean = xmalloc (strlen (name) + 1);
+ char *s2 = clean;
+ for (const char *s1 = name; *s1 != '\0'; s1++)
if (ISALNUM (*s1) || *s1 == '_')
*s2++ = *s1;
*s2 = '\0';
- buf = (char *) xmalloc (strlen (clean) + sizeof "__load_start_");
- sprintf (buf, "__load_start_%s", clean);
+ char *buf = xasprintf ("__load_start_%s", clean);
lang_add_assignment (exp_provide (buf,
exp_nameop (LOADADDR, name),
false));
- buf = (char *) xmalloc (strlen (clean) + sizeof "__load_stop_");
- sprintf (buf, "__load_stop_%s", clean);
+ buf = xasprintf ("__load_stop_%s", clean);
lang_add_assignment (exp_provide (buf,
exp_binop ('+',
exp_nameop (LOADADDR, name),
{
char * new_name = NULL;
char * percent;
- int res = 0;
if (config.map_filename[0] == 0)
{
output filename. If the % character was the last character in
the original map filename then add a .map extension. */
percent[0] = 0;
- res = asprintf (&new_name, "%s%s%s", config.map_filename,
- output_filename,
- percent[1] ? percent + 1 : ".map");
+ new_name = xasprintf ("%s%s%s", config.map_filename,
+ output_filename,
+ percent[1] ? percent + 1 : ".map");
/* FIXME: Should we ensure that any directory components in new_name exist ? */
}
else if (S_ISDIR (s.st_mode))
{
char lastc = config.map_filename[strlen (config.map_filename) - 1];
- res = asprintf (&new_name, "%s%s%s.map",
- config.map_filename,
- IS_DIR_SEPARATOR (lastc) ? "" : "/",
- lbasename (output_filename));
+ new_name = xasprintf ("%s%s%s.map", config.map_filename,
+ IS_DIR_SEPARATOR (lastc) ? "" : "/",
+ lbasename (output_filename));
}
else if (! S_ISREG (s.st_mode))
{
/* else FIXME: Check write permission ? */
}
- if (res < 0)
- {
- /* If the asprintf failed then something is probably very
- wrong. Better to halt now rather than continue on
- into more problems. */
- einfo (_("%P%F: cannot create name for linker map file: %E\n"));
- }
- else if (new_name != NULL)
+ if (new_name != NULL)
{
/* This is a trivial memory leak. */
config.map_filename = new_name;
char *oname;
bfd *abfd;
- if (asprintf (&oname, "%s_d%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_d%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
char *oname;
bfd *abfd;
- if (asprintf (&oname, "%s_d%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_d%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
}
}
- if (asprintf (&oname, "%s_d%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_d%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
char *oname;
bfd *abfd;
- if (asprintf (&oname, "%s_nmth%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_nmth%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
char *oname;
bfd *abfd;
- if (asprintf (&oname, "%s_fu%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_fu%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
bfd *abfd;
bfd_size_type size;
- if (asprintf (&oname, "%s_rtr%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_rtr%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);
char *oname;
bfd *abfd;
- if (asprintf (&oname, "%s_ertr%06d.o", dll_symname, tmp_seq) < 4)
- /* In theory we should return NULL here at let our caller decide what to
- do. But currently the return value is not checked, just used, and
- besides, this condition only happens when the system has run out of
- memory. So just give up. */
- exit (EXIT_FAILURE);
+ oname = xasprintf ("%s_ertr%06d.o", dll_symname, tmp_seq);
tmp_seq++;
abfd = bfd_create (oname, parent);