int ALT_WRITE (int file, const void *ptr, size_t len) { #ifdef ALT_STDOUT_PRESENT ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); #endif #ifdef ALT_STDERR_PRESENT ALT_DRIVER_WRITE_EXTERNS(ALT_STDERR_DEV); #endif #if !defined(ALT_STDOUT_PRESENT) && !defined(ALT_STDERR_PRESENT) /* Generate a link time warning, should this function ever be called. */ ALT_STUB_WARNING(write); #endif switch (file) { #ifdef ALT_STDOUT_PRESENT case 1: /* stdout file descriptor */ return ALT_DRIVER_WRITE(ALT_STDOUT_DEV, ptr, len, 0); #endif /* ALT_STDOUT_PRESENT */ #ifdef ALT_STDERR_PRESENT case 2: /* stderr file descriptor */ return ALT_DRIVER_WRITE(ALT_STDERR_DEV, ptr, len, 0); #endif /* ALT_STDERR_PRESENT */ default: ALT_ERRNO = EBADFD; return -1; } }
/* * Uses the ALT_DRIVER_WRITE() macro to call directly to driver if available. * Otherwise, uses newlib provided fputs() routine. */ int alt_putstr(const char* str) { #ifdef ALT_USE_DIRECT_DRIVERS ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); return ALT_DRIVER_WRITE(ALT_STDOUT_DEV, str, strlen(str), 0); #else return fputs(str, stdout); #endif }
/* * Uses the ALT_DRIVER_WRITE() macro to call directly to driver if available. * Otherwise, uses newlib provided fputs() routine. */ int alt_putstr(const char* str) { #ifdef ALT_SEMIHOSTING return write(STDOUT_FILENO,str,strlen(str)); #else #ifdef ALT_USE_DIRECT_DRIVERS ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); return ALT_DRIVER_WRITE(ALT_STDOUT_DEV, str, strlen(str), 0); #else return fputs(str, stdout); #endif #endif }
/* * Uses the ALT_DRIVER_WRITE() macro to call directly to driver if available. * Otherwise, uses newlib provided putchar() routine. */ int alt_putchar(int c) { #ifdef ALT_USE_DIRECT_DRIVERS ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); char c1 = (char)(c & 0xff); if (ALT_DRIVER_WRITE(ALT_STDOUT_DEV, &c1, 1, 0) == -1) { return -1; } return c; #else return putchar(c); #endif }