Skip site navigation (1) Skip section navigation (2)

Re: [pgsql-hackers-win32] Repleacement for src/port/snprintf.c

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Nicolai Tufar <ntufar(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>,Magnus Hagander <mha(at)sollentuna(dot)net>, pgsql-hackers(at)postgresql(dot)org,pgsql-hackers-win32(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org,devrim(at)gunduz(dot)org
Subject: Re: [pgsql-hackers-win32] Repleacement for src/port/snprintf.c
Date: 2005-02-14 00:06:34
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-hackers-win32pgsql-patches
Nicolai Tufar wrote:
> Hello all,
> I would like to submit my changes to src/port/snprintf.c to
> enable %n$ format placeholder replacement in snprintf() and
> vsnprintf(). Additionally I implemented a trivial printf().
> I also attach a diff for to include snprintf.o
> in pgport but I am sure it is not the right thing to do.
> Could someone give a hint on where I need to place such a
> definition.
> Please review my patch. as Tom Lane pointed out there
> are 150 messages in the following files that do not print
> properly:

It took me a while to understand this but I get it now.  This is the
best explanation I have seen, from Linux 2.6:

	One can also specify explicitly which argument is taken, at each place
	where an argument is required, by writing '%m$' instead of '%' and '*m$'
	instead of '*', where the decimal integer m denotes the position in the
	argument list of the desired argument, indexed starting from 1. Thus,
		printf("%*d", width, num);
		printf("%2$*1$d", width, num);
	are  equivalent.  The  second style allows repeated references to the
	same argument. The C99 standard does not include the style using '$',
	which comes from the Single Unix Specification.  If the style using '$'
	is used, it must be  used throughout for all conversions taking an
	argument and all width and precision arguments, but it may be mixed with
	'%%' formats which do not consume an argument.  There may be no gaps in
	the numbers of arguments specified using  '$';  for example, if
	arguments 1 and 3 are specified, argument 2 must also be specified
	somewhere in the format string.

I can see why this would be useful for translations because it uncouples
the order of the printf arguments from the printf string.  However, I
have learned that Win32, HP-UX, NetBSD 2.0, and BSD/OS do not support
this.  This is probably because it is not in C99 but in SUS (see above).

Anyway, this is too large to put into 8.0, but I am attaching a patch
for 8.1 that has the proper configure tests to check if the C library
supports this behavior.  If it does not, the build will use our

One problem with that is that our snprintf.c is not thread-safe.  Seems
the increases use of it will require us to fix this soon.  I have added
to TODO:

	* Make src/port/snprintf.c thread-safe

One change to the original port is that there was a define of a union
with no name:

+               union{
+                       void*   value;
+                       long_long       numvalue;
+                       double          fvalue;
+                       int             charvalue;
+               };

As far as I know a union with no name is illegal.  I just removed the
"union {" and the closing brace.

  Bruce Momjian                        |
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to


pgsql-hackers by date

Next:From: Bruce MomjianDate: 2005-02-14 01:07:58
Subject: Re: Design notes for BufMgrLock rewrite
Previous:From: Tom LaneDate: 2005-02-13 23:56:47
Subject: Re: Design notes for BufMgrLock rewrite

pgsql-patches by date

Next:From: Bruce MomjianDate: 2005-02-14 23:04:02
Subject: Cleanup for gettext() calls
Previous:From: Tom LaneDate: 2005-02-13 19:00:06
Subject: Re: [BUGS] BUG #1466: #maintenace_work_mem = 16384

pgsql-hackers-win32 by date

Next:From: Nicolai TufarDate: 2005-02-15 14:29:27
Subject: Re: [pgsql-hackers-win32] Repleacement for src/port/snprintf.c
Previous:From: Nicolai TufarDate: 2005-02-09 07:59:28
Subject: Repleacement for src/port/snprintf.c

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group