Exemplo n.º 1
0
def fstat(fd):
    if not _WIN32:
        with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
            handle_posix_error("fstat", c_fstat(fd, stresult))
            return build_stat_result(stresult)
    else:
        handle = rwin32.get_osfhandle(fd)
        win32traits = make_win32_traits(string_traits)
        filetype = win32traits.GetFileType(handle)
        if filetype == win32traits.FILE_TYPE_CHAR:
            # console or LPT device
            return make_stat_result((win32traits._S_IFCHR, 0, 0, 0, 0, 0, 0, 0, 0, 0))
        elif filetype == win32traits.FILE_TYPE_PIPE:
            # socket or named pipe
            return make_stat_result((win32traits._S_IFIFO, 0, 0, 0, 0, 0, 0, 0, 0, 0))
        elif filetype == win32traits.FILE_TYPE_UNKNOWN:
            error = rwin32.GetLastError_saved()
            if error != 0:
                raise WindowsError(error, "os_fstat failed")
            # else: unknown but valid file

        # normal disk file (FILE_TYPE_DISK)
        info = lltype.malloc(win32traits.BY_HANDLE_FILE_INFORMATION, flavor="raw", zero=True)
        try:
            res = win32traits.GetFileInformationByHandle(handle, info)
            if res == 0:
                raise WindowsError(rwin32.GetLastError_saved(), "os_fstat failed")
            return win32_by_handle_info_to_stat(win32traits, info)
        finally:
            lltype.free(info, flavor="raw")
Exemplo n.º 2
0
def fstat(fd):
    if not _WIN32:
        with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
            handle_posix_error('fstat', c_fstat(fd, stresult))
            return build_stat_result(stresult)
    else:
        handle = rwin32.get_osfhandle(fd)
        win32traits = make_win32_traits(string_traits)
        filetype = win32traits.GetFileType(handle)
        if filetype == win32traits.FILE_TYPE_CHAR:
            # console or LPT device
            return make_stat_result(
                (win32traits._S_IFCHR, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
        elif filetype == win32traits.FILE_TYPE_PIPE:
            # socket or named pipe
            return make_stat_result(
                (win32traits._S_IFIFO, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
        elif filetype == win32traits.FILE_TYPE_UNKNOWN:
            error = rwin32.GetLastError_saved()
            if error != 0:
                raise WindowsError(error, "os_fstat failed")
            # else: unknown but valid file

        # normal disk file (FILE_TYPE_DISK)
        info = lltype.malloc(win32traits.BY_HANDLE_FILE_INFORMATION,
                             flavor='raw',
                             zero=True)
        try:
            res = win32traits.GetFileInformationByHandle(handle, info)
            if res == 0:
                raise WindowsError(rwin32.GetLastError_saved(),
                                   "os_fstat failed")
            return win32_by_handle_info_to_stat(win32traits, info)
        finally:
            lltype.free(info, flavor='raw')
Exemplo n.º 3
0
 def fstatat(pathname, dir_fd=AT_FDCWD, follow_symlinks=True):
     if follow_symlinks:
         flags = 0
     else:
         flags = AT_SYMLINK_NOFOLLOW
     with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
         error = c_fstatat(dir_fd, pathname, stresult, flags)
         handle_posix_error('fstatat', error)
         return build_stat_result(stresult)
Exemplo n.º 4
0
 def fstatat(pathname, dir_fd=AT_FDCWD, follow_symlinks=True):
     if follow_symlinks:
         flags = 0
     else:
         flags = AT_SYMLINK_NOFOLLOW
     with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
         error = c_fstatat(dir_fd, pathname, stresult, flags)
         handle_posix_error('fstatat', error)
         return build_stat_result(stresult)
Exemplo n.º 5
0
def lstat(path):
    if not _WIN32:
        with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
            arg = _as_bytes0(path)
            handle_posix_error("lstat", c_lstat(arg, stresult))
            return build_stat_result(stresult)
    else:
        traits = _preferred_traits(path)
        path = traits.as_str0(path)
        return win32_xstat(traits, path, traverse=False)
Exemplo n.º 6
0
def lstat(path):
    if not _WIN32:
        with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
            arg = _as_bytes0(path)
            handle_posix_error('lstat', c_lstat(arg, stresult))
            return build_stat_result(stresult)
    else:
        traits = _preferred_traits(path)
        path = traits.as_str0(path)
        return win32_xstat(traits, path, traverse=False)
Exemplo n.º 7
0
 def _getrandom(n, result, signal_checker):
     if not getrandom_works.status:
         return n
     while n > 0:
         with rffi.scoped_alloc_buffer(n) as buf:
             got = syscall(SYS_getrandom, buf.raw, n, GRND_NONBLOCK)
             if got >= 0:
                 s = buf.str(got)
                 result.append(s)
                 n -= len(s)
                 continue
         err = get_saved_errno()
         if (err == errno.ENOSYS or err == errno.EPERM or
                 err == errno.EAGAIN):   # see CPython 3.5
             getrandom_works.status = False
             return n
         if err == errno.EINTR:
             if signal_checker is not None:
                 signal_checker()
             continue
         handle_posix_error("getrandom", got)
         raise AssertionError("unreachable")
     return n
Exemplo n.º 8
0
def statvfs(path):
    with lltype.scoped_alloc(STATVFS_STRUCT.TO) as stresult:
        arg = _as_bytes0(path)
        handle_posix_error("statvfs", c_statvfs(arg, stresult))
        return build_statvfs_result(stresult)
Exemplo n.º 9
0
def fstatvfs(fd):
    with lltype.scoped_alloc(STATVFS_STRUCT.TO) as stresult:
        handle_posix_error("fstatvfs", c_fstatvfs(fd, stresult))
        return build_statvfs_result(stresult)
Exemplo n.º 10
0
def statvfs(path):
    with lltype.scoped_alloc(STATVFS_STRUCT.TO) as stresult:
        arg = _as_bytes0(path)
        handle_posix_error('statvfs', c_statvfs(arg, stresult))
        return build_statvfs_result(stresult)
Exemplo n.º 11
0
def fstatvfs(fd):
    with lltype.scoped_alloc(STATVFS_STRUCT.TO) as stresult:
        handle_posix_error('fstatvfs', c_fstatvfs(fd, stresult))
        return build_statvfs_result(stresult)