Skip to content

Instantly share code, notes, and snippets.

@erincandescent
Created August 11, 2014 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erincandescent/bed98cbdd3fc39ed0d53 to your computer and use it in GitHub Desktop.
Save erincandescent/bed98cbdd3fc39ed0d53 to your computer and use it in GitHub Desktop.
OK mandoc, how'd that happen?
_cbprintf(3) Library Functions Manual _cbprintf(3)
NNAAMMEE
__ccbbpprriinnttff, __vvccbbpprriinnttff, __ccbbwwpprriinnttff, __vvccbbwwpprriinnttff -- formatted output
conversion by callback
SSYYNNOOPPSSIISS
##iinncclluuddee <<ssttddiioo..hh>>
iinntt __ccbbpprriinnttff(_v_o_i_d _*_p, _i_n_t _(_*_c_b_)_(_v_o_i_d _*_p_, _c_o_n_s_t _c_h_a_r _*_b_u_f_, _i_n_t _s_i_z_e_),
_c_o_n_s_t _c_h_a_r _*_f_m_t, _._._.);
iinntt __vvccbbpprriinnttff(_v_o_i_d _*_p, _i_n_t _(_*_c_b_)_(_v_o_i_d _*_p_, _c_o_n_s_t _c_h_a_r _*_b_u_f_, _i_n_t _s_i_z_e_),
_c_o_n_s_t _c_h_a_r _*_f_m_t, _v_a___l_i_s_t _a_p);
##iinncclluuddee <<wwcchhaarr..hh>>
iinntt __ccbbwwpprriinnttff(_v_o_i_d _*_p, _i_n_t _(_*_c_b_)_(_v_o_i_d _*_p_, _c_o_n_s_t _w_c_h_a_r___t _*_b_u_f_, _i_n_t _s_i_z_e_),
_c_o_n_s_t _w_c_h_a_r___t _*_f_m_t, _._._.);
iinntt __vvccbbwwpprriinnttff(_v_o_i_d _*_p,
_i_n_t _(_*_c_b_)_(_v_o_i_d _*_p_, _c_o_n_s_t _w_c_h_a_r___t _*_b_u_f_, _i_n_t _s_i_z_e_), _c_o_n_s_t _w_c_h_a_r___t _*_f_m_t,
_v_a___l_i_s_t _a_p);
DDEESSCCRRIIPPTTIIOONN
These functions permit the pprriinnttff() string formatting functionality to be
reused outside the C standard library, without the limitations of using
the sspprriinnttff() function for this process; for example, the requirement to
allocate large quantities of RAM or truncate when formatting produces a
large string.
These functions shall exhibit the same behaviour and conversion
specifiers as the printf(3) function, except they shall perform their
output by calling the _c_b callback, passing the characters to be output as
the _b_u_f parameter, and the count of such characters as _s_i_z_e. The
implementation is permitted to invoke _c_b as many or as few times as it
desires (i.e. it may perform as much or as little buffering internally as
it desires), except that, excluding the case in which formatting has
produced a zero length string. During all invocations, the callback will
be passed as _p the same value as was passed to the function.
The callback may return a negative value in order to terminate processing
(in which case the function will also return a negative value).
RREETTUURRNN VVAALLUUEESS
The functions will return the sum of the return values of the callback on
success, a negative value otherwise.
EERRRROORRSS
No errors are defined
SSEEEE AALLSSOO
printf(3)
RRAATTIIOONNAALLEE
Sensible implementations of the ISO C standard library implement an
analogous system internally, permitting them to share their
implementation of formatting between printf(3) and sprintf(3).
Therefore, implementing a callback based variant is not of substantial
complexity.
These functions permit the reuse of this functionality by applications
and libraries (for example, a logging library) without the need to
reimplement it, and without the limitations imposed by snprintf(3).
HHIISSTTOORRYY
This nonstandard extension was first defined by PDCLib.
Darwin 14.0.0 August 11, 2014 Darwin 14.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment