From db2ceea2ce5dd9992be92de79d42ed0fe18ca71a Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Fri, 17 Feb 2012 16:26:49 +0000 Subject: [PATCH] remove the dependence of device file system when enable newlib. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1955 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/libc/newlib/libc.c | 2 ++ components/libc/newlib/syscalls.c | 47 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/components/libc/newlib/libc.c b/components/libc/newlib/libc.c index bd3797b6c4..797c393db8 100644 --- a/components/libc/newlib/libc.c +++ b/components/libc/newlib/libc.c @@ -10,6 +10,7 @@ void libc_system_init(const char* tty_name) int fd; extern int pthread_system_init(void); +#ifdef RT_USING_DFS #ifndef RT_USING_DFS_DEVFS #error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h #endif @@ -21,6 +22,7 @@ void libc_system_init(const char* tty_name) fd = open("/dev/console", O_RDONLY, 0); /* for stdin */ fd = open("/dev/console", O_WRONLY, 0); /* for stdout */ fd = open("/dev/console", O_WRONLY, 0); /* for stderr */ +#endif /* set PATH and HOME */ putenv("PATH=/"); diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 3baef81419..7b918f2eb5 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -8,7 +8,11 @@ int _close_r(struct _reent *ptr, int fd) { +#ifndef RT_USING_DFS + return 0; +#else return close(fd); +#endif } int @@ -78,46 +82,66 @@ _link_r(struct _reent *ptr, const char *old, const char *new) _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { +#ifndef RT_USING_DfS + return 0; +#else _off_t rc; rc = lseek(fd, pos, whence); return rc; +#endif } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { +#ifndef RT_USING_DFS + return 0; +#else int rc; rc = mkdir(name, mode); return rc; +#endif } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { +#ifndef RT_USING_DFS + return 0; +#else int rc; rc = open(file, flags, mode); return rc; +#endif } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { +#ifndef RT_USING_DFS + return 0; +#else _ssize_t rc; rc = read(fd, buf, nbytes); return rc; +#endif } int _rename_r(struct _reent *ptr, const char *old, const char *new) { +#ifndef RT_USING_DFS + return 0; +#else int rc; rc = rename(old, new); return rc; +#endif } void * @@ -130,10 +154,14 @@ _sbrk_r(struct _reent *ptr, ptrdiff_t incr) int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { +#ifndef RT_USING_DFS + return 0; +#else int rc; rc = stat(file, pstat); return rc; +#endif } _CLOCK_T_ @@ -147,10 +175,14 @@ _times_r(struct _reent *ptr, struct tms *ptms) int _unlink_r(struct _reent *ptr, const char *file) { +#ifndef RT_USING_DFS + return 0; +#else int rc; rc = unlink(file); return rc; +#endif } int @@ -164,10 +196,23 @@ _wait_r(struct _reent *ptr, int *status) _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { +#ifndef RT_USING_DFS + if (fd < 3) + { + rt_device_t console_device; + extern rt_device_t rt_console_get_device(void); + + console_device = rt_console_get_device(); + if (console_device != 0) rt_device_write(console_device, 0, buf, nbytes); + return nbytes; + } + return 0; +#else _ssize_t rc; rc = write(fd, buf, nbytes); return rc; +#endif } #ifndef RT_USING_PTHREADS @@ -332,4 +377,6 @@ _exit (int status) { rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status); RT_ASSERT(0); + + while (1); }