+LONGEST
+target_write (struct target_ops *ops,
+ enum target_object object,
+ const char *annex, const gdb_byte *buf,
+ ULONGEST offset, LONGEST len)
+{
+ return target_write_with_progress (ops, object, annex, buf, offset, len,
+ NULL, NULL);
+}
+
+/* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
+ the size of the transferred data. PADDING additional bytes are
+ available in *BUF_P. This is a helper function for
+ target_read_alloc; see the declaration of that function for more
+ information. */
+
+static LONGEST
+target_read_alloc_1 (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte **buf_p, int padding)
+{
+ size_t buf_alloc, buf_pos;
+ gdb_byte *buf;
+ LONGEST n;
+
+ /* This function does not have a length parameter; it reads the
+ entire OBJECT). Also, it doesn't support objects fetched partly
+ from one target and partly from another (in a different stratum,
+ e.g. a core file and an executable). Both reasons make it
+ unsuitable for reading memory. */
+ gdb_assert (object != TARGET_OBJECT_MEMORY);
+
+ /* Start by reading up to 4K at a time. The target will throttle
+ this number down if necessary. */
+ buf_alloc = 4096;
+ buf = xmalloc (buf_alloc);
+ buf_pos = 0;
+ while (1)
+ {
+ n = target_read_partial (ops, object, annex, &buf[buf_pos],
+ buf_pos, buf_alloc - buf_pos - padding);
+ if (n < 0)
+ {
+ /* An error occurred. */
+ xfree (buf);
+ return -1;
+ }
+ else if (n == 0)
+ {
+ /* Read all there was. */
+ if (buf_pos == 0)
+ xfree (buf);
+ else
+ *buf_p = buf;
+ return buf_pos;
+ }
+
+ buf_pos += n;
+
+ /* If the buffer is filling up, expand it. */
+ if (buf_alloc < buf_pos * 2)
+ {
+ buf_alloc *= 2;
+ buf = xrealloc (buf, buf_alloc);
+ }
+
+ QUIT;
+ }
+}
+
+/* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
+ the size of the transferred data. See the declaration in "target.h"
+ function for more information about the return value. */
+
+LONGEST
+target_read_alloc (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte **buf_p)
+{
+ return target_read_alloc_1 (ops, object, annex, buf_p, 0);
+}
+
+/* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
+ returned as a string, allocated using xmalloc. If an error occurs
+ or the transfer is unsupported, NULL is returned. Empty objects
+ are returned as allocated but empty strings. A warning is issued
+ if the result contains any embedded NUL bytes. */
+
+char *
+target_read_stralloc (struct target_ops *ops, enum target_object object,
+ const char *annex)
+{
+ gdb_byte *buffer;
+ LONGEST transferred;
+
+ transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1);
+
+ if (transferred < 0)
+ return NULL;
+
+ if (transferred == 0)
+ return xstrdup ("");
+
+ buffer[transferred] = 0;
+ if (strlen (buffer) < transferred)
+ warning (_("target object %d, annex %s, "
+ "contained unexpected null characters"),
+ (int) object, annex ? annex : "(none)");
+
+ return (char *) buffer;
+}
+