Debian Codegraph @

c/tools/include/pncompat/misc_funcs.inc

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20
21 /*
22 * This file provides the functions for "misc_defs.h" in the form of
23 * included code, as opposed to a separate library or object
24 * dependency. In the absence of portable "pragma weak" compiler
25 * directives, this provides a simple workaround.
26 *
27 * Usage for a single compilation unit:
28 *
29 * #include "pncompat/misc_funcs.inc"
30 *
31 * Usage for multiple combined compilation units: chose one to include
32 * "pncompat/misc_funcs.inc" as above and in each other unit needing the
33 * definitions use
34 *
35 * #include "pncompat/misc_defs.h"
36 *
37 */
38
39 #include "misc_defs.h"
40
41 #if defined(_WIN32) && ! defined(__CYGWIN__)
42 #include "pncompat/internal/getopt.c"
43 #endif
44
45 #if defined(_WIN32) && ! defined(__CYGWIN__)
46 #include <windows.h>
47 pn_timestamp_t time_now(void)
48 {
49 FILETIME now;
50 ULARGE_INTEGER t;
51 GetSystemTimeAsFileTime(&now);
52 t.u.HighPart = now.dwHighDateTime;
53 t.u.LowPart = now.dwLowDateTime;
54 // Convert to milliseconds and adjust base epoch
55 return t.QuadPart / 10000 - 11644473600000;
56 }
57 #else
58 #include <sys/time.h>
59 #include <stddef.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 pn_timestamp_t time_now(void)
63 {
64 struct timeval now;
65 if (gettimeofday(&now, NULL)) {fprintf(stderr, "gettimeofday failed\n"); abort();}
66 return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
67 }
68 #endif