<p>FilePlugin currently splits files in to two groups: 1) Stdio streams and<br>
2) everything else.</p>
<p>To test for the end of file, FilePlugin>>primitiveFileAtEnd:</p>
<ol>
<li>Uses feof() for stdio streams.</li>
<li>Compares the current position to the file size for everything else.</li>
</ol>
<p>This returns the expected results for regular files, but fails for<br>
non-regular files, e.g.:</p>
<p>(FileSystem / 'dev' / 'urandom') binaryReadStream next: 8.</p>
<p>returns an empty array.</p>
<p>On Unix, the proper way to check is to read past the end of the file and<br>
then call feof() to confirm that it is in fact at the end.</p>
<p>Pharo has plenty of code that assumes that a file position >= the file<br>
size means that the file is at the end, and as stated above this<br>
generally works for regular files.</p>
<p>This patch modifies FilePlugin>>primitiveFileAtEnd to:</p>
<p>a) Keep the current behaviour of using the file position test for<br>
regular files.<br>
b) Keep the current behaviour of using feof() for stdio streams.<br>
c) Use feof() for non-regular files, e.g. /dev/urandom.</p>
<p>This allows existing code to continue to function, and allows<br>
non-regular files to be tested correctly.</p>
<p>After applying the patch, the example code above answers the expected<br>
result, e.g.:</p>
<p>(FileSystem / 'dev' / 'urandom') binaryReadStream next: 8.<br>
" #[179 136 227 226 28 147 197 125]"</p>
<p>On Windows, as far as I can tell, all files are regular, and the<br>
position test is used regularly, so no change is requried.</p>
<p>Fogbugz: <a href="https://pharo.fogbugz.com/f/cases/21643/" rel="nofollow">https://pharo.fogbugz.com/f/cases/21643/</a></p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232'>https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>FilePlugin>>primitiveFileAtEnd for non-regular files</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232/files#diff-0">platforms/Cross/plugins/FilePlugin/FilePlugin.h</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232/files#diff-1">platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c</a>
    (30)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232.patch'>https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232.patch</a></li>
  <li><a href='https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232.diff'>https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyW7DPoIZoTghIkEsORDPM6y-dJLkMks5tiKB4gaJpZM4S6rMa">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyW3KwrL6OHurk-4JWtVh7bFghkI_8ks5tiKB4gaJpZM4S6rMa.gif" height="1" width="1" alt="" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"FilePlugin\u003e\u003eprimitiveFileAtEnd for non-regular files (#232)"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232"}}}</script>