rewrite IO.for_fd in C.