<div dir="ltr">If BLOCKSIZE is less than 512, X will be 0<br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 17, 2014 at 10:45 PM, Jan Schaumann <span dir="ltr">&lt;<a href="mailto:jschauma@stevens.edu" target="_blank">jschauma@stevens.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">zding4 &lt;<a href="mailto:zding4@stevens.edu">zding4@stevens.edu</a>&gt; wrote:<br>
&gt; APUE book have the paragraph about st_blocks<br>
&gt;<br>
&gt; &quot;Be aware that different versions of the UNIX System use units other<br>
&gt; than 512-byte blocks for st_blocks.<br>
&gt; Using this value is nonportable&quot;<br>
<br>
</span>That is correct.  However, there is no portable method of determining<br>
the value used for st_blocks, so for our purposes here we may make the<br>
assumption that it is in fact 512 bytes.<br>
<br>
That means that the approach of calculating the correct value based on<br>
the environment variable as discussed in this thread does work (although<br>
you need to be careful to round up when needed).<br>
<br>
The NetBSD implementation of ls(1) takes the approach of setting the<br>
value for &#39;-s&#39; output to<br>
<br>
X = BLOCKSIZE/512<br>
Y = ( (st_blocks + (X - 1)) / X )<br>
<br>
st_blocks * 512 / BLOCKSIZE  will get close, but occasionally be off by<br>
one.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Jan<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/mailman/listinfo/cs631apue</a><br>
</div></div></blockquote></div><br></div></div>