added some error codes, tried to eliminate unspecific return -1 where it made sense. This was SVN commit r1436.
This was SVN commit r976.
This was SVN commit r873.
This was SVN commit r862.