20
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
* SOFTWARE.
22
22
*/
23
+ #include " Arduino.h"
23
24
#include < rt_sys.h>
24
25
#include < stdint.h>
25
26
#include < stdlib.h>
26
27
#include < time.h>
27
- #include " Arduino.h"
28
28
29
- #pragma import(__use_no_semihosting)
29
+ #ifdef __MICROLIB
30
+ #pragma import(__use_no_semihosting_swi)
31
+ #include < stdio.h>
30
32
31
- enum
33
+ extern " C " int fputc ( int ch, FILE* stream)
32
34
{
35
+ (void )stream;
36
+ Serial.write (ch);
37
+ return ch;
38
+ }
39
+ #else
40
+ #pragma import(__use_no_semihosting)
41
+ #endif
42
+
43
+ enum {
33
44
STDIN,
34
45
STDOUT,
35
46
STDERR,
43
54
* As we define _sys_open() to always return the same file handle,
44
55
* these can be left as their default values.
45
56
*/
46
- const char __stdin_name[] = " __stdin" ;
47
- const char __stdout_name[] = " __stdout" ;
48
- const char __stderr_name[] = " __stderr" ;
57
+ const char __stdin_name[] = " __stdin" ;
58
+ const char __stdout_name[] = " __stdout" ;
59
+ const char __stderr_name[] = " __stderr" ;
60
+
49
61
/*
50
62
* Open a file. May return -1 if the file failed to open.
51
63
*/
52
- FILEHANDLE _sys_open (const char * name, int openmode)
64
+ FILEHANDLE _sys_open (const char * name, int openmode)
53
65
{
54
- if (name == __stdin_name)
55
- {
66
+ if (name == __stdin_name) {
56
67
return STDIN;
57
68
}
58
- else if (name == __stdout_name)
59
- {
69
+
70
+ if (name == __stdout_name) {
60
71
return STDOUT;
61
72
}
62
- else if (name == __stderr_name)
63
- {
73
+
74
+ if (name == __stderr_name) {
64
75
return STDERR;
65
76
}
66
77
67
- return (FILEHANDLE) - 1 ;
78
+ return (FILEHANDLE)- 1 ;
68
79
}
69
80
70
81
/*
71
82
* Close a file. Should return 0 on success or a negative value on error.
72
83
*/
73
84
int _sys_close (FILEHANDLE fh)
74
85
{
75
- if (IS_STD_FILEHANDLE (fh))
76
- {
86
+ if (IS_STD_FILEHANDLE (fh)) {
77
87
return 0 ;
78
88
}
79
89
80
- return -1 ;
90
+ return -1 ;
81
91
}
82
92
83
93
/*
84
94
* Write to a file. Returns 0 on success, negative on error, and
85
95
* the number of characters _not_ written on partial success.
86
96
* `mode' exists for historical reasons and must be ignored.
87
97
*/
88
- int _sys_write (FILEHANDLE fh, const unsigned char *buf,
89
- unsigned len, int mode)
98
+ int _sys_write (
99
+ FILEHANDLE fh,
100
+ const unsigned char * buf,
101
+ unsigned len,
102
+ int mode)
90
103
{
91
- if (IS_STD_FILEHANDLE (fh))
92
- {
93
- if (fh == STDOUT || fh == STDERR)
94
- {
104
+ if (IS_STD_FILEHANDLE (fh)) {
105
+ if (fh == STDOUT || fh == STDERR) {
95
106
Serial.write (buf, len);
96
107
}
97
108
return len;
@@ -125,11 +136,13 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf,
125
136
*
126
137
* `mode' exists for historical reasons and must be ignored.
127
138
*/
128
- int _sys_read (FILEHANDLE fh, unsigned char *buf,
129
- unsigned len, int mode)
139
+ int _sys_read (
140
+ FILEHANDLE fh,
141
+ unsigned char * buf,
142
+ unsigned len,
143
+ int mode)
130
144
{
131
- if (IS_STD_FILEHANDLE (fh))
132
- {
145
+ if (IS_STD_FILEHANDLE (fh)) {
133
146
return 0 ;
134
147
}
135
148
@@ -188,7 +201,7 @@ long _sys_flen(FILEHANDLE fh)
188
201
* name. Returns 0 on failure. maxlen is the maximum name length
189
202
* allowed.
190
203
*/
191
- int _sys_tmpnam (char * name, int sig, unsigned maxlen)
204
+ int _sys_tmpnam (char * name, int sig, unsigned maxlen)
192
205
{
193
206
return 0 ;
194
207
}
@@ -200,42 +213,44 @@ int _sys_tmpnam(char *name, int sig, unsigned maxlen)
200
213
void _sys_exit (int status)
201
214
{
202
215
/* main return*/
203
- while (1 );
216
+ while (1 )
217
+ ;
204
218
}
205
219
206
220
/*
207
221
* Return a pointer to the command line used to invoke the program.
208
222
* The supplied buffer may be used to store the string, but need
209
223
* not be.
210
224
*/
211
- char * _sys_command_string (char * cmd, int len)
225
+ char * _sys_command_string (char * cmd, int len)
212
226
{
213
227
return cmd;
214
228
}
215
229
216
230
extern " C" {
217
- time_t time (time_t * time)
218
- {
219
- return millis ();
220
- }
231
+ time_t time (time_t * time)
232
+ {
233
+ return ( time_t ) millis ();
234
+ }
221
235
222
- void exit (int status)
223
- {
224
- while (1 );
225
- }
236
+ void exit (int status)
237
+ {
238
+ while (1 )
239
+ ;
240
+ }
226
241
227
- int system (const char * string)
228
- {
229
- return 0 ;
230
- }
242
+ int system (const char * string)
243
+ {
244
+ return 0 ;
245
+ }
231
246
232
- int remove (const char * filename)
233
- {
234
- return 0 ;
235
- }
247
+ int remove (const char * filename)
248
+ {
249
+ return 0 ;
250
+ }
236
251
237
- clock_t clock ()
238
- {
239
- return millis ();
240
- }
252
+ clock_t clock ()
253
+ {
254
+ return ( clock_t ) millis ();
255
+ }
241
256
}
0 commit comments