Re: support for POSIX 1003.1-2001 hosts - Mailing list pgsql-patches

From Paul Eggert
Subject Re: support for POSIX 1003.1-2001 hosts
Date
Msg-id 200203120022.g2C0Mdb08837@shade.twinsun.com
Whole thread Raw
In response to Re: support for POSIX 1003.1-2001 hosts  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-patches
> From: Bruce Momjian <pgman@candle.pha.pa.us>
> Date: Mon, 11 Mar 2002 19:04:24 -0500 (EST)
>
> The patch basically takes:
>
>     sort +1 -0 and changes it to
>
> and makes it:
>
>     sort +1 -0 || sort -k 1,0
>
> or something like that.

Here is a bit more detail about what the patch does.

* It transforms `head -1 FOO' to `sed q FOO'.
  This is portable to all hosts that I know of.
  As it happens, `head -1' didn't work in Unix Version 7, but `sed q' did,
  so this transformation improves portability to some ancient hosts too.

* It transforms `sort +0n -1' to `(sort -k 1,1n 2>/dev/null || sort +0n -1)',
  and similarly for all other uses of `sort +FOO'.  The basic idea is
  to try POSIX standard syntax (standard since the first version of POSIX,
  anyway, more than a dozen years ago), and to fall back on the traditional
  Unix Version 7 syntax if the POSIX standard syntax is not supported.

The former transformation is perfectly safe.  The latter
transformation is a bit tricky, since the first `sort' can fail for
reasons other than "I don't know what -k is", and in that case the
second `sort' will be invoked even though it should not be.  I don't
think this will be a real problem in practice, but if you're worried
about it I could change the second transform to look like this:

  if sort -k 1,1n /dev/null >/dev/null 2>&1
  then sort -k 1,1n
  else sort +0n -1
  fi

I can submit a revised patch along those lines if you like.

pgsql-patches by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: support for POSIX 1003.1-2001 hosts
Next
From: Tom Lane
Date:
Subject: Re: Adds the parsing of a CREATE SCHEMA statement