C lib insanity
strfmon() is a function that formats "money" values according to local convention, or locale as we geeks like to call it. This accounts for such things as how you group your numbers (by thousands for most countries; Japan groups by ten thousands), whether the currency symbol goes before or after the amount, where you put spacing, what your group separator is, etc.
strfmon() belongs to the insane class of C library functions that refuse to allocate memory for something they should allocate memory for. Specifically, to get a result from strfmon() you have to give it a buffer to write the result into. It will tell you how much of that buffer it used. But, er, you don't know how much of a buffer to give it until you've already called the function. This leaves you in the situation of either (a) calling the damned thing repeatedly until it's happy or (b) making a rough guess, and crossing your fingers. Since I'm in a fairly restricted environment, I've currently opted for the latter in the interests of not adding needless cycles to an already overcycled system. But seriously folks. DON'T FRICKIN' DESIGN YOUR INTERFACES LIKE THIS.
(oh yeah. for added pain, I'm actually calling this via a C extension to Perl, which I've mostly hand-built due to the fact that I guess everyone else who looked at the task ran screaming from the strfmon() interface.)
strfmon() belongs to the insane class of C library functions that refuse to allocate memory for something they should allocate memory for. Specifically, to get a result from strfmon() you have to give it a buffer to write the result into. It will tell you how much of that buffer it used. But, er, you don't know how much of a buffer to give it until you've already called the function. This leaves you in the situation of either (a) calling the damned thing repeatedly until it's happy or (b) making a rough guess, and crossing your fingers. Since I'm in a fairly restricted environment, I've currently opted for the latter in the interests of not adding needless cycles to an already overcycled system. But seriously folks. DON'T FRICKIN' DESIGN YOUR INTERFACES LIKE THIS.
(oh yeah. for added pain, I'm actually calling this via a C extension to Perl, which I've mostly hand-built due to the fact that I guess everyone else who looked at the task ran screaming from the strfmon() interface.)
Slogan
"New and improved with 7.2% more beer!"
Still, at least you can pass the size of the buffer to it.