From 5aa095298d974b4faacfaa4fb4f4ff4c65db514a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 3 Sep 2015 11:15:05 +1000 Subject: [PATCH] libc syscalls: ENOSYS implementations for open,fstat,close,lseek Closes #41 --- core/newlib_syscalls.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/newlib_syscalls.c b/core/newlib_syscalls.c index bb35ce0..767dd2d 100644 --- a/core/newlib_syscalls.c +++ b/core/newlib_syscalls.c @@ -65,20 +65,19 @@ long _read_r( struct _reent *r, int fd, char *ptr, int len ) return len; } -/* These are stub implementations for the reentrant syscalls that - * newlib is configured to expect */ -int _fstat_r(struct _reent *r, int fd, void *buf) +/* Stub syscall implementations follow, to allow compiling newlib functions that + pull these in via various codepaths +*/ +__attribute__((alias("syscall_returns_enosys"))) int _open_r(struct _reent *r, const char *pathname, int flags, int mode); +__attribute__((alias("syscall_returns_enosys"))) int _fstat_r(struct _reent *r, int fd, void *buf); +__attribute__((alias("syscall_returns_enosys"))) int _close_r(struct _reent *r, int fd); +__attribute__((alias("syscall_returns_enosys"))) off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence); + +/* Generic stub for any newlib syscall that fails with errno ENOSYS + ("Function not implemented") and a return value equivalent to + (int)-1. */ +static int syscall_returns_enosys(struct _reent *r) { + r->_errno=ENOSYS; return -1; } - -int _close_r(struct _reent *r, int fd) -{ - return -1; -} - -off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence) -{ - return (off_t)-1; -} -