From: John Hughes (John@Calva.COM)
Date: Mon Sep 23 2002 - 18:22:52 CEST
[ patch to add [facility.prio] &c to log messages ]
Nice idea, but I don't like some of the implementation,
you use the same method of converting from facility,priority
into text as "textpri" did, i.e. a loop, rather than a
just a table lookup, you memset the buffer to 0's, you
use strlen to find the output buffer length even though
you almost know it, in other words I think you're being
a little cruel to the poor old cpu.
+ if(LogPriority) {
+ memset(pribuf,'\0',sizeof(pribuf));
Why?
+ decodepri(f->f_prevpri,&fac,&sev);
+ strcpy(pribuf," [");
+ pb=pribuf+strlen(pribuf);
or:
pb = pribuf + 2;
+
+ if(LogPriority & 1) {
...
+ }
+ strcpy(pb,"] ");
pb += 2;
+
+ v->iov_base = pribuf;
+ v->iov_len = strlen(pribuf);
v->iov_len = pb - pribuf;
+ } else {
A little macro makes the "+2" stuff more appealing:
#define STRCAT(s1,s2) \
memcpy (s1, s2, sizeof s2 - 1); s1 += sizeof s2 - 1;
If we could assume a recent c library you could replace
sprintf (pb, ....); pb += strlen (pb);
with
pb += sprintf (pb, ....);
This archive was generated by hypermail 2.1.4 : Mon Sep 23 2002 - 18:23:01 CEST