1 /*
2  * Copyright (C) 2005-2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _LIBS_LOG_LOG_TIME_H
18 #define _LIBS_LOG_LOG_TIME_H
19 
20 #include <stdint.h>
21 
22 /* struct log_time is a wire-format variant of struct timespec */
23 #ifndef NS_PER_SEC
24 #define NS_PER_SEC 1000000000ULL
25 #endif
26 #ifndef US_PER_SEC
27 #define US_PER_SEC 1000000ULL
28 #endif
29 #ifndef MS_PER_SEC
30 #define MS_PER_SEC 1000ULL
31 #endif
32 
33 #ifndef __struct_log_time_defined
34 #define __struct_log_time_defined
35 
36 #define LOG_TIME_SEC(t) ((t)->tv_sec)
37 /* next power of two after NS_PER_SEC */
38 #define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2))
39 
40 typedef struct log_time {
41   uint32_t tv_sec;
42   uint32_t tv_nsec;
43 } __attribute__((__packed__)) log_time;
44 
45 #endif
46 
47 #endif /* _LIBS_LOG_LOG_TIME_H */
48