/* Remote target system call support.
- Copyright 1997 Free Software Foundation, Inc.
+ Copyright 1997, 1998 Free Software Foundation, Inc.
Contributed by Cygnus Solutions.
This file is part of GDB.
/* When doing file read/writes, do this many bytes at a time. */
#define FILE_XFR_SIZE 4096
-/* FIXME: for now */
-#define TWORD unsigned long
+/* FIXME: for now, need to consider target word size. */
+#define TWORD long
#define TADDR unsigned long
/* Utility of cb_syscall to fetch a path name or other string from the target.
}
/* Perform a system call on behalf of the target. */
-/* FIXME: TODO: Add magic number to CB_SYSCALL, macro to initialize it,
- and test for the magic number here. */
CB_RC
cb_syscall (cb, sc)
host_callback *cb;
CB_SYSCALL *sc;
{
- /* ??? Need to consider target word size. */
- long result = 0, errcode = 0;
+ TWORD result = 0, errcode = 0;
+
+ if (sc->magic != CB_SYSCALL_MAGIC)
+ abort ();
switch (cb_target_to_host_syscall (cb, sc->func))
{
? count : FILE_XFR_SIZE));
if (result == -1)
goto ErrorFinish;
+ if (result == 0) /* EOF */
+ break;
bytes_written = (*sc->write_mem) (cb, sc, addr, buf, result);
if (bytes_written != result)
{
bytes_read += result;
count -= result;
addr += result;
+ /* If this is a short read, don't go back for more */
+ if (result != FILE_XFR_SIZE)
+ break;
}
result = bytes_read;
}
goto FinishSyscall;
}
if (fd == 1)
- result = (int) (*cb->write_stdout) (cb, buf, bytes_read);
- if (fd == 2)
- result = (int) (*cb->write_stderr) (cb, buf, bytes_read);
+ {
+ result = (int) (*cb->write_stdout) (cb, buf, bytes_read);
+ (*cb->flush_stdout) (cb);
+ }
+ else if (fd == 2)
+ {
+ result = (int) (*cb->write_stderr) (cb, buf, bytes_read);
+ (*cb->flush_stderr) (cb);
+ }
else
result = (int) (*cb->write) (cb, fd, buf, bytes_read);
if (result == -1)
result = -1;
goto FinishSyscall;
}
- /* ??? Coercion to unsigned avoids -Wall -Werror failure.
- Ya, cb_host_to_target_stat could return an unsigned int,
- but that seems worse. */
- if ((*sc->write_mem) (cb, sc, addr, buf, buflen) != (unsigned) buflen)
+ if ((*sc->write_mem) (cb, sc, addr, buf, buflen) != buflen)
{
free (buf);
errcode = EINVAL;
result = -1;
goto FinishSyscall;
}
- /* ??? Coercion to unsigned avoids -Wall -Werror failure.
- Ya, cb_host_to_target_stat could return an unsigned int,
- but that seems worse. */
- if ((*sc->write_mem) (cb, sc, addr, buf, buflen) != (unsigned) buflen)
+ if ((*sc->write_mem) (cb, sc, addr, buf, buflen) != buflen)
{
free (buf);
errcode = EINVAL;