[LIBC] code cleanup
This commit is contained in:
parent
01c3460cdb
commit
87171f003c
|
@ -13,7 +13,7 @@
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-11-23 Yihui The first version
|
* 2012-11-23 Yihui The first version
|
||||||
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
|
* 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.
|
* in msh.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -48,11 +48,11 @@ const char __stderr_name[] = "STDERR";
|
||||||
*/
|
*/
|
||||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
int fd;
|
int fd;
|
||||||
int mode = O_RDONLY;
|
int mode = O_RDONLY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Register standard Input Output devices. */
|
/* Register standard Input Output devices. */
|
||||||
if (strcmp(name, __stdin_name) == 0)
|
if (strcmp(name, __stdin_name) == 0)
|
||||||
return (STDIN);
|
return (STDIN);
|
||||||
|
@ -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;
|
||||||
|
@ -121,10 +121,10 @@ int _sys_close(FILEHANDLE fh)
|
||||||
*/
|
*/
|
||||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
int size;
|
int size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fh == STDIN)
|
if (fh == STDIN)
|
||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
|
@ -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;
|
||||||
|
@ -159,7 +159,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
int size;
|
int size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((fh == STDOUT) || (fh == STDERR))
|
if ((fh == STDOUT) || (fh == STDERR))
|
||||||
{
|
{
|
||||||
#ifndef RT_USING_CONSOLE
|
#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();
|
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
|
||||||
|
|
Loading…
Reference in New Issue