On linux you can use clock_gettime() with CLOCK_TAI:
CLOCK_TAI (since Linux 3.10; Linux-specific)
A nonsettable system-wide clock derived from wall-clock time
but ignoring leap seconds. This clock does not experience
discontinuities and backwards jumps caused by NTP inserting
leap seconds as CLOCK_REALTIME does.
The acronym TAI refers to International Atomic Time.
Now, leap seconds are advertised in advance and your system know when they occur through a leap seconds file (leap-seconds.list) that needs to be kept up to date.