/* Helper routines for parsing XML using Expat.
- Copyright (C) 2006-2018 Free Software Foundation, Inc.
+ Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "gdbcmd.h"
#include "xml-support.h"
-#include "filestuff.h"
+#include "common/filestuff.h"
#include "safe-ctype.h"
#include <vector>
#include <string>
gdb_xml_parser::vdebug (const char *format, va_list ap)
{
int line = XML_GetCurrentLineNumber (m_expat_parser);
- char *message;
- message = xstrvprintf (format, ap);
+ std::string message = string_vprintf (format, ap);
if (line)
fprintf_unfiltered (gdb_stderr, "%s (line %d): %s\n",
- m_name, line, message);
+ m_name, line, message.c_str ());
else
fprintf_unfiltered (gdb_stderr, "%s: %s\n",
- m_name, message);
- xfree (message);
+ m_name, message.c_str ());
}
void
gdb_xml_error (parser, _("Maximum XInclude depth (%d) exceeded"),
MAX_XINCLUDE_DEPTH);
- gdb::unique_xmalloc_ptr<char> text = data->fetcher (href,
- data->fetcher_baton);
- if (text == NULL)
+ gdb::optional<gdb::char_vector> text
+ = data->fetcher (href, data->fetcher_baton);
+ if (!text)
gdb_xml_error (parser, _("Could not load XML document \"%s\""), href);
if (!xml_process_xincludes (data->output, parser->name (),
- text.get (), data->fetcher,
+ text->data (), data->fetcher,
data->fetcher_baton,
data->include_depth + 1))
gdb_xml_error (parser, _("Parsing \"%s\" failed"), href);
fprintf_filtered (file, _("XML debugging is %s.\n"), value);
}
-gdb::unique_xmalloc_ptr<char>
+gdb::optional<gdb::char_vector>
xml_fetch_content_from_file (const char *filename, void *baton)
{
const char *dirname = (const char *) baton;
file = gdb_fopen_cloexec (filename, FOPEN_RT);
if (file == NULL)
- return NULL;
+ return {};
/* Read in the whole file. */
len = ftell (file.get ());
rewind (file.get ());
- gdb::unique_xmalloc_ptr<char> text ((char *) xmalloc (len + 1));
+ gdb::char_vector text (len + 1);
- if (fread (text.get (), 1, len, file.get ()) != len
+ if (fread (text.data (), 1, len, file.get ()) != len
|| ferror (file.get ()))
{
warning (_("Read error from \"%s\""), filename);
- return NULL;
+ return {};
}
- text.get ()[len] = '\0';
+ text.back () = '\0';
return text;
}