Quellcode durchsuchen

[LIBC] fix the fopen/open issue in armlibc

Bernard Xiong vor 10 Jahren
Ursprung
Commit
0797e54f3f
1 geänderte Dateien mit 29 neuen und 5 gelöschten Zeilen
  1. 29 5
      components/libc/armlibc/stubs.c

+ 29 - 5
components/libc/armlibc/stubs.c

@@ -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)
 {