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