/* * include files for C library of the host. Currently only tested * with glibc 2.31. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include int putstring( char *s ) { printf( "%s", s ); return 0; } int putint( int i ) { printf( "%d", i ); return i; } int putnl( void ) { return puts( "" ); } /* TODO: duplicate of functions in libc-freestanding.c */ static void strreverse( char *s ) { char *end = s + strlen( s ) - 1; while( s < end ) { *s ^= *end; *end ^= *s; *s ^= *end; s++; end--; } } char *itoa( int v, char *s, int base ) { static char digit[] = "0123456789ABCDEF"; int sign = 0; char *p = s; if( base < 2 || base > 16 ) { return NULL; } if( v < 0 ) { v = -v; sign = 1; } do { *p++ = digit[v % base]; } while( ( v /= base ) > 0 ); if( sign ) { *p++ = '-'; } *p = '\0'; strreverse( s ); return s; }