2007-10-11 Jesper Nilsson <jesper.nilsson@axis.com>
authorDaniel Jacobowitz <drow@false.org>
Thu, 11 Oct 2007 18:44:07 +0000 (18:44 +0000)
committerDaniel Jacobowitz <drow@false.org>
Thu, 11 Oct 2007 18:44:07 +0000 (18:44 +0000)
* callback.c (cb_is_stdin, cb_is_stdout, cb_is_stderr): Add functions.
* syscall.c (cb_syscall): Test for stdin/out/err, not just fd 0/1/2.

2007-10-11  Jesper Nilsson  <jesper.nilsson@axis.com>

* callback.h (cb_is_stdin, cb_is_stdout, cb_is_stderr): Add prototypes.

2007-10-11  Jesper Nilsson  <jesper.nilsson@axis.com>

* sim/cris/c/freopen2.c: Added testcase.

include/gdb/ChangeLog
include/gdb/callback.h
sim/common/ChangeLog
sim/common/callback.c
sim/common/syscall.c
sim/testsuite/ChangeLog
sim/testsuite/sim/cris/c/freopen1.c
sim/testsuite/sim/cris/c/freopen2.c [new file with mode: 0644]

index 70266e2ccfa95d97e45382dddbc6248f9ffe890d..67e5d970d5672440fcdbe6b593d946fd15885fa3 100644 (file)
@@ -1,6 +1,6 @@
 2007-10-11  Jesper Nilsson  <jesper.nilsson@axis.com>
 
-       * callback.h (cb_is_stdin): Add prototype.
+       * callback.h (cb_is_stdin, cb_is_stdout, cb_is_stderr): Add prototypes.
 
 2007-08-23  Joel Brobecker  <brobecker@adacore.com>
 
index 2245c87dc430846cdc04132aa258a3ec384ba95d..eb991f74eca36e80f67d0b75a54a59c2c980cbb8 100644 (file)
@@ -315,8 +315,10 @@ int cb_host_to_target_stat PARAMS ((host_callback *, const struct stat *, PTR));
 /* Translate a value to target endian.  */
 void cb_store_target_endian PARAMS ((host_callback *, char *, int, long));
 
-/* Test if the fd is stdin. */
+/* Tests for special fds.  */
 int cb_is_stdin PARAMS ((host_callback *, int));
+int cb_is_stdout PARAMS ((host_callback *, int));
+int cb_is_stderr PARAMS ((host_callback *, int));
 
 /* Perform a system call.  */
 CB_RC cb_syscall PARAMS ((host_callback *, CB_SYSCALL *));
index bd09a5c536639b691c9f206cd9080f418e33d4f1..87bc0ee2f27980601929617db9da3f3edfa802f7 100644 (file)
@@ -1,7 +1,7 @@
 2007-10-11  Jesper Nilsson  <jesper.nilsson@axis.com>
 
-       * callback.c (cb_is_stdin): Add.
-       * syscall.c (cb_syscall): Test for stdin, not just fd 0.
+       * callback.c (cb_is_stdin, cb_is_stdout, cb_is_stderr): Add functions.
+       * syscall.c (cb_syscall): Test for stdin/out/err, not just fd 0/1/2.
 
 2007-08-10  Nick Clifton  <nickc@redhat.com>
 
index f83dd547c220e49d0be3c32cbfdab0b1222e0d31..18bcc80d4d62b79f569514d18e2c347396b6fb4c 100644 (file)
@@ -1143,3 +1143,14 @@ cb_is_stdin (host_callback *cb, int fd)
   return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 0;
 }
 
+int
+cb_is_stdout (host_callback *cb, int fd)
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 1;
+}
+
+int
+cb_is_stderr (host_callback *cb, int fd)
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 2;
+}
index a3e7560bf484977a4446c8b838fa8cb5c88effb3..b00244882f909d9941ac5f1a650a98d02eb5c133 100644 (file)
@@ -344,12 +344,12 @@ cb_syscall (cb, sc)
                errcode = EINVAL;
                goto FinishSyscall;
              }
-           if (fd == 1)
+           if (cb_is_stdout(cb, fd))
              {
                result = (int) (*cb->write_stdout) (cb, buf, bytes_read);
                (*cb->flush_stdout) (cb);
              }
-           else if (fd == 2)
+           else if (cb_is_stderr(cb, fd))
              {
                result = (int) (*cb->write_stderr) (cb, buf, bytes_read);
                (*cb->flush_stderr) (cb);
index c7c0acca51a1a91882533e20177ecedd41355ec4..168b05d9e4d71e37c096f0cfe3167236b7c7c28f 100644 (file)
@@ -1,3 +1,7 @@
+2007-10-11  Jesper Nilsson  <jesper.nilsson@axis.com>
+
+       * sim/cris/c/freopen2.c: Added testcase.
+
 2006-10-02  Hans-Peter Nilsson  <hp@axis.com>
            Edgar E. Iglesias  <edgar@axis.com>
 
index eeb6079fdb51f66c92a8607aca1e527c03312205..0e0f28d9615c865155c772d7e9a7742d7511c5a7 100644 (file)
@@ -1,7 +1,4 @@
-/* Check that basic freopen functionality works.
-#xfail: *-*-*
-   Currently doesn't work, because syscall.c:cb_syscall case
-   CB_SYS_write intercepts writes to fd 1 and 2.  */
+/* Check that basic freopen functionality works.  */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/testsuite/sim/cris/c/freopen2.c b/sim/testsuite/sim/cris/c/freopen2.c
new file mode 100644 (file)
index 0000000..3959607
--- /dev/null
@@ -0,0 +1,40 @@
+/* Tests that stdin can be redirected from a normal file.  */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (void)
+{
+   const char* fname = "freopen.dat";
+   const char tsttxt[]
+       = "A random line of text, used to test correct freopen etc.\n";
+   FILE* instream;
+   FILE *old_stderr;
+   char c1;
+
+   /* Like the freopen call in flex.  */
+   old_stderr = freopen (fname, "w+", stderr);
+   if (old_stderr == NULL
+      || fwrite (tsttxt, 1, strlen (tsttxt), stderr) != strlen (tsttxt)
+      || fclose (stderr) != 0)
+   {
+      printf ("fail\n");
+      exit (1);
+   }
+
+   instream = freopen(fname, "r", stdin);
+   if (instream == NULL) {
+      printf("fail\n");
+      exit(1);
+   }
+
+   c1 = getc(instream);
+   if (c1 != 'A') {
+      printf("fail\n");
+      exit(1);
+   }
+
+   printf ("pass\n");
+   exit(0);
+}
This page took 0.032233 seconds and 4 git commands to generate.