def get_osfhandle(fd): from rpython.rlib.rposix import validate_fd validate_fd(fd) handle = _get_osfhandle(fd) if handle == INVALID_HANDLE_VALUE: raise WindowsError(ERROR_INVALID_HANDLE, "Invalid file handle") return handle
def create_fdopen_rfile(fd, mode="r", buffering=-1): newmode = _sanitize_mode(mode) rposix.validate_fd(fd) ll_mode = rffi.str2charp(newmode) try: ll_file = c_fdopen(fd, ll_mode) if not ll_file: errno = rposix.get_saved_errno() raise OSError(errno, os.strerror(errno)) finally: lltype.free(ll_mode, flavor='raw') _dircheck(ll_file) f = RFile(ll_file, mode) f._setbufsize(buffering) return f
def validate_fd(space, fd): try: rposix.validate_fd(fd) except OSError, e: raise wrap_oserror(space, e)
def feof(fp): validate_fd(fileno(fp)) return _feof(fp)
def fread(buf, sz, n, fp): validate_fd(fileno(fp)) return _fread(buf, sz, n, fp)
def fwrite(buf, sz, n, fp): validate_fd(fileno(fp)) return _fwrite(buf, sz, n, fp)