From: Tom Lane on
The recently added contrib/pg_upgrade code contains this bit:

/*
* scandir() is originally from BSD 4.3, which had the third argument as
* non-const. Linux and other C libraries have updated it to use a const.
* http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg00214.html
*
* Here we try to guess which libc's need const, and which don't. The net
* goal here is to try to suppress a compiler warning due to a prototype
* mismatch of const usage. Ideally we would do this via autoconf, but
* autoconf doesn't have a suitable builtin test and it seems overkill
* to add one just to avoid a warning.
*/
#elif defined(freebsd) || defined(bsdi) || defined(__darwin__) || defined(openbsd)
/* no const */
return scandir(dirname, namelist, (int (*) (struct dirent *)) selector, NULL);
#else
/* use const */
return scandir(dirname, namelist, selector, NULL);

This drew my attention a couple days ago because it was picking the
wrong alternative on OS X, which was because the as-committed coding
was "defined(darwin)", which is not how that symbol is spelled. I fixed
that, but I am now thinking that the other three checks are equally
tin-eared. In particular, I see that buildfarm members ermine (FreeBSD)
and spoonbill (OpenBSD) are reporting warnings here, which proves that
those two platforms don't predefine "freebsd" or "openbsd" respectively.
Does anyone know if they define "__freebsd__" or "__freebsd" etc?

I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
too. A search of our code finds

contrib/pg_upgrade/file.c: 248: #elif defined(freebsd) || defined(bsdi) || defined(__darwin__) || defined(openbsd)
src/backend/utils/misc/ps_status.c: 67: #elif (defined(BSD) || defined(__bsdi__) || defined(__hurd__)) && !defined(__darwin__)
src/include/port.h: 355: #if defined(bsdi) || defined(netbsd)
src/port/fseeko.c: 20: #if defined(__bsdi__) || defined(__NetBSD__)
src/port/fseeko.c: 24: #ifdef bsdi
src/port/fseeko.c: 47: #ifdef bsdi
src/port/fseeko.c: 55: #ifdef bsdi
src/port/fseeko.c: 66: #ifdef bsdi
src/port/fseeko.c: 76: #ifdef bsdi
src/port/fseeko.c: 87: #ifdef bsdi

which leaves one with not a lot of warm fuzzies that we know how to
spell the symbol for either bsdi or netbsd. (Oh, and shouldn't
this pg_upgrade check be looking for netbsd too?)

In the "darwin" case we aren't really making any assumptions,
because we actually define __darwin__ in port/darwin.h.

I suppose that at least some of the *BSD herd really do predefine some
of the symbols being attributed to them here, but I would like to see
something authoritative about which and what.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers(a)postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers