Hi Silvio, I understand what you are asking for, but I'm not terribly inclined to do so. For starters, this would break ABI compatibility, which is not a nice thing. Also, allocating the string buffer (like you do) on the stack may not be OK for some applications -- stacks on some OSes can be very tiny, and 1k may be too much. OTOH, truncating log messages is also bad. So the current solution offers the most flexibility.
Furthermore, I don't quite see what's so weird about your solution. The code is pretty straightforward to read, and "it works". Breaking our ABI so that Delphi can safe 4 lines of code because it's not C-compatible is not a good trade-off in my mind. Still, I think sharing this here is useful, as others may have the same question in the future, and I actually think your solution is great. Happy hacking! Christian On 02/27/2016 09:14 PM, silvioprog wrote: > Hello, > > I'm using MHD in a small application written in Delphi (Pascal), and it is > working like a charm. Today I needed to get all generated log from MHD, > however it seems that it depends on functions like *sprintf(), but the > Pascal Format() function is a little bit different from C, because the > Pascal ones use other format style. And the other problem is that Delphi > and Free Pascal don't have this function on their RTL, so I did something > like: > > function vsnprintf_s(buffer: Pcchar; sizeOfBuffer: size_t; count: size_t; > format: Pcchar; argptr: va_list): cint; cdecl; > external LIB_NAME name {$IFDEF > MSWINDOWS}'_vsnprintf_s'{$ELSE}'vsnprintf_s'{$ENDIF}; > > procedure ErrorLog(ACls: Pointer; AFmt: Pcchar; AArgs: va_list); cdecl; > var > S: RawByteString; > VBuffer: array[0..1024] of AnsiChar; > begin > SetString(S, VBuffer, vsnprintf_s(VBuffer, SizeOf(VBuffer), > Length(VBuffer), > AFmt, AArgs)); > SetCodePage(S, CP_UTF8, False); > MyLogger.Append(S); > end; > > It works, but it seems a very weird solution, so can I get the entire > generated MHD log in a *char? In pure C code, something like: > > void error_log(void *cls, char *log) { > printf("%s", log); > } > > Instead of: > > void error_log(void *cls, char *fmt, va_list args) { > vprintf(fmt, args); > } > > It would be very useful to the ones that need to get the entire log without > depends on C format functions. > > Thank you! >
signature.asc
Description: OpenPGP digital signature