提交 db2ceea2 编写于 作者: B bernard.xiong@gmail.com

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
上级 c11a30db
...@@ -10,6 +10,7 @@ void libc_system_init(const char* tty_name) ...@@ -10,6 +10,7 @@ void libc_system_init(const char* tty_name)
int fd; int fd;
extern int pthread_system_init(void); extern int pthread_system_init(void);
#ifdef RT_USING_DFS
#ifndef RT_USING_DFS_DEVFS #ifndef RT_USING_DFS_DEVFS
#error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h #error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h
#endif #endif
...@@ -21,6 +22,7 @@ void libc_system_init(const char* tty_name) ...@@ -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_RDONLY, 0); /* for stdin */
fd = open("/dev/console", O_WRONLY, 0); /* for stdout */ fd = open("/dev/console", O_WRONLY, 0); /* for stdout */
fd = open("/dev/console", O_WRONLY, 0); /* for stderr */ fd = open("/dev/console", O_WRONLY, 0); /* for stderr */
#endif
/* set PATH and HOME */ /* set PATH and HOME */
putenv("PATH=/"); putenv("PATH=/");
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
int int
_close_r(struct _reent *ptr, int fd) _close_r(struct _reent *ptr, int fd)
{ {
#ifndef RT_USING_DFS
return 0;
#else
return close(fd); return close(fd);
#endif
} }
int int
...@@ -78,46 +82,66 @@ _link_r(struct _reent *ptr, const char *old, const char *new) ...@@ -78,46 +82,66 @@ _link_r(struct _reent *ptr, const char *old, const char *new)
_off_t _off_t
_lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{ {
#ifndef RT_USING_DfS
return 0;
#else
_off_t rc; _off_t rc;
rc = lseek(fd, pos, whence); rc = lseek(fd, pos, whence);
return rc; return rc;
#endif
} }
int int
_mkdir_r(struct _reent *ptr, const char *name, int mode) _mkdir_r(struct _reent *ptr, const char *name, int mode)
{ {
#ifndef RT_USING_DFS
return 0;
#else
int rc; int rc;
rc = mkdir(name, mode); rc = mkdir(name, mode);
return rc; return rc;
#endif
} }
int int
_open_r(struct _reent *ptr, const char *file, int flags, int mode) _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{ {
#ifndef RT_USING_DFS
return 0;
#else
int rc; int rc;
rc = open(file, flags, mode); rc = open(file, flags, mode);
return rc; return rc;
#endif
} }
_ssize_t _ssize_t
_read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{ {
#ifndef RT_USING_DFS
return 0;
#else
_ssize_t rc; _ssize_t rc;
rc = read(fd, buf, nbytes); rc = read(fd, buf, nbytes);
return rc; return rc;
#endif
} }
int int
_rename_r(struct _reent *ptr, const char *old, const char *new) _rename_r(struct _reent *ptr, const char *old, const char *new)
{ {
#ifndef RT_USING_DFS
return 0;
#else
int rc; int rc;
rc = rename(old, new); rc = rename(old, new);
return rc; return rc;
#endif
} }
void * void *
...@@ -130,10 +154,14 @@ _sbrk_r(struct _reent *ptr, ptrdiff_t incr) ...@@ -130,10 +154,14 @@ _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
int int
_stat_r(struct _reent *ptr, const char *file, struct stat *pstat) _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{ {
#ifndef RT_USING_DFS
return 0;
#else
int rc; int rc;
rc = stat(file, pstat); rc = stat(file, pstat);
return rc; return rc;
#endif
} }
_CLOCK_T_ _CLOCK_T_
...@@ -147,10 +175,14 @@ _times_r(struct _reent *ptr, struct tms *ptms) ...@@ -147,10 +175,14 @@ _times_r(struct _reent *ptr, struct tms *ptms)
int int
_unlink_r(struct _reent *ptr, const char *file) _unlink_r(struct _reent *ptr, const char *file)
{ {
#ifndef RT_USING_DFS
return 0;
#else
int rc; int rc;
rc = unlink(file); rc = unlink(file);
return rc; return rc;
#endif
} }
int int
...@@ -164,10 +196,23 @@ _wait_r(struct _reent *ptr, int *status) ...@@ -164,10 +196,23 @@ _wait_r(struct _reent *ptr, int *status)
_ssize_t _ssize_t
_write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) _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; _ssize_t rc;
rc = write(fd, buf, nbytes); rc = write(fd, buf, nbytes);
return rc; return rc;
#endif
} }
#ifndef RT_USING_PTHREADS #ifndef RT_USING_PTHREADS
...@@ -332,4 +377,6 @@ _exit (int status) ...@@ -332,4 +377,6 @@ _exit (int status)
{ {
rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status); rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status);
RT_ASSERT(0); RT_ASSERT(0);
while (1);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册