simplify base64_encode

base64_encode will now allocate its buffer internally.
cleanup base64_decode
return bytes written and use standard error numbers
Merge branch 'cleanups'

* cleanups:
  return bytes written and use standard error numbers
  cleanup base64_decode
  simplify base64_encode