add readn and writen functions for unp