An ioctl with both read an writes parameters.

    size (ctype type or instance)
        Type/structure of the argument passed to ioctl's "arg" argument.
487755
def IOWR(type, nr, size):
    
    return IOC(IOC_READ | IOC_WRITE, type, nr, IOC_TYPECHECK(size))
779464
def _ctypes_out(parameter):
    
    if (parameter.dimension is not None and ":" in parameter.dimension
        and "out" in parameter.direction and ("allocatable" in parameter.modifiers or
                                              "pointer" in parameter.modifiers)):
        if parameter.direction == "(inout)":
            return ("type(C_PTR), intent(inout) :: {}_o".format(parameter.name), True)
        else: #self.direction == "(out)" since that is the only other option.
            return ("type(C_PTR), intent(inout) :: {}_c".format(parameter.name), True)
968475
function ByteBuffer(arg) {
    var initial_size;
    if (arg == null) {
        initial_size = 1024 * 1024;
    } else if (typeof arg === "number") {
        initial_size = arg;
    } else if (arg instanceof Uint8Array) {
        this.buffer = arg;
        this.position = 0;  // Overwrite
        return;
    } else {
        // typeof arg -> String
        throw typeof arg + " is invalid parameter type for ByteBuffer constructor";
    }
    // arg is null or number
    this.buffer = new Uint8Array(initial_size);
    this.position = 0;
}
1200576
def _ctypes_variables(parameter):
    
    if parameter.dimension is not None and ":" in parameter.dimension:
        #For arrays that provide input (including 'inout'), we pass the output separately
        #through a c-pointer. They will always be input arrays. For pure (out) parameters
        #we use *only* a c-ptr, but it needs intent (inout) since it is created by ctypes.
        if "in" in parameter.direction or parameter.direction == "":
            #We have to get the ctypes-compatible data type for the parameters.
            #stype = _ctypes_dtype(parameter)
            splice = _ctypes_splice(parameter)
            name = parameter.ctypes_parameter()[0]
            if parameter.direction == "(inout)" and not ("allocatable" in parameter.modifiers or
                                                         "pointer" in parameter.modifiers):
                return (parameter.definition(optionals=False, customdim=splice), False)
            else:
                return ("{}, intent(in) :: {}({})".format(parameter.strtype, name, splice), False)
    else:
        if parameter.dtype == "logical":
            stype = _ctypes_dtype(parameter)
            suffix = "_c"
            modifiers = None
        elif hasattr(parameter, "parameters"):
            stype = None
            suffix = "_f"
            modifiers = ["intent(out)"]
        else:
            stype = None
            suffix = ""
            modifiers = None
            
        return (parameter.definition(ctype=stype, optionals=False, suffix=suffix,
                                     modifiers=modifiers), False)
846795
def create_binary_buffer(init_or_size):
    
    # As per ctypes.create_string_buffer, as of python 2.7.10 at least:
    # - int or long is a length
    # - str or unicode is an initialiser
    # Testing the latter confuses 2to3, so test the former.
    if isinstance(init_or_size, (int, long)):
        init_or_size = bytearray(init_or_size)
    return create_initialised_buffer(init_or_size)
560860
def _Cobject(cls, ctype):
    
    o = object.__new__(cls)
    o._as_parameter_ = ctype
    return o
1308592
def alloca(self, typ, size=None, name=''):
        
        if size is None:
            pass
        elif isinstance(size, (values.Value, values.Constant)):
            assert isinstance(size.type, types.IntType)
        else:
            # If it is not a Value instance,
            # assume to be a Python integer.
            size = values.Constant(types.IntType(32), size)

        al = instructions.AllocaInstr(self.block, typ, size, name)
        self._insert(al)
        return al
