Library for subverting current date and time to a given application.

Preload this library to a program that calls time(2) or gettimeofday(2) functions if you need to make it think that it's not the current date but a different one.


Set one of these environment variables:

First call to time() or gettimeofday() will return the given <sec-since-epoch>. Subsequent calls will return a time with appropriate correction, i.e. if the second call to time() occurs five seconds after the first one, it will return <sec-since-epoch>+5.
Each call to time() or gettimeofday() returns current time + <offset_sec_from_now>.

If both variables are set, then FAKE_TIME_OFFSET has a precedence.

To convert a given time to <sec-since-epoch> use:

$ date -d "2000-01-01 12:13:14" +%s


$ date
Wed Sep 24 14:41:20 CEST 2003

Tue Sep 23 14:41:20 CEST 2003

$ FAKE_TIME_START=946725194 LD_PRELOAD=./ date
Sat Jan 1 12:13:14 CET 2000


On ELF systems it is possible to let the library print a help when invoked directly from the command line, i.e.

$ ./ - Library for subverting current time.

For this to work you must know your runtime linker at the time of compilation. The approach used in my Makefile is to build a dummy program, extract its .interp section to a separate file and finally put the content of this file to ld-so.h header.

This was tested on different linux architectures with different names of runtime linkers, e.g. /lib/ on i386, /lib64/ on AMD64, /lib/ on S390, /lib/ on S390x, etc.

Please see the Makefile below for details on how is ld-so.h generated.


The main source itself:
faketime.c (Colorized)
Makefile for successfull build:
Makefile (Colorized)
Tarball both the above files and even more...


Thanks to Andreas Thienemann for clock_gettime(3) support

Place for your feedback...
Sep 2   13:42 good work (by Miro Kubiczek)
Sep 14   19:37 solaris 9 compile (by Eddie Anzalone)
Jun 22   2:28 great stuff! (by J.Frenzel)