* 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.
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>
/* 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 *));
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>
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;
+}
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);
+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>
-/* 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>
--- /dev/null
+/* 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);
+}