title: How to find out if the linux kernel will insert a leap second at the end of the month
body: <p>Suppose my program runs on a linux machine that is properly configured to handle <a href="http://www.eecis.udel.edu/~mills/leap.html">leap seconds</a>. How that configuration is done exactly (NTP, config file) should not be relevant to this question.</p>
  
  <p>In effect, the kernel will insert an additional second or skip over a second at the UTC end of the month. This has an effect on the time value read by gettimeofday(2). The last UTC second of the month is either repeated or skipped. Example readings of the time during a leap second are <a href="http://lists.ntp.org/pipermail/questions/2006-January/008560.html">listed here</a>.</p>
  
  <p>My question: How can I find out, in a C/C++ program, if a leap second will occur at the end of the month, and in which direction. So how do I implement the following function on linux</p>
  
  <pre><code>int leap_seconds_scheduled_for_end_of_month() {
    if (/*kernel_will_insert_extra_second?*/)
      return 1;
    if (/*kernel_will_skip_over_last_second?*/)
      return -1;
    return 0;
  }
  </code></pre>
  
  <p>It is ok if the result is incorrect if the end of the month is far in the future. (far, for my purposes, is >=2 seconds)  The answer has to be correct(*) during the last second before a possible leap second, i.e. 23:59:58 UTC on the last day of the month. It is not sufficient if I learn about the leap second after it has occurred, as I have to prepare for it in advance.</p>
  
  <p>I have been trying to find any leap second indicator in sysfs or procfs, but so far have been unsuccessful.</p>
  
  <p>(*) Of course, if the kernel itself learns about the leap second only a fraction before it occurs, e.g. due to an outage of the NTP service during the whole last month, the answer cannot be correct then. That's ok.</p>