1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>V4L2 open()</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix A. Function Reference"><link rel="prev" href="func-munmap.html" title="V4L2 munmap()"><link rel="next" href="func-poll.html" title="V4L2 poll()"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">V4L2 open()</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="func-munmap.html">Prev</a> </td><th width="60%" align="center">Appendix A. Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="func-poll.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="func-open"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>v4l2-open — Open a V4L2 device</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <fcntl.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">open</b>(</code></td><td>const char *<var class="pdparam">device_name</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1117010828"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>device_name</code></em></span></dt><dd><p>Device to be opened.</p></dd><dt><span class="term"><em class="parameter"><code>flags</code></em></span></dt><dd><p>Open flags. Access mode must be 2<code class="constant">O_RDWR</code>. This is just a technicality, input devices 3still support only reading and output devices only writing.</p><p>When the <code class="constant">O_NONBLOCK</code> flag is 4given, the read() function and the <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_DQBUF</code></a> ioctl will return 5the <span class="errorcode">EAGAIN</span> error code when no data is available or no buffer is in the driver 6outgoing queue, otherwise these functions block until data becomes 7available. All V4L2 drivers exchanging data with applications must 8support the <code class="constant">O_NONBLOCK</code> flag.</p><p>Other flags have no effect.</p></dd></dl></div></div><div class="refsect1"><a name="idp1117015588"></a><h2>Description</h2><p>To open a V4L2 device applications call 9<code class="function">open()</code> with the desired device name. This 10function has no side effects; all data format parameters, current 11input or output, control values or other properties remain unchanged. 12At the first <code class="function">open()</code> call after loading the driver 13they will be reset to default values, drivers are never in an 14undefined state.</p></div><div class="refsect1"><a name="idp1117058140"></a><h2>Return Value</h2><p>On success <code class="function">open</code> returns the new file 15descriptor. On error -1 is returned, and the <code class="varname">errno</code> 16variable is set appropriately. Possible error codes are:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorcode">EACCES</span></span></dt><dd><p>The caller has no permission to access the 17device.</p></dd><dt><span class="term"><span class="errorcode">EBUSY</span></span></dt><dd><p>The driver does not support multiple opens and the 18device is already in use.</p></dd><dt><span class="term"><span class="errorcode">ENXIO</span></span></dt><dd><p>No device corresponding to this device special file 19exists.</p></dd><dt><span class="term"><span class="errorcode">ENOMEM</span></span></dt><dd><p>Not enough kernel memory was available to complete the 20request.</p></dd><dt><span class="term"><span class="errorcode">EMFILE</span></span></dt><dd><p>The process already has the maximum number of 21files open.</p></dd><dt><span class="term"><span class="errorcode">ENFILE</span></span></dt><dd><p>The limit on the total number of files open on the 22system has been reached.</p></dd></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="func-munmap.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="func-poll.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">V4L2 munmap() </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> V4L2 poll()</td></tr></table></div></body></html> 23