title: Linux I2C file handles - safe to cache?
body: <p>I am just starting to look at the I2C support on (embedded) linux (Beaglebone Black, to be precise). Since it's linux, everything is a file, so it's no surprise that I2C is too.</p>
  
  <pre><code>int file = open( "/dev/i2c-0", O_RDWR );
  </code></pre>
  
  <p>and then the actual address on that bus is selected through <code>ioctl()</code>. My question is this - is it safe, or even <em>legal</em>, to cache <code>file</code> for the duration of application execution? It would seem to my naive eyes that the overheading of opening a resource to read every 250ms would be an unnecessary strain on the kernel. So it is valid to open, and then just use <code>ioctl()</code> to switch address whenever I need to, or must I <code>close()</code> the descriptor between reads and writes?</p>