1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #include <stdio.h>
|
---|
39 | #include <stdlib.h>
|
---|
40 |
|
---|
41 | #if defined(VMS)
|
---|
42 | #include <sys/timeb.h>
|
---|
43 | #elif defined(XP_UNIX) || defined(XP_OS2_EMX) || defined(XP_BEOS)
|
---|
44 | #include <sys/time.h>
|
---|
45 | #elif defined(WIN32)
|
---|
46 | #include <windows.h>
|
---|
47 | #elif defined(XP_OS2_VACPP)
|
---|
48 | #include <sys/timeb.h>
|
---|
49 | #else
|
---|
50 | #error "Architecture not supported"
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | int main(int argc, char **argv)
|
---|
55 | {
|
---|
56 | #if defined(OMIT_LIB_BUILD_TIME)
|
---|
57 | /*
|
---|
58 | * Some platforms don't have any 64-bit integer type
|
---|
59 | * such as 'long long'. Because we can't use NSPR's
|
---|
60 | * PR_snprintf in this program, it is difficult to
|
---|
61 | * print a static initializer for PRInt64 (a struct).
|
---|
62 | * So we print nothing. The makefiles that build the
|
---|
63 | * shared libraries will detect the empty output string
|
---|
64 | * of this program and omit the library build time
|
---|
65 | * in PRVersionDescription.
|
---|
66 | */
|
---|
67 | #elif defined(VMS)
|
---|
68 | long long now;
|
---|
69 | struct timeb b;
|
---|
70 | ftime(&b);
|
---|
71 | now = b.time;
|
---|
72 | now *= 1000000;
|
---|
73 | now += (1000 * b.millitm);
|
---|
74 | fprintf(stdout, "%Ld", now);
|
---|
75 | #elif defined(XP_UNIX) || defined(XP_OS2_EMX) || defined(XP_BEOS)
|
---|
76 | long long now;
|
---|
77 | struct timeval tv;
|
---|
78 | #ifdef HAVE_SVID_GETTOD
|
---|
79 | gettimeofday(&tv);
|
---|
80 | #else
|
---|
81 | gettimeofday(&tv, NULL);
|
---|
82 | #endif
|
---|
83 | now = ((1000000LL) * tv.tv_sec) + (long long)tv.tv_usec;
|
---|
84 | #if defined(OSF1)
|
---|
85 | fprintf(stdout, "%ld", now);
|
---|
86 | #elif defined(BEOS) && defined(__POWERPC__)
|
---|
87 | fprintf(stdout, "%Ld", now); /* Metroworks on BeOS PPC */
|
---|
88 | #else
|
---|
89 | fprintf(stdout, "%lld", now);
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #elif defined(WIN32)
|
---|
93 | __int64 now;
|
---|
94 | FILETIME ft;
|
---|
95 | GetSystemTimeAsFileTime(&ft);
|
---|
96 | CopyMemory(&now, &ft, sizeof(now));
|
---|
97 | /*
|
---|
98 | * 116444736000000000 is the number of 100-nanosecond intervals
|
---|
99 | * between Jan. 1, 1601 and Jan. 1, 1970.
|
---|
100 | */
|
---|
101 | #ifdef __GNUC__
|
---|
102 | now = (now - 116444736000000000LL) / 10LL;
|
---|
103 | fprintf(stdout, "%lld", now);
|
---|
104 | #else
|
---|
105 | now = (now - 116444736000000000i64) / 10i64;
|
---|
106 | fprintf(stdout, "%I64d", now);
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | #elif defined(XP_OS2_VACPP)
|
---|
110 | /* no long long or i64 so we use a string */
|
---|
111 | #include <string.h>
|
---|
112 | char buf[24];
|
---|
113 | char tbuf[7];
|
---|
114 | time_t now;
|
---|
115 | long mtime;
|
---|
116 | int i;
|
---|
117 |
|
---|
118 | struct timeb b;
|
---|
119 | ftime(&b);
|
---|
120 | now = b.time;
|
---|
121 | _ltoa(now, buf, 10);
|
---|
122 |
|
---|
123 | mtime = b.millitm * 1000;
|
---|
124 | if (mtime == 0){
|
---|
125 | ++now;
|
---|
126 | strcat(buf, "000000");
|
---|
127 | } else {
|
---|
128 | _ltoa(mtime, tbuf, 10);
|
---|
129 | for (i = strlen(tbuf); i < 6; ++i)
|
---|
130 | strcat(buf, "0");
|
---|
131 | strcat(buf, tbuf);
|
---|
132 | }
|
---|
133 | fprintf(stdout, "%s", buf);
|
---|
134 |
|
---|
135 | #else
|
---|
136 | #error "Architecture not supported"
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | return 0;
|
---|
140 | } /* main */
|
---|
141 |
|
---|
142 | /* now.c */
|
---|