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!

-- 
Silvio Clécio

Reply via email to