xref: /linux/Documentation/userspace-api/media/cec/cec-func-open.rst (revision dd05fd125e66932e54da696f33f0cee51d4f8e95)
1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
201fae02dSMauro Carvalho Chehab.. c:namespace:: CEC
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _cec-func-open:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab**********
754f38fcaSMauro Carvalho Chehabcec open()
854f38fcaSMauro Carvalho Chehab**********
954f38fcaSMauro Carvalho Chehab
1054f38fcaSMauro Carvalho ChehabName
1154f38fcaSMauro Carvalho Chehab====
1254f38fcaSMauro Carvalho Chehab
1354f38fcaSMauro Carvalho Chehabcec-open - Open a cec device
1454f38fcaSMauro Carvalho Chehab
1554f38fcaSMauro Carvalho ChehabSynopsis
1654f38fcaSMauro Carvalho Chehab========
1754f38fcaSMauro Carvalho Chehab
1854f38fcaSMauro Carvalho Chehab.. code-block:: c
1954f38fcaSMauro Carvalho Chehab
2054f38fcaSMauro Carvalho Chehab    #include <fcntl.h>
2154f38fcaSMauro Carvalho Chehab
2254f38fcaSMauro Carvalho Chehab.. c:function:: int open( const char *device_name, int flags )
2354f38fcaSMauro Carvalho Chehab
2454f38fcaSMauro Carvalho ChehabArguments
2554f38fcaSMauro Carvalho Chehab=========
2654f38fcaSMauro Carvalho Chehab
2754f38fcaSMauro Carvalho Chehab``device_name``
2854f38fcaSMauro Carvalho Chehab    Device to be opened.
2954f38fcaSMauro Carvalho Chehab
3054f38fcaSMauro Carvalho Chehab``flags``
3154f38fcaSMauro Carvalho Chehab    Open flags. Access mode must be ``O_RDWR``.
3254f38fcaSMauro Carvalho Chehab
3354f38fcaSMauro Carvalho Chehab    When the ``O_NONBLOCK`` flag is given, the
3454f38fcaSMauro Carvalho Chehab    :ref:`CEC_RECEIVE <CEC_RECEIVE>` and :ref:`CEC_DQEVENT <CEC_DQEVENT>` ioctls
3554f38fcaSMauro Carvalho Chehab    will return the ``EAGAIN`` error code when no message or event is available, and
3654f38fcaSMauro Carvalho Chehab    ioctls :ref:`CEC_TRANSMIT <CEC_TRANSMIT>`,
3754f38fcaSMauro Carvalho Chehab    :ref:`CEC_ADAP_S_PHYS_ADDR <CEC_ADAP_S_PHYS_ADDR>` and
3854f38fcaSMauro Carvalho Chehab    :ref:`CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
3954f38fcaSMauro Carvalho Chehab    all return 0.
4054f38fcaSMauro Carvalho Chehab
4154f38fcaSMauro Carvalho Chehab    Other flags have no effect.
4254f38fcaSMauro Carvalho Chehab
4354f38fcaSMauro Carvalho ChehabDescription
4454f38fcaSMauro Carvalho Chehab===========
4554f38fcaSMauro Carvalho Chehab
4601fae02dSMauro Carvalho ChehabTo open a cec device applications call :c:func:`open()` with the
4754f38fcaSMauro Carvalho Chehabdesired device name. The function has no side effects; the device
4854f38fcaSMauro Carvalho Chehabconfiguration remain unchanged.
4954f38fcaSMauro Carvalho Chehab
5054f38fcaSMauro Carvalho ChehabWhen the device is opened in read-only mode, attempts to modify its
5154f38fcaSMauro Carvalho Chehabconfiguration will result in an error, and ``errno`` will be set to
5254f38fcaSMauro Carvalho ChehabEBADF.
5354f38fcaSMauro Carvalho Chehab
5454f38fcaSMauro Carvalho ChehabReturn Value
5554f38fcaSMauro Carvalho Chehab============
5654f38fcaSMauro Carvalho Chehab
5701fae02dSMauro Carvalho Chehab:c:func:`open()` returns the new file descriptor on success. On error,
5854f38fcaSMauro Carvalho Chehab-1 is returned, and ``errno`` is set appropriately. Possible error codes
5954f38fcaSMauro Carvalho Chehabinclude:
6054f38fcaSMauro Carvalho Chehab
6154f38fcaSMauro Carvalho Chehab``EACCES``
6254f38fcaSMauro Carvalho Chehab    The requested access to the file is not allowed.
6354f38fcaSMauro Carvalho Chehab
6454f38fcaSMauro Carvalho Chehab``EMFILE``
6554f38fcaSMauro Carvalho Chehab    The process already has the maximum number of files open.
6654f38fcaSMauro Carvalho Chehab
6754f38fcaSMauro Carvalho Chehab``ENFILE``
6854f38fcaSMauro Carvalho Chehab    The system limit on the total number of open files has been reached.
6954f38fcaSMauro Carvalho Chehab
7054f38fcaSMauro Carvalho Chehab``ENOMEM``
7154f38fcaSMauro Carvalho Chehab    Insufficient kernel memory was available.
7254f38fcaSMauro Carvalho Chehab
73*dd05fd12SHans Verkuil``ENODEV``
74*dd05fd12SHans Verkuil    Device not found or was removed.
75