readline: use g_strndup instead of open-coding it