use strdup and take size_t instead of int for read and write_until