I know that I can get the current local time by time()
function in C.
int main(void)
{
time_t now = time(NULL);
struct tm *tm = localtime(&now);
}
However, I want to the insider of the time()
function, which means I want to know how the function knows the system time.
In, time.h
file, I see that there is defined of the function and it looks like the one below.
time_t time(time_t *);
Thus, I find what time_t
is and it is defined like the one below.
typedef __darwin_time_t time_t;
Finally, __darwin_time_t
type is defined like the one below.
typedef long __darwin_time_t;
How the time()
function get the current time? Where the code to get the current time of the system?
I'm a beginner of the C programming and wonder how the compiler gets the time.