#include "defs.h"
#include "ui-file.h"
#include "gdb_string.h"
+#include "gdb_select.h"
#include <errno.h>
}
char *
-ui_file_xstrdup (struct ui_file *file,
- long *length)
+ui_file_xstrdup (struct ui_file *file, long *length)
{
struct accumulated_ui_file acc;
acc.buffer = NULL;
ui_file_put (file, do_ui_file_xstrdup, &acc);
if (acc.buffer == NULL)
acc.buffer = xstrdup ("");
- *length = acc.length;
+ if (length != NULL)
+ *length = acc.length;
return acc.buffer;
}
\f
if (stdio->magic != &stdio_file_magic)
internal_error (__FILE__, __LINE__,
_("stdio_file_read: bad magic number"));
+
+ /* For the benefit of Windows, call gdb_select before reading from
+ the file. Wait until at least one byte of data is available.
+ Control-C can interrupt gdb_select, but not read. */
+ {
+ int fd = fileno (stdio->file);
+ fd_set readfds;
+ FD_ZERO (&readfds);
+ FD_SET (fd, &readfds);
+ if (gdb_select (fd + 1, &readfds, NULL, NULL, NULL) == -1)
+ return -1;
+ }
+
return read (fileno (stdio->file), buf, length_buf);
}