1 /*
2  * Copyright (c) 1999, 2000, 2002, 2003 X-Way Rights BV
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  */
19 
20 /*!\file timestamp.c
21  * \brief Java compatible 64-bit timestamp.
22  * \author Bob Deblier <bob.deblier@telenet.be>
23  */
24 
25 #define BEECRYPT_DLL_EXPORT
26 
27 #if HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #include "beecrypt/timestamp.h"
32 
33 #if TIME_WITH_SYS_TIME
34 # include <sys/time.h>
35 # include <time.h>
36 #else
37 # if HAVE_SYS_TIME_H
38 #  include <sys/time.h>
39 # elif HAVE_TIME_H
40 #  include <time.h>
41 # endif
42 #endif
43 
timestamp()44 jlong timestamp()
45 {
46 	jlong tmp;
47 	#if HAVE_SYS_TIME_H
48 	# if HAVE_GETTIMEOFDAY
49 	struct timeval now;
50 
51 	gettimeofday(&now, 0);
52 
53 	tmp = ((jlong) now.tv_sec) * 1000 + (now.tv_usec / 1000);
54 	# else
55 	#  error
56 	# endif
57 	#elif HAVE_TIME_H
58 	tmp = ((jlong) time(0)) * 1000;
59 	#else
60 	# error implement other time function
61 	#endif
62 
63 	return tmp;
64 }
65