海王  
int
direct_safe_dup( int fd )
{
    int n = 0;
    int fc[3];

    while (fd >= 0 && fd <= 2) {
        fc[n++] = fd;
        fd = dup (fd);
    }

    while (n)
        close (fc[--n]);

    return fd;
}
 代码来源directfb
posted on 2010-12-24 14:48  海王  阅读(264)  评论(0编辑  收藏  举报