From eb639c500494ee8c4ca8978c50451dca10112744 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Thu, 11 Oct 2007 18:44:07 +0000 Subject: 2007-10-11 Jesper Nilsson * 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 * callback.h (cb_is_stdin, cb_is_stdout, cb_is_stderr): Add prototypes. 2007-10-11 Jesper Nilsson * sim/cris/c/freopen2.c: Added testcase. --- sim/common/ChangeLog | 4 ++-- sim/common/callback.c | 11 +++++++++++ sim/common/syscall.c | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'sim/common') diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index bd09a5c..87bc0ee 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,7 +1,7 @@ 2007-10-11 Jesper Nilsson - * 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 diff --git a/sim/common/callback.c b/sim/common/callback.c index f83dd54..18bcc80 100644 --- a/sim/common/callback.c +++ b/sim/common/callback.c @@ -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; +} diff --git a/sim/common/syscall.c b/sim/common/syscall.c index a3e7560..b002448 100644 --- a/sim/common/syscall.c +++ b/sim/common/syscall.c @@ -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); -- cgit v1.1