_emx_link.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ndk-python 作者: gittor 项目源码 文件源码
def link(source, target):
    """link(source, target) -> None

    Attempt to hard link the source file to the target file name.
    On OS/2, this creates a complete copy of the source file.
    """

    s = os.open(source, os.O_RDONLY | os.O_BINARY)
    if os.isatty(s):
        raise OSError, (errno.EXDEV, 'Cross-device link')
    data = os.read(s, 1024)

    try:
        t = os.open(target, os.O_WRONLY | os.O_BINARY | os.O_CREAT | os.O_EXCL)
    except OSError:
        os.close(s)
        raise

    try:
        while data:
            os.write(t, data)
            data = os.read(s, 1024)
    except OSError:
        os.close(s)
        os.close(t)
        os.unlink(target)
        raise

    os.close(s)
    os.close(t)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号