#include "inf-child.h"
#include "gdb/fileio.h"
#include "agent.h"
+#include "gdb_wait.h"
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> /* for MAXPATHLEN */
#include <fcntl.h>
#include <unistd.h>
+/* Helper function for child_wait and the derivatives of child_wait.
+ HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
+ translation of that in OURSTATUS. */
+void
+store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
+{
+ if (WIFEXITED (hoststatus))
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = WEXITSTATUS (hoststatus);
+ }
+ else if (!WIFSTOPPED (hoststatus))
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = gdb_signal_from_host (WTERMSIG (hoststatus));
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_STOPPED;
+ ourstatus->value.sig = gdb_signal_from_host (WSTOPSIG (hoststatus));
+ }
+}
+
/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
for all registers. */
#ifdef HAVE_PWRITE
ret = pwrite (fd, write_buf, len, (long) offset);
#else
- ret = lseek (fd, (long) offset, SEEK_SET);
- if (ret != -1)
- ret = write (fd, write_buf, len);
+ ret = -1;
#endif
+ /* If we have no pwrite or it failed for this file, use lseek/write. */
+ if (ret == -1)
+ {
+ ret = lseek (fd, (long) offset, SEEK_SET);
+ if (ret != -1)
+ ret = write (fd, write_buf, len);
+ }
if (ret == -1)
*target_errno = inf_child_errno_to_fileio_error (errno);
#ifdef HAVE_PREAD
ret = pread (fd, read_buf, len, (long) offset);
#else
- ret = lseek (fd, (long) offset, SEEK_SET);
- if (ret != -1)
- ret = read (fd, read_buf, len);
+ ret = -1;
#endif
+ /* If we have no pread or it failed for this file, use lseek/read. */
+ if (ret == -1)
+ {
+ ret = lseek (fd, (long) offset, SEEK_SET);
+ if (ret != -1)
+ ret = read (fd, read_buf, len);
+ }
if (ret == -1)
*target_errno = inf_child_errno_to_fileio_error (errno);