Leverage common IO routines from libcouchbase

Change-Id: Ibab96d75226bb2dfe78550d90f7f6dd2c05137a2
Reviewed-on: http://review.couchbase.org/40026
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>