Uses indices instead of pointers

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6517 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2005-05-24 14:01:16 +00:00
parent 4135046303
commit 056effc945
1 changed files with 9 additions and 8 deletions

View File

@ -34,27 +34,28 @@
#define MAX_LOGF_LINES 1000
#define MAX_LOGF_DATASIZE (16*MAX_LOGF_LINES)
unsigned char logfbuffer[MAX_LOGF_DATASIZE];
unsigned char *logfend=&logfbuffer[MAX_LOGF_DATASIZE];
unsigned char *logfptr=&logfbuffer[0];
unsigned char logfbuffer[MAX_LOGF_LINES][16];
int logfindex;
bool logfwrap;
void logf(const char *format, ...)
{
int len;
unsigned char *ptr;
va_list ap;
va_start(ap, format);
if(logfptr >= logfend) {
if(logfindex >= MAX_LOGF_LINES) {
/* wrap */
logfwrap = true;
logfptr = &logfbuffer[0];
logfindex = 0;
}
len = vsnprintf(logfptr, 16, format, ap);
ptr = logfbuffer[logfindex];
len = vsnprintf(ptr, 16, format, ap);
va_end(ap);
if(len < 16)
/* pad with spaces up to the 16 byte border */
memset(logfptr+len, ' ', 16-len);
memset(ptr+len, ' ', 16-len);
logfptr += 16; /* leave it where we write the next time */
logfindex++; /* leave it where we write the next time */
}