[LIBC] fix the fopen/open issue in armlibc

This commit is contained in:
Bernard Xiong 2014-10-30 03:53:22 +00:00
parent 692e597847
commit 0797e54f3f
1 changed files with 29 additions and 5 deletions

View File

@ -50,6 +50,7 @@ FILEHANDLE _sys_open(const char *name, int openmode)
{
#ifdef RT_USING_DFS
int fd;
int mode = O_RDONLY;
#endif
/* Register standard Input Output devices. */
@ -63,8 +64,33 @@ FILEHANDLE _sys_open(const char *name, int openmode)
#ifndef RT_USING_DFS
return -1;
#else
/* TODO: adjust open file mode */
fd = open(name, openmode, 0);
/* 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)
return -1;
else
@ -140,7 +166,6 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return 0;
#else
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, len);
@ -227,7 +252,6 @@ int _sys_istty(FILEHANDLE fh)
return 0;
}
int remove(const char *filename)
{
#ifndef RT_USING_DFS
@ -238,7 +262,7 @@ int remove(const char *filename)
}
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
/* use system implementation in the msh */
/* use system(const char *string) implementation in the msh */
#else
int system(const char *string)
{