From a58593f784d4b84ce09f194c15bc79e20a80aa6a Mon Sep 17 00:00:00 2001 From: bernard Date: Wed, 25 Jun 2014 17:20:57 +0800 Subject: [libc] code cleanup. --- components/libc/armlibc/stubs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'components/libc') diff --git a/components/libc/armlibc/stubs.c b/components/libc/armlibc/stubs.c index 301f654182..d219b3430a 100644 --- a/components/libc/armlibc/stubs.c +++ b/components/libc/armlibc/stubs.c @@ -46,8 +46,10 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { +#ifdef RT_USING_DFS int fd; - +#endif + /* Register standard Input Output devices. */ if (strcmp(name, __stdin_name) == 0) return (STDIN); @@ -91,12 +93,13 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { +#ifdef RT_USING_DFS int size; - +#endif + if (fh == STDIN) { /* TODO */ - return 0; } @@ -125,8 +128,10 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { +#ifdef RT_USING_DFS int size; - +#endif + if ((fh == STDOUT) || (fh == STDERR)) { #ifndef RT_USING_CONSOLE -- cgit v1.3.1 From 59c128c0733c4b3ffa61558bb2ce8bf981c78adb Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 31 Jul 2014 09:30:18 +0800 Subject: [libc] fix compiling warning --- components/dfs/src/dfs_posix.c | 11 ++++++++--- components/libc/newlib/syscalls.c | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'components/libc') diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 96139837e9..a7d6159a1c 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -537,12 +537,17 @@ struct dirent *readdir(DIR *d) if (fd == RT_NULL) { rt_set_errno(-DFS_STATUS_EBADF); - return RT_NULL; } - if (!d->num || - (d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num) + if (d->num) + { + struct dirent* dirent_ptr; + dirent_ptr = (struct dirent*)&d->buf[d->cur]; + d->cur += dirent_ptr->d_reclen; + } + + if (!d->num || d->cur >= d->num) { /* get a new entry */ result = dfs_file_getdents(fd, diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 5b829f4753..388d240c94 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -3,6 +3,14 @@ #include #include +#ifdef RT_USING_DFS +#include +#endif + +#ifdef RT_USING_PTHREADS +#include +#endif + /* Reentrant versions of system calls. */ int -- cgit v1.3.1 From fccd0e6b8314ecc95bde542fe7031bc881dac722 Mon Sep 17 00:00:00 2001 From: bernard Date: Sun, 3 Aug 2014 14:30:31 +0800 Subject: [libc] Use __SIZE_TYPE__ instead of rt_size_t in minilibc. --- components/libc/minilibc/sys/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc') diff --git a/components/libc/minilibc/sys/types.h b/components/libc/minilibc/sys/types.h index 6d92d80826..a6860f2aee 100644 --- a/components/libc/minilibc/sys/types.h +++ b/components/libc/minilibc/sys/types.h @@ -4,7 +4,7 @@ #include typedef long off_t; -typedef rt_size_t size_t; +typedef __SIZE_TYPE__ size_t; typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */ typedef rt_uint8_t u_char; -- cgit v1.3.1 From 4ee93b75524e7194e5a9dc3468409e08e69e0663 Mon Sep 17 00:00:00 2001 From: bernard Date: Sun, 3 Aug 2014 14:31:19 +0800 Subject: [libc] Fix system issue when use msh and make code cleanup. --- components/libc/armlibc/mem_std.c | 22 ++++++++++++++++++---- components/libc/armlibc/stubs.c | 22 +++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'components/libc') diff --git a/components/libc/armlibc/mem_std.c b/components/libc/armlibc/mem_std.c index 017ed77fef..6faf86555f 100644 --- a/components/libc/armlibc/mem_std.c +++ b/components/libc/armlibc/mem_std.c @@ -1,7 +1,16 @@ /* - * File: mem_std.c - * Brief: Replace memory management functions of arm standard c library + * File : mem_std.c + * Brief : implement standard memory routins. * + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2014, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * 2014-08-03 bernard Add file header. */ #include "rtthread.h" @@ -9,16 +18,21 @@ /* avoid the heap and heap-using library functions supplied by arm */ #pragma import(__use_no_heap) -void * malloc(int n) +void *malloc(int n) { return rt_malloc(n); } -void * realloc(void *rmem, rt_size_t newsize) +void *realloc(void *rmem, rt_size_t newsize) { return rt_realloc(rmem, newsize); } +void *calloc(rt_size_t nelem, rt_size_t elsize) +{ + return rt_calloc(nelem, elsize); +} + void free(void *rmem) { rt_free(rmem); diff --git a/components/libc/armlibc/stubs.c b/components/libc/armlibc/stubs.c index d219b3430a..1f9e01ba3c 100644 --- a/components/libc/armlibc/stubs.c +++ b/components/libc/armlibc/stubs.c @@ -13,6 +13,8 @@ * Date Author Notes * 2012-11-23 Yihui The first version * 2013-11-24 aozima fixed _sys_read()/_sys_write() issues. + * 2014-08-03 bernard If using msh, use system() implementation + * in msh. */ #include @@ -194,9 +196,13 @@ char *_sys_command_string(char *cmd, int len) return cmd; } +/* This function writes a character to the console. */ void _ttywrch(int ch) { - /* TODO */ + char c; + + c = (char)ch; + rt_kprintf(&c); } void _sys_exit(int return_code) @@ -231,18 +237,12 @@ int remove(const char *filename) #endif } -/* rename() is defined in dfs_posix.c instead */ -#if 0 -int rename(const char *old, const char *new) -{ - return -1; -} -#endif - +#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS) +/* use system implementation in the msh */ +#else int system(const char *string) { RT_ASSERT(0); for(;;); } - - +#endif -- cgit v1.3.1