Greetings, for a couple of days I have been hacking on src/port/snprintf.c. With Magnus' help I have managed to implement argument replacement in snprintf(). The code is very crude and not quite optimised, any suggestions will be more than welcome.
Here is what I did: 1. I renamed snprintf() to pg_snprintf(), vsnprintf() to pg_vsnprintf() and introduced pg_printf() that calls pg_vsnprintf(). 2. After running configure I manually added snprintf.o to src/Makefile.global's LIBOBJ declaration and -lpgport to Makefile.shlib's DLLWRAP declaration 3. To make sure these functions are used everywhere I introduced the following lines at the end of src/include/c.h: #define snprintf pg_snprintf #define vsnprintf pg_vsnprintf #define printf pg_printf 4. I introduced a volatile static char[] variable in snprintf.c code so I can grep executables for this string and be sure that it is included. 5. Before running regression test I always ran make install, apparently because libpq is read from /usr/local/. During compilation the following warnings were reported: ../../../src/include/utils/elog.h:121: warning: `pg_printf' is an unrecognized format function type which is perfectly fine because we replace printf with pg_printf and gcc's format() does know anything about it. On Linux, PostgreSQL passed regression tests with flying colours and prints messages with %n$ just fine. On win32: int8, timestamp, timestamptz, abstime, horology, constraints, vacuum, and many others failed. To check my code, I reverted snprintf.c to the original one from CVS and forced win32 port to use these functions and it fails in same places. After examining regression tests diff I came to conclusion that problem is in fmtnum() function when it operates with particularly long integers. In snprintf() file I changed only and only dopr() function, neve touching fmtnum(), fmtstr() or fmtfolat(). I would like to kindly ask these questions: 1. Am I on the right to implement %n$ ? Can it be accepted? 2. Why would we not just take FreeBSD's vfprintf() and use it instead? 3. What is wrong with fmtnum() on Win32? 4. What %m format string is used for? And where is it handled. Do I need to implement it? I am attaching my version if snprintf.c (because it is too different from the original to make a patch) and regression.diff of a failed Win32 regression test produced wither with my or with original snprintf.c. Best regards, Nicolai Tufar ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster