This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / sim / common / syscall.c
index fbeb24cb378e6fc2403947cb87e0ccb73adc5862..e0a3b880b84c26a061b8e3a2400ce6c5f78cda49 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
@@ -64,8 +64,8 @@
 /* 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.
@@ -123,16 +123,16 @@ get_path (cb, sc, addr, bufp)
 }
 
 /* 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))
     {
@@ -279,6 +279,8 @@ cb_syscall (cb, sc)
                                           ? 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)
              {
@@ -289,6 +291,9 @@ cb_syscall (cb, sc)
            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;
       }
@@ -318,9 +323,15 @@ cb_syscall (cb, sc)
                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)
@@ -390,10 +401,7 @@ cb_syscall (cb, sc)
            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;
@@ -425,10 +433,7 @@ cb_syscall (cb, sc)
            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;
This page took 0.024688 seconds and 4 git commands to generate.