Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_vscprintf equivalent on Android?

_vscprintf is not available on Android. Also vsprintf(NULL, fmt, ap) does not work (produces seg fault), so there seems to be no way of calculating size of buffer required for vsnprintf to succeed?

Android sources indicate that __android_log_print function just truncates strings to 1024 using vsnprintf...

How do you handle this scenario?

like image 487
miha Avatar asked Dec 12 '22 08:12

miha


1 Answers

Section [7.19.6.13]—The vsprintf function—of the C99 Standard does not state that the output buffer may be NULL.

You probably want to use vsnprintf:

int len = vsnprintf(NULL, 0, fmt, ap)

If the call is successful, the return value is the number of characters that would have been written if the buffer were large enough, excluding the NUL terminator. This is like _vscprintf, which also does not include the NUL terminator in its count.

like image 171
Daniel Trebbien Avatar answered Dec 27 '22 09:12

Daniel Trebbien