printf again
Hi I nearly succeeded in getting printf to work. I supplied the missing routines. Here I just simply write to a string. BUT: printf gets called every loop , but only calls write when it has produced 1024 chars! grrr , where do I change that?
I am working with code red and use the newlib
by the way 1 : I get the errorcode BFD: printf.axf: warning: sh_link not set for section `.ARM.exidx' but this seems to be a bug in GCC
by the way 2: sprintf works OK!
| Code: |
#include <stdio.h>
#include <sys/stat.h>
char str[100];
char *cp = str;
void writechar(char ch);
int main(void) {
int x = 1;
while (1) {
cp = str;
printf(" abc %d ", x);
writechar(0);
x+= 1;
}
}
int _close(int file) {
return -1;
}
int _exit(int x) {
while (1)
;
}
int _fstat(int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
//lseek
// Set position in a file. Minimal implementation:
int _lseek(int file, int ptr, int dir) {
return 0;
}
int isatty(int file) {
return 1;
}
//read
// Read from a file. Minimal implementation:
int _read(int file, char *ptr, int len) {
return 0;
}
//sbrk
// Increase program data space. As malloc and related functions depend on this, it is useful to
have a working implementation. The following suffices for a standalone system; it exploits the
symbol end automatically defined by the GNU linker.
caddr_t _sbrk(int incr) {
extern char end; /* Defined by the linker */
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0) {
heap_end = &end;
}
prev_heap_end = heap_end;
heap_end += incr;
return (caddr_t) prev_heap_end;
}
//getpid
// Process-ID; this is sometimes used to generate strings unlikely to conflict with other
processes. Minimal implementation, for a system without processes:
int _getpid() {
return 1;
}
//kill
// Send a signal. Minimal implementation:
#include <errno.h>
#undef errno
extern int errno;
int _kill(int pid, int sig) {
errno=EINVAL;
return (-1);
}
// write
// Write a character to a file.
void writechar(char ch) {
*cp++ = ch;
if (cp == (str + 100))
cp = str;
}
int _write(int file, char *ptr, int len) {
int todo;
for (todo = 0; todo < len; todo++) {
writechar(*ptr++);
}
return len;
}
|
Post edited by: digkleppe, at: 2008/06/28 12:33
Post edited by: digkleppe, at: 2008/06/28 12:37
login or register to reply
|