lib: Refactor read/write functionality

Both the read and write functions used the same code
slightly modified for reading and writing.  Combine this
code together.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>

Edited-by: Paul Jakma <paul.jakma@hpe.com> to retain the
external library symbols, for ease of merging.
1 file changed