7 /* This output manipulator gives the option to use Old style format
8 specifications in ostreams. Note that this is done at the expense
9 of typesafety, so if possible this manipulator should be avoided.
10 When is it allowed to use this manipulator? I wrote it to be used
11 i18n strings and gettext, and it should only(?) be used in that
14 Ad. the implementation. I have only tested this on egcs-2.91.66 with
15 glibc 2.1.2. So further testing is needed. The loop in fmt(...) will
16 usually spin one or two times, but might spin more times with older
17 glibc libraries, since the returned -1 when size is too small. Newer
18 glibc returns the needed size.
19 One problem can be that vsnprintf is not implemented on all archs,
20 but AFAIK it is part of the new ANSI C standard.
25 string fmt(char const * fmtstr ...)
28 char * str = new char[size];
32 int const r = ::vsnprintf(str, size, fmtstr, ap);
34 if (r == -1) { // size is too small
36 size *= 2; // seems quite safe to double.
38 } else if (r >= size) { // r gives the needed size