From 87171f003cc1d4f6aae11a63a06e1aacaf4c7a14 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 28 Jan 2015 14:14:30 +0800 Subject: [PATCH] [LIBC] code cleanup --- components/libc/armlibc/stubs.c | 72 ++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/components/libc/armlibc/stubs.c b/components/libc/armlibc/stubs.c index b74710e05..bd57ca4c5 100644 --- a/components/libc/armlibc/stubs.c +++ b/components/libc/armlibc/stubs.c @@ -13,7 +13,7 @@ * 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 + * 2014-08-03 bernard If using msh, use system() implementation * in msh. */ @@ -48,11 +48,11 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_DFS +#ifdef RT_USING_DFS int fd; int mode = O_RDONLY; #endif - + /* Register standard Input Output devices. */ if (strcmp(name, __stdin_name) == 0) return (STDIN); @@ -64,34 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode) #ifndef RT_USING_DFS return -1; #else - /* Correct openmode from fopen to open */ - if (openmode & OPEN_PLUS) - { - if (openmode & OPEN_W) - { - mode |= (O_RDWR | O_TRUNC | O_CREAT); - } - else if (openmode & OPEN_A) - { - mode |= (O_RDWR | O_APPEND | O_CREAT); - } - else - mode |= O_RDWR; - } - else - { - if (openmode & OPEN_W) - { - mode |= (O_WRONLY | O_TRUNC | O_CREAT); - } - else if (openmode & OPEN_A) - { + /* Correct openmode from fopen to open */ + if (openmode & OPEN_PLUS) + { + if (openmode & OPEN_W) + { + mode |= (O_RDWR | O_TRUNC | O_CREAT); + } + else if (openmode & OPEN_A) + { + mode |= (O_RDWR | O_APPEND | O_CREAT); + } + else + mode |= O_RDWR; + } + else + { + if (openmode & OPEN_W) + { + mode |= (O_WRONLY | O_TRUNC | O_CREAT); + } + else if (openmode & OPEN_A) + { mode |= (O_WRONLY | O_APPEND | O_CREAT); - } - } + } + } fd = open(name, mode, 0); - if(fd < 0) + if (fd < 0) return -1; else return fd + STDERR + 1; @@ -121,10 +121,10 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_USING_DFS int size; #endif - + if (fh == STDIN) { /* TODO */ @@ -138,7 +138,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) return 0; #else size = read(fh - STDERR - 1, buf, len); - if(size >= 0) + if (size >= 0) return len - size; else return -1; @@ -159,7 +159,7 @@ 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 @@ -170,18 +170,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) console_device = rt_console_get_device(); if (console_device != 0) rt_device_write(console_device, 0, buf, len); - return 0; + return 0; #endif } - if(fh == STDIN) + if (fh == STDIN) return -1; #ifndef RT_USING_DFS return 0; #else size = write(fh - STDERR - 1, buf, len); - if(size >= 0) + if (size >= 0) return len - size; else return -1; @@ -270,6 +270,6 @@ int remove(const char *filename) int system(const char *string) { RT_ASSERT(0); - for(;;); + for (;;); } #endif