Linux and the Y2K Bug
Robert Kiesling
Listing 1 | Listing
2
Linux, like other POSIX-compliant operating systems, provides facilities for coping
with the Y2K bug, and software written properly for Linux should be able to cope
with the end of the millennium. As a systems administrator, however, you may want
to test both your Linux systems and any applications running on them for date
compliance.
This article describes the time keeping functions that are available in the Linux C libraries, Version 5. The GNU glib2 libraries, which are still in the early stages of development, will provide similar functionality and compliance with time keeping standards. I also explore how you might go about testing Linux-based applications for date compliance.
Linux Time
Linux keeps track of the time using the 32-bit time_t type that maintains the count of UTC calendar time, which is the number of seconds since January 1, 1970. It is declared in time.h as the following:
typedef long time_t;
The standard UNIX utilities (or the free software versions distributed by the GNU project) that have been ported to Linux, support this data type. Assuming that the hardware clock handles the dates in the next century correctly, time keeping should be correct until the year 2038, when the 32-bit time_t counter will overflow. Solving what may become known as the Y2038K bug is beyond the scope of this article, however.
The Linux libraries include the following functions to provide time and date information.
time() /* Returns the value of time_t in seconds. */
ctime() /* Returns ASCII formatted output from time_t. */
stime() /* Set the date and time using UTC calendar time. */
Functions related to ctime(), such as asctime(), gmtime(), localtime(), and mktime(), use the value stored in time_t and return hours, minutes, seconds, day, date, month, and year in either data structure tm, or in ASCII format.<>
|