1

I want to be able to calculate the time using the minimum amount of header files as possible. So I looked inside of the <time.h> header and found the time function as,

extern time_t time (time_t *__timer) __THROW;

I kind of understand what extern means but I couldn't find anywhere where the body of this function is, I am not even sure if there is such thing.

So how this time function know what to do, and where can I find it?

Mustafa Süve
  • 151
  • 2
  • 11
  • It's in the standard library somewhere. – user253751 Jul 29 '16 at 07:08
  • `time` is part of the standard C library. Don't know what your platform details are. [glibc](https://www.gnu.org/software/libc/) is the common library for Linux. – kaylum Jul 29 '16 at 07:09
  • Usually precompiled into binary libs so there's no need to include the source in your system. For example you could find it in libc.so in Ubuntu x64 by `objdump -TC /lib/x86_64-linux-gnu/libc-2.19.so | grep "\ – neuront Jul 29 '16 at 07:13
  • @kaylum I am at ubuntu right now – Mustafa Süve Jul 29 '16 at 07:14
  • [Here](https://stackoverflow.com/questions/35564970/how-to-format-a-time-stamp-in-c/35565089#35565089) is a working example. Maybe will help you to get an Idea – Michi Jul 29 '16 at 07:16
  • 3
    The actual implementation of `time` is done [in the kernel](https://github.com/torvalds/linux/blob/master/kernel/time/time.c#L63), so this question is more about how glibc interacts with the kernel than finding things in the source of glibc. Therefore, I don't think it is a duplicate of the mentioned question, @PP. – Sjoerd Jul 29 '16 at 07:21
  • @Michi Thank you. Yes I saw something like that. But what I want to do is to get the current time without using `time(NULL)`. I want to be able to do what the `time` function does inside. – Mustafa Süve Jul 29 '16 at 07:43
  • I'm seconding what @Sjoerd said; I believe this question is sufficiently different from the one it supposedly duplicates that it merits its own thread. Voting to reopen. – Jules Oct 29 '16 at 16:05

1 Answers1

0

time.h is a header from the C standard library.

You can find it in your c library implementation of your system. This is the posix implementation in glibc.

aebudak
  • 641
  • 6
  • 8