13
13
* Date Author Notes
14
14
* 2012-11-23 Yihui The first version
15
15
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
16
- * 2014-08-03 bernard If using msh, use system() implementation
16
+ * 2014-08-03 bernard If using msh, use system() implementation
17
17
* in msh.
18
18
*/
19
19
@@ -48,11 +48,11 @@ const char __stderr_name[] = "STDERR";
48
48
*/
49
49
FILEHANDLE _sys_open (const char * name , int openmode )
50
50
{
51
- #ifdef RT_USING_DFS
51
+ #ifdef RT_USING_DFS
52
52
int fd ;
53
53
int mode = O_RDONLY ;
54
54
#endif
55
-
55
+
56
56
/* Register standard Input Output devices. */
57
57
if (strcmp (name , __stdin_name ) == 0 )
58
58
return (STDIN );
@@ -64,34 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode)
64
64
#ifndef RT_USING_DFS
65
65
return -1 ;
66
66
#else
67
- /* Correct openmode from fopen to open */
68
- if (openmode & OPEN_PLUS )
69
- {
70
- if (openmode & OPEN_W )
71
- {
72
- mode |= (O_RDWR | O_TRUNC | O_CREAT );
73
- }
74
- else if (openmode & OPEN_A )
75
- {
76
- mode |= (O_RDWR | O_APPEND | O_CREAT );
77
- }
78
- else
79
- mode |= O_RDWR ;
80
- }
81
- else
82
- {
83
- if (openmode & OPEN_W )
84
- {
85
- mode |= (O_WRONLY | O_TRUNC | O_CREAT );
86
- }
87
- else if (openmode & OPEN_A )
88
- {
67
+ /* Correct openmode from fopen to open */
68
+ if (openmode & OPEN_PLUS )
69
+ {
70
+ if (openmode & OPEN_W )
71
+ {
72
+ mode |= (O_RDWR | O_TRUNC | O_CREAT );
73
+ }
74
+ else if (openmode & OPEN_A )
75
+ {
76
+ mode |= (O_RDWR | O_APPEND | O_CREAT );
77
+ }
78
+ else
79
+ mode |= O_RDWR ;
80
+ }
81
+ else
82
+ {
83
+ if (openmode & OPEN_W )
84
+ {
85
+ mode |= (O_WRONLY | O_TRUNC | O_CREAT );
86
+ }
87
+ else if (openmode & OPEN_A )
88
+ {
89
89
mode |= (O_WRONLY | O_APPEND | O_CREAT );
90
- }
91
- }
90
+ }
91
+ }
92
92
93
93
fd = open (name , mode , 0 );
94
- if (fd < 0 )
94
+ if (fd < 0 )
95
95
return -1 ;
96
96
else
97
97
return fd + STDERR + 1 ;
@@ -121,10 +121,10 @@ int _sys_close(FILEHANDLE fh)
121
121
*/
122
122
int _sys_read (FILEHANDLE fh , unsigned char * buf , unsigned len , int mode )
123
123
{
124
- #ifdef RT_USING_DFS
124
+ #ifdef RT_USING_DFS
125
125
int size ;
126
126
#endif
127
-
127
+
128
128
if (fh == STDIN )
129
129
{
130
130
/* TODO */
@@ -138,7 +138,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
138
138
return 0 ;
139
139
#else
140
140
size = read (fh - STDERR - 1 , buf , len );
141
- if (size >= 0 )
141
+ if (size >= 0 )
142
142
return len - size ;
143
143
else
144
144
return -1 ;
@@ -159,7 +159,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
159
159
#ifdef RT_USING_DFS
160
160
int size ;
161
161
#endif
162
-
162
+
163
163
if ((fh == STDOUT ) || (fh == STDERR ))
164
164
{
165
165
#ifndef RT_USING_CONSOLE
@@ -170,18 +170,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
170
170
console_device = rt_console_get_device ();
171
171
if (console_device != 0 ) rt_device_write (console_device , 0 , buf , len );
172
172
173
- return 0 ;
173
+ return 0 ;
174
174
#endif
175
175
}
176
176
177
- if (fh == STDIN )
177
+ if (fh == STDIN )
178
178
return -1 ;
179
179
180
180
#ifndef RT_USING_DFS
181
181
return 0 ;
182
182
#else
183
183
size = write (fh - STDERR - 1 , buf , len );
184
- if (size >= 0 )
184
+ if (size >= 0 )
185
185
return len - size ;
186
186
else
187
187
return -1 ;
@@ -270,6 +270,6 @@ int remove(const char *filename)
270
270
int system (const char * string )
271
271
{
272
272
RT_ASSERT (0 );
273
- for (;;);
273
+ for (;;);
274
274
}
275
275
#endif
0 commit comments