LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2011, 09:42 AM   #1
bidur
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
Source code for the time_t time( time_t *timer ) function


I am longing to know how the clock ticks are read and then they are stored in the data structure (time_t). I could learn that The time_t is at least 2 bytes long since they store somewhat unique timestamp(with all the year, month, day, hour, second, etc).
I am trying to encode just 24 hours time with as less as possible number of bits. I am able to encode 86400 seconds by using 11 bits, Is it possible to do so by using lesser bits than 11?
For that, I am trying to see how the time is calculated by using the clock ticks information by the standard C function time_t time( time_t *timer ) declared in time.h .
I searched the code for time.h in the ubuntu machine I could find many header files time.h which just declare the time() function with extern keyword. How can I locate the source file location where the actual implementation of the time() function is done.

I am hoping for relevant guidance.

Thanks
 
Old 08-29-2011, 12:54 PM   #2
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Smile Kernel sources should be what you are looking for...

Hi there!

First of all, you need to get yourself the kernel sources, because the header files won't tell you what you long to know. That for, you might want to take a closer look at this.

Once you got the kernel sources, a few hundred megabyte of digital wisdom await your exploration. To cut things short, you might want to try something like:

Code:
find /YOUR_SOURCE_CODE_DIRECTORY -name time.c
When it comes to my box, its like

Code:
Me@MYBOX ~/Linux_source/linux-source-2.6.35 $ find ./ -name time.c
./kernel/time.c
./arch/m32r/kernel/time.c
./arch/m68k/kernel/time.c
./arch/m68k/atari/time.c
./arch/m68k/sun3x/time.c
./arch/m68k/hp300/time.c

...and so on...

Here is what made me think this would be a good enty point:
Code:
/*
 *  linux/kernel/time.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  This file contains the interface functions for the various
 *  time related system calls: time, stime, gettimeofday, settimeofday,
 *			       adjtime
 */
/*

I guess, from now on you will have to digg your way on your own. But in case you get stuck, don't hesitate to ask again...

Have fun,

Heraton

Last edited by Heraton; 08-29-2011 at 01:04 PM. Reason: added header "preview"
 
Old 09-06-2011, 06:07 AM   #3
bidur
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Dear Friends,
Thanks you for your replies which helped in my understandings.
Also, as I have said earlier in my description that 24 hours can be encoded by 11 bits, I had a calculation error and 11 bits can encode 24 hours not in terms of seconds but in terms of minutes only. For encoding 24 hours in terms of seconds (i.e. 86400 seconds) it requires at least 17 bits. I could not find ways to encode time(86400 seconds) in less than 17 bits.

Thank You
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] why I couldn't find the source code of printf function in glibc source? famsinyi Programming 5 09-21-2009 09:06 AM
[SOLVED] Get the number of leap seconds in time ( time_t) minimol Linux - Newbie 5 07-07-2009 11:52 AM
Can't find a function in a program's source code 2.718281828 Programming 2 12-01-2006 07:37 PM
source code for libc function dvm Programming 1 12-27-2004 06:04 PM
source code for read() function ? Mike Davies Linux - Software 1 11-03-2004 02:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration