Shouldn't you init band_fd to -1? 0 is stdin.