658296
def get_terminal_size():
    ''''''
    def read_terminal_size_by_ioctl(fd):
        try:
            import struct, fcntl, termios
            cr = struct.unpack('hh', fcntl.ioctl(1, termios.TIOCGWINSZ,
                                                            '0000'))
        except ImportError:
            return None
        except IOError as e:
            return None
        return cr[1], cr[0]

    cr = read_terminal_size_by_ioctl(0) or \
            read_terminal_size_by_ioctl(1) or \
            read_terminal_size_by_ioctl(2)
    if not cr:
        try:
            import os
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = read_terminal_size_by_ioctl(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        import os
        cr = [80, 25] # 25 rows, 80 columns is the default value
        if os.getenv('ROWS'):
            cr[1] = int(os.getenv('ROWS'))
        if os.getenv('COLUMNS'):
            cr[0] = int(os.getenv('COLUMNS'))

    return cr[1], cr[0]
1146719
def _term_size(self):
        
        for fd in (0, 1, 2):
            try:
                return self._ioctl_GWINSZ(fd)
            except:
                pass
        # try os.ctermid()
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            try:
                return self._ioctl_GWINSZ(fd)
            finally:
                os.close(fd)
        except:
            pass
        # try `stty size`
        try:
            return tuple(int(x) for x in os.popen("stty size", "r").read().split())
        except:
            pass
        # try environment variables
        try:
            return tuple(int(os.getenv(var)) for var in ("LINES", "COLUMNS"))
        except:
            pass
        # i give up. return default.
        return (25, 80)
814940
def writeObject(self, o):
        
        if self.writeReference(o) != -1:
            return

        self.context.addObject(o)
        alias = self.context.getClassAlias(o.__class__)

        alias.compile()

        if alias.amf3:
            self.writeAMF3(o)

            return

        if alias.anonymous:
            self.writeType(TYPE_OBJECT)
        else:
            self.writeType(TYPE_TYPEDOBJECT)
            self.serialiseString(alias.alias)

        attrs = alias.getEncodableAttributes(o, codec=self)

        if alias.static_attrs and attrs:
            for key in alias.static_attrs:
                value = attrs.pop(key)

                self.serialiseString(key)
                self.writeElement(value)

        if attrs:
            self._writeDict(attrs)

        self._writeEndObject()
1200105
def writeInfoLine(self, stream, fromUUID, size):
        
        if size is None or fromUUID is None:
            return
        if not isinstance(size, int):
            logger.warning("Bad size: %s", size)
            return
        stream.write(str("%s\t%s\t%d\n" % (
            self.uuid,
            fromUUID,
            size,
        )))
1235177
def get_terminal_size():
    "
    try:
        rc = os.popen('stty size', 'r').read().split()
        return int(rc[0]), int(rc[1])
    except:
        pass

    env = os.environ

    def ioctl_GWINSZ(fd):
        try:
            import fcntl, termios, struct
            rc = struct.unpack('hh',
                               fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
            return rc
        except:
            return None

    rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)

    if not rc:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            rc = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass

    if not rc:
        rc = (env.get('LINES', 25), env.get('COLUMNS', 80))

    return int(rc[0]), int(rc[1])
807052
def IOC(dir, type, nr, size):
    
    assert dir <= _IOC_DIRMASK, dir
    assert type <= _IOC_TYPEMASK, type
    assert nr <= _IOC_NRMASK, nr
    assert size <= _IOC_SIZEMASK, size
    return (dir << _IOC_DIRSHIFT) | (type << _IOC_TYPESHIFT) | (nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT)
1221591
def writeline(self, fmt, *args):
        
        fmt = self.endian + fmt
        size = struct.calcsize(fmt)

        fix = struct.pack(self.endian + 'i', size)
        line = struct.pack(fmt, *args)

        self.write(fix)
        self.write(line)
        self.write(fix)
414303
def write(self, s, size=None):
        
        self._buffer.write(s)
        self._len_changed = True
339300
def params_size(m: Union[nn.Module,Learner], size: tuple = (3, 64, 64))->Tuple[Sizes, Tensor, Hooks]:
    ""
    if isinstance(m, Learner):
        if m.data.is_empty:
            raise Exception("This is an empty `Learner` and `Learner.summary` requires some data to pass through the model.")
        ds_type = DatasetType.Train if m.data.train_dl else (DatasetType.Valid if m.data.valid_dl else DatasetType.Test)
        x = m.data.one_batch(ds_type=ds_type, detach=False, denorm=False)[0]
        x = [o[:1] for o in x]  if is_listy(x) else x[:1]
        m = m.model
    elif isinstance(m, nn.Module): x = next(m.parameters()).new(1, *size)
    else: raise TypeError('You should either pass in a Learner or nn.Module')
    with hook_outputs(flatten_model(m)) as hook_o:
        with hook_params(flatten_model(m))as hook_p:
            x = m.eval()(*x) if is_listy(x) else m.eval()(x)
            output_size = [((o.stored.shape[1:]) if o.stored is not None else None) for o in hook_o]
            params = [(o.stored if o.stored is not None else (None,None)) for o in hook_p]
    params, trainables = map(list,zip(*params))
    return output_size, params, trainables
1278451
def make_ctypes_convertor(self, _flags):
        
        tu = util.get_tu('''
typedef short short_t;
typedef int int_t;
typedef long long_t;
typedef long long longlong_t;
typedef float float_t;
typedef double double_t;
typedef long double longdouble_t;
typedef void* pointer_t;''', flags=_flags)
        size = util.get_cursor(tu, 'short_t').type.get_size() * 8
        self.ctypes_typename[TypeKind.SHORT] = 'c_int%d' % (size)
        self.ctypes_typename[TypeKind.USHORT] = 'c_uint%d' % (size)
        self.ctypes_sizes[TypeKind.SHORT] = size
        self.ctypes_sizes[TypeKind.USHORT] = size

        size = util.get_cursor(tu, 'int_t').type.get_size() * 8
        self.ctypes_typename[TypeKind.INT] = 'c_int%d' % (size)
        self.ctypes_typename[TypeKind.UINT] = 'c_uint%d' % (size)
        self.ctypes_sizes[TypeKind.INT] = size
        self.ctypes_sizes[TypeKind.UINT] = size

        size = util.get_cursor(tu, 'long_t').type.get_size() * 8
        self.ctypes_typename[TypeKind.LONG] = 'c_int%d' % (size)
        self.ctypes_typename[TypeKind.ULONG] = 'c_uint%d' % (size)
        self.ctypes_sizes[TypeKind.LONG] = size
        self.ctypes_sizes[TypeKind.ULONG] = size

        size = util.get_cursor(tu, 'longlong_t').type.get_size() * 8
        self.ctypes_typename[TypeKind.LONGLONG] = 'c_int%d' % (size)
        self.ctypes_typename[TypeKind.ULONGLONG] = 'c_uint%d' % (size)
        self.ctypes_sizes[TypeKind.LONGLONG] = size
        self.ctypes_sizes[TypeKind.ULONGLONG] = size

        # FIXME : Float && http://en.wikipedia.org/wiki/Long_double
        size0 = util.get_cursor(tu, 'float_t').type.get_size() * 8
        size1 = util.get_cursor(tu, 'double_t').type.get_size() * 8
        size2 = util.get_cursor(tu, 'longdouble_t').type.get_size() * 8
        # 2014-01 stop generating crap.
        # 2015-01 reverse until better solution is found
        # the idea is that a you cannot assume a c_double will be same format as a c_long_double.
        # at least this pass size TU
        if size1 != size2:
            self.ctypes_typename[TypeKind.LONGDOUBLE] = 'c_long_double_t'
        else:
            self.ctypes_typename[TypeKind.LONGDOUBLE] = 'c_double'

        self.ctypes_sizes[TypeKind.FLOAT] = size0
        self.ctypes_sizes[TypeKind.DOUBLE] = size1
        self.ctypes_sizes[TypeKind.LONGDOUBLE] = size2

        # save the target pointer size.
        size = util.get_cursor(tu, 'pointer_t').type.get_size() * 8
        self.ctypes_sizes[TypeKind.POINTER] = size
        self.ctypes_sizes[TypeKind.NULLPTR] = size

        log.debug('ARCH sizes: long:%s longdouble:%s',
                  self.ctypes_typename[TypeKind.LONG],
                  self.ctypes_typename[TypeKind.LONGDOUBLE])
        return