A number of improvements to CAPI compatibility

Separated out from some more involved changes that are
required to get the 'pwd' module working.