1 /** @file
2 
3   Some small general interest definitions
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "tscore/ink_config.h"
27 #include <stddef.h> // NOLINT(modernize-deprecated-headers)
28 #include <sys/mman.h>
29 
30 #ifdef HAVE_STDINT_H
31 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
32 #else
33 // TODO: Add "standard" int types?
34 #endif
35 
36 #ifdef HAVE_INTTYPES_H
37 #include <inttypes.h> // NOLINT(modernize-deprecated-headers)
38 #else
39 // TODO: add PRI*64 stuff?
40 #endif
41 
42 #ifndef INT64_MIN
43 #define INT64_MAX (9223372036854775807LL)
44 #define INT64_MIN (-INT64_MAX - 1LL)
45 #define INT32_MAX (2147483647)
46 #define INT32_MIN (-2147483647 - 1)
47 #endif
48 
49 #define POSIX_THREAD
50 #define POSIX_THREAD_10031c
51 
52 #ifndef ETIME
53 #ifdef ETIMEDOUT
54 #define ETIME ETIMEDOUT
55 #endif
56 #endif
57 
58 #ifndef ENOTSUP
59 #ifdef EOPNOTSUPP
60 #define ENOTSUP EOPNOTSUPP
61 #endif
62 #endif
63 
64 #if defined(darwin)
65 #define RENTRENT_GETHOSTBYNAME
66 #define RENTRENT_GETHOSTBYADDR
67 #endif
68 
69 #define NUL '\0'
70 
71 // Determine the element count for an array.
72 #ifdef __cplusplus
73 template <typename T, unsigned N>
74 static inline unsigned
countof(const T (&)[N])75 countof(const T (&)[N])
76 {
77   return N;
78 }
79 #else
80 #define countof(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
81 #endif
82 
83 #define SOCKOPT_ON ((char *)&on)
84 #define SOCKOPT_OFF ((char *)&off)
85 
86 #ifndef ABS
87 #define ABS(x) (((x) < 0) ? (-(x)) : (x))
88 #endif
89 
90 #define ATS_UNUSED __attribute__((unused))
91 #define ATS_WARN_IF_UNUSED __attribute__((warn_unused_result))
92 #define ATS_UNUSED_RETURN(x) \
93   if (x) {                   \
94   }
95 
96 #ifndef likely
97 #define likely(x) __builtin_expect(!!(x), 1)
98 #endif
99 #ifndef unlikely
100 #define unlikely(x) __builtin_expect(!!(x), 0)
101 #endif
102 
103 #if TS_USE_HWLOC
104 #include <hwloc.h>
105 #endif
106 
107 #ifndef ROUNDUP
108 #define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
109 #endif
110 
111 #if defined(MAP_NORESERVE)
112 #define MAP_SHARED_MAP_NORESERVE (MAP_SHARED | MAP_NORESERVE)
113 #else
114 #define MAP_SHARED_MAP_NORESERVE (MAP_SHARED)
115 #endif
116 
117 /* Variables
118  */
119 extern int debug_level;
120 extern int off;
121 extern int on;
122 
123 /* Functions
124  */
125 int ink_sys_name_release(char *name, int namelen, char *release, int releaselen);
126 int ink_number_of_processors();
127 int ink_login_name_max();
128 
129 #if TS_USE_HWLOC
130 // Get the hardware topology
131 hwloc_topology_t ink_get_topology();
132 #endif
133