<div dir="ltr"><div style>Try to open /dev/null, and then to poll the file descriptor. Neither in the man page nor in the standard I see anything preventing you to poll on /dev/null, yet, it does not work on Mac OS X. You get a POLLNVAL.</div>
<div style><br></div>Run the following:<div><br></div><div><a href="https://gist.github.com/elazarl/5805848">https://gist.github.com/elazarl/5805848</a><br><div><br></div><div><pre class="" style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:16px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0)">
<div class="" id="file-poll_dev-c-LC1"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include <stdio.h></span></div><div class="" id="file-poll_dev-c-LC2"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include <poll.h></span></div>
<div class="" id="file-poll_dev-c-LC3"> </div><div class="" id="file-poll_dev-c-LC4"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include <fcntl.h></span></div><div class="" id="file-poll_dev-c-LC5">
</div><div class="" id="file-poll_dev-c-LC6"><span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">main</span><span class="">()</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC7"> <span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="" style="color:rgb(51,51,51)">fd</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(51,51,51)">open</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"/dev/null"</span><span class="">,</span> <span class="" style="color:rgb(51,51,51)">O_WRONLY</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC8"> <span class="" style="font-weight:bold">struct</span> <span class="" style="color:rgb(51,51,51)">pollfd</span> <span class="" style="color:rgb(51,51,51)">pollfds</span> <span class="" style="font-weight:bold">=</span> <span class="">{</span> <span class="" style="color:rgb(51,51,51)">fd</span><span class="">,</span> <span class="" style="color:rgb(51,51,51)">POLLOUT</span><span class="">,</span> <span class="" style="color:rgb(0,153,153)">0</span> <span class="">};</span></div>
<div class="" id="file-poll_dev-c-LC9"> <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">fd</span> <span class="" style="font-weight:bold"><</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC10"> <span class="" style="color:rgb(51,51,51)">perror</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"open"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC11"> <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="">;</span></div><div class="" id="file-poll_dev-c-LC12">
<span class="">}</span></div><div class="" id="file-poll_dev-c-LC13"> <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">poll</span><span class="">(</span><span class="" style="font-weight:bold">&</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">,</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="">,</span> <span class="" style="font-weight:bold">-</span><span class="" style="color:rgb(0,153,153)">1</span><span class="">)</span> <span class="" style="font-weight:bold"><</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC14"> <span class="" style="color:rgb(51,51,51)">perror</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"poll"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC15"> <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">2</span><span class="">;</span></div><div class="" id="file-poll_dev-c-LC16">
<span class="">}</span></div><div class="" id="file-poll_dev-c-LC17"> <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">.</span><span class="" style="color:rgb(51,51,51)">revents</span> <span class="" style="font-weight:bold">==</span> <span class="" style="color:rgb(51,51,51)">POLLNVAL</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC18"> <span class="" style="color:rgb(51,51,51)">puts</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"huh? why poll({/dev/null, POLLOUT, 0}, 1) returns POLLNVAL?"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC19"> <span class="">}</span></div><div class="" id="file-poll_dev-c-LC20"> <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">.</span><span class="" style="color:rgb(51,51,51)">revents</span> <span class="" style="font-weight:bold">==</span> <span class="" style="color:rgb(51,51,51)">POLLOUT</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC21"> <span class="" style="color:rgb(51,51,51)">puts</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"working as expected"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC22"> <span class="">}</span></div><div class="" id="file-poll_dev-c-LC23"> <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">;</span></div>
<div class="" id="file-poll_dev-c-LC24"><span class="">}</span></div><div class="" id="file-poll_dev-c-LC24"><span class=""><br></span></div><div class="" id="file-poll_dev-c-LC24" style><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">Is there anything I'm missing? Or is it a real vaguely implemented corner of the standard.</span><br>
</div><div class="" id="file-poll_dev-c-LC24" style><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">If it is, I'll be glad to see a list of supported/unsupported platforms,</span></div>
<div class="" id="file-poll_dev-c-LC24" style><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">as well as list of other corner cases (for instance, POLLHUP may or may be received on EOF).</span></div>
<div class="" id="file-poll_dev-c-LC24" style><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal"><br></span></div></pre></div></div></div>