2020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121 * SOFTWARE.
2222 */
23+ #include " Arduino.h"
2324#include < rt_sys.h>
2425#include < stdint.h>
2526#include < stdlib.h>
2627#include < time.h>
27- #include " Arduino.h"
2828
29- #pragma import(__use_no_semihosting)
29+ #ifdef __MICROLIB
30+ #pragma import(__use_no_semihosting_swi)
31+ #include < stdio.h>
3032
31- enum
33+ extern " C " int fputc ( int ch, FILE* stream)
3234{
35+ (void )stream;
36+ Serial.write (ch);
37+ return ch;
38+ }
39+ #else
40+ #pragma import(__use_no_semihosting)
41+ #endif
42+
43+ enum {
3344 STDIN,
3445 STDOUT,
3546 STDERR,
4354 * As we define _sys_open() to always return the same file handle,
4455 * these can be left as their default values.
4556 */
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+
4961/*
5062 * Open a file. May return -1 if the file failed to open.
5163 */
52- FILEHANDLE _sys_open (const char * name, int openmode)
64+ FILEHANDLE _sys_open (const char * name, int openmode)
5365{
54- if (name == __stdin_name)
55- {
66+ if (name == __stdin_name) {
5667 return STDIN;
5768 }
58- else if (name == __stdout_name)
59- {
69+
70+ if (name == __stdout_name) {
6071 return STDOUT;
6172 }
62- else if (name == __stderr_name)
63- {
73+
74+ if (name == __stderr_name) {
6475 return STDERR;
6576 }
6677
67- return (FILEHANDLE) - 1 ;
78+ return (FILEHANDLE)- 1 ;
6879}
6980
7081/*
7182 * Close a file. Should return 0 on success or a negative value on error.
7283 */
7384int _sys_close (FILEHANDLE fh)
7485{
75- if (IS_STD_FILEHANDLE (fh))
76- {
86+ if (IS_STD_FILEHANDLE (fh)) {
7787 return 0 ;
7888 }
7989
80- return -1 ;
90+ return -1 ;
8191}
8292
8393/*
8494 * Write to a file. Returns 0 on success, negative on error, and
8595 * the number of characters _not_ written on partial success.
8696 * `mode' exists for historical reasons and must be ignored.
8797 */
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)
90103{
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) {
95106 Serial.write (buf, len);
96107 }
97108 return len;
@@ -125,11 +136,13 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf,
125136 *
126137 * `mode' exists for historical reasons and must be ignored.
127138 */
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)
130144{
131- if (IS_STD_FILEHANDLE (fh))
132- {
145+ if (IS_STD_FILEHANDLE (fh)) {
133146 return 0 ;
134147 }
135148
@@ -188,7 +201,7 @@ long _sys_flen(FILEHANDLE fh)
188201 * name. Returns 0 on failure. maxlen is the maximum name length
189202 * allowed.
190203 */
191- int _sys_tmpnam (char * name, int sig, unsigned maxlen)
204+ int _sys_tmpnam (char * name, int sig, unsigned maxlen)
192205{
193206 return 0 ;
194207}
@@ -200,42 +213,44 @@ int _sys_tmpnam(char *name, int sig, unsigned maxlen)
200213void _sys_exit (int status)
201214{
202215 /* main return*/
203- while (1 );
216+ while (1 )
217+ ;
204218}
205219
206220/*
207221 * Return a pointer to the command line used to invoke the program.
208222 * The supplied buffer may be used to store the string, but need
209223 * not be.
210224 */
211- char * _sys_command_string (char * cmd, int len)
225+ char * _sys_command_string (char * cmd, int len)
212226{
213227 return cmd;
214228}
215229
216230extern " 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+ }
221235
222- void exit (int status)
223- {
224- while (1 );
225- }
236+ void exit (int status)
237+ {
238+ while (1 )
239+ ;
240+ }
226241
227- int system (const char * string)
228- {
229- return 0 ;
230- }
242+ int system (const char * string)
243+ {
244+ return 0 ;
245+ }
231246
232- int remove (const char * filename)
233- {
234- return 0 ;
235- }
247+ int remove (const char * filename)
248+ {
249+ return 0 ;
250+ }
236251
237- clock_t clock ()
238- {
239- return millis ();
240- }
252+ clock_t clock ()
253+ {
254+ return ( clock_t ) millis ();
255+ }
241256}
0 commit comments