summaryrefslogtreecommitdiff
path: root/digital/ucoolib/ucoolib/arch
diff options
context:
space:
mode:
authorNicolas Schodet2012-12-22 09:42:44 +0100
committerNicolas Schodet2012-12-23 12:42:25 +0100
commit57510da98a112699188012b8505136d58594c274 (patch)
tree592eedc90a37f53d2ebc32fe111ff9853dfcfac0 /digital/ucoolib/ucoolib/arch
parent570345e49b5e1c0d4eb2bd9495c9a39de5a58b75 (diff)
digital/ucoolib/ucoolib/arch: implement read and write
Diffstat (limited to 'digital/ucoolib/ucoolib/arch')
-rw-r--r--digital/ucoolib/ucoolib/arch/syscalls.newlib.cc55
-rw-r--r--digital/ucoolib/ucoolib/arch/syscalls.newlib.hh35
2 files changed, 87 insertions, 3 deletions
diff --git a/digital/ucoolib/ucoolib/arch/syscalls.newlib.cc b/digital/ucoolib/ucoolib/arch/syscalls.newlib.cc
index f18712cc..02dd26f7 100644
--- a/digital/ucoolib/ucoolib/arch/syscalls.newlib.cc
+++ b/digital/ucoolib/ucoolib/arch/syscalls.newlib.cc
@@ -22,11 +22,14 @@
*
* }}} */
#include "ucoolib/common.hh"
+#include "syscalls.newlib.hh"
#include <reent.h>
#include <sys/stat.h>
#include <errno.h>
+ucoo::Stream *ucoo::syscalls_streams[3];
+
/** This is needed by C++ ABI, this simple definition will do. See:
* http://lists.debian.org/debian-gcc/2003/07/msg00057.html */
void *__dso_handle = (void*) &__dso_handle;
@@ -117,14 +120,60 @@ _open_r (struct _reent *ptr, const char *file, int flags, int mode)
extern "C" int
_read_r (struct _reent *ptr, int fd, void *buf, size_t cnt)
{
- return 0;
+ if (fd == 0)
+ {
+ if (ucoo::syscalls_streams[0])
+ {
+ ucoo::Stream &s = *ucoo::syscalls_streams[0];
+ int r = s.read (reinterpret_cast<char *> (buf), cnt);
+ switch (r)
+ {
+ case -2:
+ return 0;
+ case -1:
+ ptr->_errno = EIO;
+ return -1;
+ case 0:
+ ptr->_errno = EAGAIN;
+ return -1;
+ default:
+ return r;
+ }
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ ptr->_errno = EBADF;
+ return -1;
+ }
}
/** Write to file, to be improved to write to stream. */
extern "C" int
_write_r (struct _reent *ptr, int fd, const void *buf, size_t cnt)
{
- ptr->_errno = EBADF;
- return -1;
+ if ((fd == 1 || fd == 2) && ucoo::syscalls_streams[fd])
+ {
+ ucoo::Stream &s = *ucoo::syscalls_streams[fd];
+ int r = s.write (reinterpret_cast<const char *> (buf), cnt);
+ switch (r)
+ {
+ case -1:
+ ptr->_errno = EIO;
+ return -1;
+ case 0:
+ ptr->_errno = EAGAIN;
+ return -1;
+ default:
+ return r;
+ }
+ }
+ else
+ {
+ ptr->_errno = EBADF;
+ return -1;
+ }
}
diff --git a/digital/ucoolib/ucoolib/arch/syscalls.newlib.hh b/digital/ucoolib/ucoolib/arch/syscalls.newlib.hh
new file mode 100644
index 00000000..be83e85e
--- /dev/null
+++ b/digital/ucoolib/ucoolib/arch/syscalls.newlib.hh
@@ -0,0 +1,35 @@
+#ifndef ucoolib_arch_syscalls_newlib_hh
+#define ucoolib_arch_syscalls_newlib_hh
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// APBTeam:
+// Web: http://apbteam.org/
+// Email: team AT apbteam DOT org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "ucoolib/intf/stream.hh"
+
+namespace ucoo {
+
+// Streams used as stdin, stdout and stderr.
+extern Stream *syscalls_streams[3];
+
+} // namespace ucoo
+
+#endif // ucoolib_arch_syscalls_newlib_hh