refactor: factor out doselection-like functionality.

* lib/posix/compat.lua (doselection): Given a table of field
names, and a mapping table return a tuple of remapped names, or
the whole table when no fields are passed.
(getpasswd, getpid, stat): Simplify accordingly.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>