[LIBC] code cleanup

This commit is contained in:
Bernard Xiong 2015-01-28 14:14:30 +08:00
parent 01c3460cdb
commit 87171f003c

View File

@ -64,34 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode)
#ifndef RT_USING_DFS #ifndef RT_USING_DFS
return -1; return -1;
#else #else
/* Correct openmode from fopen to open */ /* Correct openmode from fopen to open */
if (openmode & OPEN_PLUS) if (openmode & OPEN_PLUS)
{ {
if (openmode & OPEN_W) if (openmode & OPEN_W)
{ {
mode |= (O_RDWR | O_TRUNC | O_CREAT); mode |= (O_RDWR | O_TRUNC | O_CREAT);
} }
else if (openmode & OPEN_A) else if (openmode & OPEN_A)
{ {
mode |= (O_RDWR | O_APPEND | O_CREAT); mode |= (O_RDWR | O_APPEND | O_CREAT);
} }
else else
mode |= O_RDWR; mode |= O_RDWR;
} }
else else
{ {
if (openmode & OPEN_W) if (openmode & OPEN_W)
{ {
mode |= (O_WRONLY | O_TRUNC | O_CREAT); mode |= (O_WRONLY | O_TRUNC | O_CREAT);
} }
else if (openmode & OPEN_A) else if (openmode & OPEN_A)
{ {
mode |= (O_WRONLY | O_APPEND | O_CREAT); mode |= (O_WRONLY | O_APPEND | O_CREAT);
} }
} }
fd = open(name, mode, 0); fd = open(name, mode, 0);
if(fd < 0) if (fd < 0)
return -1; return -1;
else else
return fd + STDERR + 1; return fd + STDERR + 1;
@ -138,7 +138,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
return 0; return 0;
#else #else
size = read(fh - STDERR - 1, buf, len); size = read(fh - STDERR - 1, buf, len);
if(size >= 0) if (size >= 0)
return len - size; return len - size;
else else
return -1; return -1;
@ -170,18 +170,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
console_device = rt_console_get_device(); console_device = rt_console_get_device();
if (console_device != 0) rt_device_write(console_device, 0, buf, len); if (console_device != 0) rt_device_write(console_device, 0, buf, len);
return 0; return 0;
#endif #endif
} }
if(fh == STDIN) if (fh == STDIN)
return -1; return -1;
#ifndef RT_USING_DFS #ifndef RT_USING_DFS
return 0; return 0;
#else #else
size = write(fh - STDERR - 1, buf, len); size = write(fh - STDERR - 1, buf, len);
if(size >= 0) if (size >= 0)
return len - size; return len - size;
else else
return -1; return -1;
@ -270,6 +270,6 @@ int remove(const char *filename)
int system(const char *string) int system(const char *string)
{ {
RT_ASSERT(0); RT_ASSERT(0);
for(;;); for (;;);
} }
#endif #endif