Apologies I am using openwrt therefore post question here for your attention ![]()
Program:
char asd[] = "02";
char asdf[] = "DEADBEEFABCDEFDDDAAACCC995283264";
char asdf1[] = "DEA";
fdo = open("/dev/kmsg", O_WRONLY);
dprintf(fdo, "*AAAAAAAAA AAA written data '%s' at buffer position %s\n", asdf, asd);
dprintf(fdo, "*AAAAAAAAA AAA written data '%s' at buffer position %s\n", asdf1, asd);
FILE* fi = fopen(/dev/kmsg, "w");
if(fi != NULL)
{
fprintf(fi, "*AAAAAAAAA AAA written data '%s' at buffer position %s\n", asdf, asd);
fclose(fi);
}
Causes the following outputs into the log:
[14419.719344] *AAAAAAAAA AAA written data 'DEADBEEFABCDEFDDDAAACCC995283264' at buffer position
[14419.719372] 02
[14419.729843] *AAAAAAAAA AAA written data 'DEA' at buffer position 02
[14419.736378] *AAAAAAAAA AAA written data 'DEADBEEFABCDEFDDDAAACCC995283264' at buffer position 02
See something strange? First dprintf command puts last %s onto the new log line. If I put just "02" instead of "%s", then it is logged as whole single line. Second line shows 02 to be on the same log line, but line is shorter. Third line - fprintf - correct otuput.
Seems like dprintf has mechanism to split lines, while documentation says it is exact behavior as printf?
Update: the workaround is to make whole string using snprintf first and then perform dprintf as only "%s".