3 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_
4 #define INCLUDE_NN_NLIB_PLATFORM_H_
7 # error Sorry, ILP64 not supported
11 #define NLIB_VERSION_YEAR 2015
12 #define NLIB_VERSION_YEAR_SHORT 15
13 #define NLIB_VERSION_DATE 0908
14 #define NLIB_VERSION 20150908
17 # ifndef __STDC_LIMIT_MACROS
19 # pragma message(__FILE__ ": __STDC_LIMIT_MACROS not defined, compile may fail")
20 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE)
21 # warning __STDC_LIMIT_MACROS not defined, compile may fail
23 # define __STDC_LIMIT_MACROS
25 # ifndef __STDC_CONSTANT_MACROS
27 # pragma message(__FILE__ ": __STDC_CONSTANT_MACROS not defined, compile may fail")
28 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE)
29 # warning __STDC_CONSTANT_MACROS not defined, compile may fail
31 # define __STDC_CONSTANT_MACROS
33 # ifndef __STDC_FORMAT_MACROS
35 # pragma message(__FILE__ ": __STDC_FORMAT_MACROS not defined, compile may fail")
36 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE)
37 # warning __STDC_FORMAT_MACROS not defined, compile may fail
39 # define __STDC_FORMAT_MACROS
48 #if defined(NLIB_RENAME_CAPI) && !defined(_MSC_VER)
50 # define NLIB_CAPI(x) mypfx##x
53 #define nlib_error_string NLIB_CAPI(nlib_error_string)
54 #define nlib_get_native_last_error NLIB_CAPI(nlib_get_native_last_error)
55 #define nlib_getversion NLIB_CAPI(nlib_getversion)
56 #define nlib_epochtime NLIB_CAPI(nlib_epochtime)
57 #define nlib_ticktime NLIB_CAPI(nlib_ticktime)
58 #define nlib_sleep NLIB_CAPI(nlib_sleep)
59 #define nlib_gen_random NLIB_CAPI(nlib_gen_random)
60 #define nlib_mempagesize NLIB_CAPI(nlib_mempagesize)
61 #define nlib_virtual_alloc NLIB_CAPI(nlib_virtual_alloc)
62 #define nlib_virtual_free NLIB_CAPI(nlib_virtual_free)
63 #define nlib_physical_alloc NLIB_CAPI(nlib_physical_alloc)
64 #define nlib_physical_free NLIB_CAPI(nlib_physical_free)
65 #define nlib_mlock NLIB_CAPI(nlib_mlock)
66 #define nlib_munlock NLIB_CAPI(nlib_munlock)
67 #define nlib_tls_alloc NLIB_CAPI(nlib_tls_alloc)
68 #define nlib_tls_free NLIB_CAPI(nlib_tls_free)
69 #define nlib_tls_setvalue NLIB_CAPI(nlib_tls_setvalue)
70 #define nlib_tls_getvalue NLIB_CAPI(nlib_tls_getvalue)
71 #define nlib_mutex_init NLIB_CAPI(nlib_mutex_init)
72 #define nlib_mutex_recursive_init NLIB_CAPI(nlib_mutex_recursive_init)
73 #define nlib_mutex_recursive_timed_init NLIB_CAPI(nlib_mutex_recursive_timed_init)
74 #define nlib_mutex_lock NLIB_CAPI(nlib_mutex_lock)
75 #define nlib_mutex_trylock NLIB_CAPI(nlib_mutex_trylock)
76 #define nlib_mutex_trylock_for NLIB_CAPI(nlib_mutex_trylock_for)
77 #define nlib_mutex_unlock NLIB_CAPI(nlib_mutex_unlock)
78 #define nlib_mutex_destroy NLIB_CAPI(nlib_mutex_destroy)
79 #define nlib_semaphore_init NLIB_CAPI(nlib_semaphore_init)
80 #define nlib_semaphore_wait NLIB_CAPI(nlib_semaphore_wait)
81 #define nlib_semaphore_trywait NLIB_CAPI(nlib_semaphore_trywait)
82 #define nlib_semaphore_trywait_for NLIB_CAPI(nlib_semaphore_trywait_for)
83 #define nlib_semaphore_post NLIB_CAPI(nlib_semaphore_post)
84 #define nlib_semaphore_post_ex NLIB_CAPI(nlib_semaphore_post_ex)
85 #define nlib_semaphore_destroy NLIB_CAPI(nlib_semaphore_destroy)
86 #define nlib_cond_init NLIB_CAPI(nlib_cond_init)
87 #define nlib_cond_signal NLIB_CAPI(nlib_cond_signal)
88 #define nlib_cond_broadcast NLIB_CAPI(nlib_cond_broadcast)
89 #define nlib_cond_wait NLIB_CAPI(nlib_cond_wait)
90 #define nlib_cond_wait_for NLIB_CAPI(nlib_cond_wait_for)
91 #define nlib_cond_wait_until NLIB_CAPI(nlib_cond_wait_until)
92 #define nlib_cond_destroy NLIB_CAPI(nlib_cond_destroy)
93 #define nlib_rwlock_init NLIB_CAPI(nlib_rwlock_init)
94 #define nlib_rwlock_destroy NLIB_CAPI(nlib_rwlock_destroy)
95 #define nlib_rwlock_rdlock NLIB_CAPI(nlib_rwlock_rdlock)
96 #define nlib_rwlock_tryrdlock NLIB_CAPI(nlib_rwlock_tryrdlock)
97 #define nlib_rwlock_tryrdlock_for NLIB_CAPI(nlib_rwlock_tryrdlock_for)
98 #define nlib_rwlock_tryrdlock_until NLIB_CAPI(nlib_rwlock_tryrdlock_until)
99 #define nlib_rwlock_rdunlock NLIB_CAPI(nlib_rwlock_rdunlock)
100 #define nlib_rwlock_wrlock NLIB_CAPI(nlib_rwlock_wrlock)
101 #define nlib_rwlock_trywrlock NLIB_CAPI(nlib_rwlock_trywrlock)
102 #define nlib_rwlock_trywrlock_for NLIB_CAPI(nlib_rwlock_trywrlock_for)
103 #define nlib_rwlock_trywrlock_until NLIB_CAPI(nlib_rwlock_trywrlock_until)
104 #define nlib_rwlock_wrunlock NLIB_CAPI(nlib_rwlock_wrunlock)
105 #define nlib_condrwlock_init NLIB_CAPI(nlib_condrwlock_init)
106 #define nlib_condrwlock_destroy NLIB_CAPI(nlib_condrwlock_destroy)
107 #define nlib_condrwlock_signal NLIB_CAPI(nlib_condrwlock_signal)
108 #define nlib_condrwlock_broadcast NLIB_CAPI(nlib_condrwlock_broadcast)
109 #define nlib_condrwlock_wait NLIB_CAPI(nlib_condrwlock_wait)
110 #define nlib_condrwlock_wait_for NLIB_CAPI(nlib_condrwlock_wait_for)
111 #define nlib_condrwlock_wait_until NLIB_CAPI(nlib_condrwlock_wait_until)
112 #define nlib_barrier_init NLIB_CAPI(nlib_barrier_init)
113 #define nlib_barrier_destroy NLIB_CAPI(nlib_barrier_destroy)
114 #define nlib_barrier_wait NLIB_CAPI(nlib_barrier_wait)
115 #define nlib_once NLIB_CAPI(nlib_once)
116 #define nlib_tryonce NLIB_CAPI(nlib_tryonce)
117 #define nlib_mq_open NLIB_CAPI(nlib_mq_open)
118 #define nlib_mq_getattr NLIB_CAPI(nlib_mq_getattr)
119 #define nlib_mq_close NLIB_CAPI(nlib_mq_close)
120 #define nlib_mq_readonly NLIB_CAPI(nlib_mq_readonly)
121 #define nlib_mq_send NLIB_CAPI(nlib_mq_send)
122 #define nlib_mq_send_until NLIB_CAPI(nlib_mq_send_until)
123 #define nlib_mq_receive NLIB_CAPI(nlib_mq_receive)
124 #define nlib_mq_receive_until NLIB_CAPI(nlib_mq_receive_until)
125 #define nlib_mq_drop NLIB_CAPI(nlib_mq_drop)
126 #define nlib_yield NLIB_CAPI(nlib_yield)
127 #define nlib_thread_create NLIB_CAPI(nlib_thread_create)
128 #define nlib_thread_join NLIB_CAPI(nlib_thread_join)
129 #define nlib_thread_detach NLIB_CAPI(nlib_thread_detach)
130 #define nlib_thread_self NLIB_CAPI(nlib_thread_self)
131 #define nlib_thread_getconcurrency NLIB_CAPI(nlib_thread_getconcurrency)
132 #define nlib_thread_getid NLIB_CAPI(nlib_thread_getid)
133 #define nlib_thread_equal NLIB_CAPI(nlib_thread_equal)
134 #define nlib_thread_getcpu NLIB_CAPI(nlib_thread_getcpu)
135 #define nlib_thread_setaffinity NLIB_CAPI(nlib_thread_setaffinity)
136 #define nlib_thread_setname NLIB_CAPI(nlib_thread_setname)
137 #define nlib_thread_attr_init NLIB_CAPI(nlib_thread_attr_init)
138 #define nlib_thread_attr_setint NLIB_CAPI(nlib_thread_attr_setint)
139 #define nlib_thread_attr_getint NLIB_CAPI(nlib_thread_attr_getint)
140 #define nlib_thread_attr_setptr NLIB_CAPI(nlib_thread_attr_setptr)
141 #define nlib_thread_attr_getptr NLIB_CAPI(nlib_thread_attr_getptr)
142 #define nlib_thread_attr_setstack NLIB_CAPI(nlib_thread_attr_setstack)
143 #define nlib_thread_attr_getstack NLIB_CAPI(nlib_thread_attr_getstack)
144 #define nlib_thread_attr_destroy NLIB_CAPI(nlib_thread_attr_destroy)
145 #define nlib_thread_getpriority NLIB_CAPI(nlib_thread_getpriority)
146 #define nlib_thread_setpriority NLIB_CAPI(nlib_thread_setpriority)
147 #define nlib_thread_priority_min NLIB_CAPI(nlib_thread_priority_min)
148 #define nlib_thread_priority_max NLIB_CAPI(nlib_thread_priority_max)
149 #define nlib_thread_priority_default NLIB_CAPI(nlib_thread_priority_default)
150 #define nlib_thread_exit NLIB_CAPI(nlib_thread_exit)
151 #define nlib_thread_cleanup_push_ NLIB_CAPI(nlib_thread_cleanup_push_)
152 #define nlib_thread_cleanup_pop_ NLIB_CAPI(nlib_thread_cleanup_pop_)
153 #define nlib_write_stdout NLIB_CAPI(nlib_write_stdout)
154 #define nlib_write_stderr NLIB_CAPI(nlib_write_stderr)
155 #define nlib_debug_break NLIB_CAPI(nlib_debug_break)
156 #define nlib_debug_backtrace NLIB_CAPI(nlib_debug_backtrace)
157 #define nlib_debug_backtrace_gettext NLIB_CAPI(nlib_debug_backtrace_gettext)
158 #define nlib_getenv NLIB_CAPI(nlib_getenv)
159 #define nlib_log_print NLIB_CAPI(nlib_log_print)
160 #define nlib_log_vprint NLIB_CAPI(nlib_log_vprint)
161 #define nlib_log_attr_setint NLIB_CAPI(nlib_log_attr_setint)
162 #define nlib_fd_open NLIB_CAPI(nlib_fd_open)
163 #define nlib_fd_close NLIB_CAPI(nlib_fd_close)
164 #define nlib_fd_read NLIB_CAPI(nlib_fd_read)
165 #define nlib_fd_write NLIB_CAPI(nlib_fd_write)
166 #define nlib_fd_seek NLIB_CAPI(nlib_fd_seek)
167 #define nlib_fd_pread NLIB_CAPI(nlib_fd_pread)
168 #define nlib_fd_pwrite NLIB_CAPI(nlib_fd_pwrite)
169 #define nlib_fd_truncate NLIB_CAPI(nlib_fd_truncate)
170 #define nlib_fd_getsize NLIB_CAPI(nlib_fd_getsize)
171 #define nlib_fd_flush NLIB_CAPI(nlib_fd_flush)
172 #define nlib_fd_sync NLIB_CAPI(nlib_fd_sync)
173 #define nlib_fd_native_handle NLIB_CAPI(nlib_fd_native_handle)
174 #define nlib_fd_readv NLIB_CAPI(nlib_fd_readv)
175 #define nlib_fd_writev NLIB_CAPI(nlib_fd_writev)
176 #define nlib_fd_preadv NLIB_CAPI(nlib_fd_preadv)
177 #define nlib_fd_pwritev NLIB_CAPI(nlib_fd_pwritev)
178 #define nlib_unlink NLIB_CAPI(nlib_unlink)
179 #define nlib_mkdir NLIB_CAPI(nlib_mkdir)
180 #define nlib_rmdir NLIB_CAPI(nlib_rmdir)
181 #define nlib_rename NLIB_CAPI(nlib_rename)
182 #define nlib_dir_open NLIB_CAPI(nlib_dir_open)
183 #define nlib_dir_close NLIB_CAPI(nlib_dir_close)
184 #define nlib_dir_read NLIB_CAPI(nlib_dir_read)
185 #define nlib_is_dir NLIB_CAPI(nlib_is_dir)
186 #define nlib_exist_path NLIB_CAPI(nlib_exist_path)
187 #define nlib_disk_freespace NLIB_CAPI(nlib_disk_freespace)
188 #define nlib_spinlock_lock_ NLIB_CAPI(nlib_spinlock_lock_)
189 #define nlib_spinlock_unlock_ NLIB_CAPI(nlib_spinlock_unlock_)
190 #define nlib_vsnprintf NLIB_CAPI(nlib_vsnprintf)
191 #define nlib_snprintf NLIB_CAPI(nlib_snprintf)
192 #define nlib_vdprintf NLIB_CAPI(nlib_vdprintf)
193 #define nlib_dprintf NLIB_CAPI(nlib_dprintf)
194 #define nlib_printf NLIB_CAPI(nlib_printf)
195 #define nlib_vsnwprintf NLIB_CAPI(nlib_vsnwprintf)
196 #define nlib_snwprintf NLIB_CAPI(nlib_snwprintf)
197 #define nlib_vdwprintf NLIB_CAPI(nlib_vdwprintf)
198 #define nlib_dwprintf NLIB_CAPI(nlib_dwprintf)
199 #define nlib_wprintf NLIB_CAPI(nlib_wprintf)
200 #define nlib_vsnprintf_fallback NLIB_CAPI(nlib_vsnprintf_fallback)
201 #define nlib_snprintf_fallback NLIB_CAPI(nlib_snprintf_fallback)
202 #define nlib_vsnwprintf_fallback NLIB_CAPI(nlib_vsnwprintf_fallback)
203 #define nlib_snwprintf_fallback NLIB_CAPI(nlib_snwprintf_fallback)
204 #define nlib_memcmp NLIB_CAPI(nlib_memcmp)
205 #define nlib_memchr NLIB_CAPI(nlib_memchr)
206 #define nlib_memrchr NLIB_CAPI(nlib_memrchr)
207 #define nlib_memchr_not NLIB_CAPI(nlib_memchr_not)
208 #define nlib_memchr_range_not NLIB_CAPI(nlib_memchr_range_not)
209 #define nlib_memchr_lt NLIB_CAPI(nlib_memchr_lt)
210 #define nlib_memchr_gt NLIB_CAPI(nlib_memchr_gt)
211 #define nlib_memchr_mb NLIB_CAPI(nlib_memchr_mb)
212 #define nlib_memchr_set NLIB_CAPI(nlib_memchr_set)
213 #define nlib_memchr_set_not NLIB_CAPI(nlib_memchr_set_not)
214 #define nlib_skipws NLIB_CAPI(nlib_skipws)
215 #define nlib_strlen NLIB_CAPI(nlib_strlen)
216 #define nlib_strnlen NLIB_CAPI(nlib_strnlen)
217 #define nlib_strcpy NLIB_CAPI(nlib_strcpy)
218 #define nlib_strncpy NLIB_CAPI(nlib_strncpy)
219 #define nlib_strchr NLIB_CAPI(nlib_strchr)
220 #define nlib_strrchr NLIB_CAPI(nlib_strrchr)
221 #define nlib_strchr_mb NLIB_CAPI(nlib_strchr_mb)
222 #define nlib_wcslen NLIB_CAPI(nlib_wcslen)
223 #define nlib_wcsnlen NLIB_CAPI(nlib_wcsnlen)
224 #define nlib_wcscpy NLIB_CAPI(nlib_wcscpy)
225 #define nlib_wcsncpy NLIB_CAPI(nlib_wcsncpy)
226 #define nlib_strcat NLIB_CAPI(nlib_strcat)
227 #define nlib_strncat NLIB_CAPI(nlib_strncat)
228 #define nlib_wcscat NLIB_CAPI(nlib_wcscat)
229 #define nlib_wcsncat NLIB_CAPI(nlib_wcsncat)
230 #define nlib_wide_to_utf8 NLIB_CAPI(nlib_wide_to_utf8)
231 #define nlib_utf8_to_wide NLIB_CAPI(nlib_utf8_to_wide)
232 #define nlib_strcplen NLIB_CAPI(nlib_strcplen)
233 #define nlib_strcplen_ex NLIB_CAPI(nlib_strcplen_ex)
234 #define nlib_wcscplen NLIB_CAPI(nlib_wcscplen)
235 #define nlib_swapendian_16 NLIB_CAPI(nlib_swapendian_16)
236 #define nlib_swapendian_32 NLIB_CAPI(nlib_swapendian_32)
237 #define nlib_swapendian_64 NLIB_CAPI(nlib_swapendian_64)
238 #define nlib_malloc NLIB_CAPI(nlib_malloc)
239 #define nlib_free NLIB_CAPI(nlib_free)
240 #define nlib_calloc NLIB_CAPI(nlib_calloc)
241 #define nlib_realloc NLIB_CAPI(nlib_realloc)
242 #define nlib_free_size NLIB_CAPI(nlib_free_size)
243 #define nlib_memalign NLIB_CAPI(nlib_memalign)
244 #define nlib_popcnt NLIB_CAPI(nlib_popcnt)
245 #define nlib_popcnt64 NLIB_CAPI(nlib_popcnt64)
246 #define nlib_popcnt16 NLIB_CAPI(nlib_popcnt16)
249 #if defined(_MSC_VER)
250 # include "nn/nlib/Platform_win32.h"
251 #elif defined(__linux__) || \
252 defined(__FreeBSD__) || \
253 defined(__CYGWIN__) || \
254 (defined(__APPLE__) && defined(__MACH__))
258 # include "nn/nlib/Platform_unix.h"
259 #elif defined(NN_PLATFORM_CTR)
260 # include "nn/nlib/Platform_ctr.h"
262 # ifndef NLIB_CAFE_PPC
263 # define NLIB_CAFE_PPC
265 # include "nn/nlib/Platform_cafe.h"
268 #if defined(__ARM_NEON__) || defined(__aarch64__)
280 #if defined(NLIB_SSE41) || defined(NLIB_NEON)
283 # include <arm_neon.h>
287 # include <nmmintrin.h>
295 # define RSIZE_MAX 0x7FFFFFFFL
297 # define RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL
302 # define NLIB_WARN(exp) ("WARNING: " exp)
312 #ifndef __PRIS_PREFIX
313 # define __PRIS_PREFIX "z"
317 # define PRIdS __PRIS_PREFIX "d"
321 # define PRIxS __PRIS_PREFIX "x"
325 # define PRIuS __PRIS_PREFIX "u"
329 # define PRIXS __PRIS_PREFIX "X"
333 # define PRIoS __PRIS_PREFIX "o"
336 #ifndef NLIB_LOCKABLE
337 # define NLIB_LOCKABLE
340 #ifndef NLIB_LOCK_FUNC
341 # define NLIB_LOCK_FUNC(...)
344 #ifndef NLIB_SHARED_LOCK_FUNC
345 # define NLIB_SHARED_LOCK_FUNC(...)
348 #ifndef NLIB_SHARED_TRYLOCK_FUNC
349 # define NLIB_SHARED_TRYLOCK_FUNC(...)
352 #ifndef NLIB_UNLOCK_FUNC
353 # define NLIB_UNLOCK_FUNC(...)
356 #ifndef NLIB_SHARED_UNLOCK_FUNC
357 # define NLIB_SHARED_UNLOCK_FUNC(...)
360 #ifndef NLIB_TRYLOCK_FUNC
361 # define NLIB_TRYLOCK_FUNC(...)
364 #ifndef NLIB_GUARDED_BY
365 # define NLIB_GUARDED_BY(x)
368 #ifndef NLIB_PT_GUARDED_BY
369 # define NLIB_PT_GUARDED_BY(x)
372 #ifndef NLIB_LOCK_REQUIRED
373 # define NLIB_LOCK_REQUIRED(...)
376 #ifndef NLIB_LOCK_EXCLUDED
377 # define NLIB_LOCK_EXCLUDED(...)
380 #ifndef NLIB_SHARED_LOCK_REQUIRED
381 # define NLIB_SHARED_LOCK_REQUIRED(...)
384 #ifndef NLIB_SCOPED_LOCKABLE
385 # define NLIB_SCOPED_LOCKABLE
388 #ifndef NLIB_NO_THREAD_SAFETY_ANALYSIS
389 # define NLIB_NO_THREAD_SAFETY_ANALYSIS
393 # define NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else __builtin_unreachable()
396 #ifdef NLIB_NONNULL_ENABLED
397 # define NLIB_EINVAL_IFNULL(p)
399 # define NLIB_EINVAL_IFNULL(p) if (!p) return EINVAL
410 #ifdef NLIB_HAS_STDHEADER_STDINT
414 #ifdef NLIB_HAS_STDHEADER_INTTYPES
415 # include <inttypes.h>
418 #if defined(__LP64__) && __LP64__ == 1
428 #ifndef NLIB_VIS_PUBLIC_ALT
429 #define NLIB_VIS_PUBLIC_ALT NLIB_VIS_PUBLIC
453 #if defined(__INTELLISENSE__)
454 #define NLIB_ATOMIC_RELAXED (0)
455 #define NLIB_ATOMIC_ACQUIRE (1)
456 #define NLIB_ATOMIC_RELEASE (2)
457 #define NLIB_ATOMIC_ACQ_REL (3)
458 #define NLIB_ATOMIC_SEQ_CST (7)
466 int32_t desired,
int weak,
467 int success_memorder,
int failure_memorder);
495 int64_t desired,
int weak,
496 int success_memorder,
int failure_memorder);
522 void* desired,
int weak,
523 int success_memorder,
int failure_memorder);
562 #define NLIB_PHYSICAL_ALLOC_PROT_NONE 0
563 #define NLIB_PHYSICAL_ALLOC_PROT_READ 1
564 #define NLIB_PHYSICAL_ALLOC_PROT_WRITE 2
565 #define NLIB_PHYSICAL_ALLOC_PROT_EXEC 4
683 #ifndef NLIB_RWLOCK_HAS_NATIVE
684 struct nlib_rwlock_ {
691 #define NLIB_RWLOCK_INITIALIZER { \
693 { NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER, NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER }, \
694 NLIB_COND_INITIALIZER }
716 #if defined(_MSC_VER) && defined(NLIB_RWLOCK_HAS_NATIVE)
717 typedef struct nlib_condrwlock_ {
718 CONDITION_VARIABLE cond;
720 #define NLIB_CONDRWLOCK_INITIALIZER { CONDITION_VARIABLE_INIT }
722 typedef struct nlib_condrwlock_ {
726 #define NLIB_CONDRWLOCK_INITIALIZER { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER }
738 nlib_duration duration,
748 #ifndef NLIB_BARRIER_HAS_NATIVE
749 struct nlib_barrier_ {
764 struct nlib_onceflag_ {
768 #define NLIB_ONCE_INIT { 0 }
785 typedef struct nlib_mq_ {
791 #define NLIB_MQ_BLOCK 0
792 #define NLIB_MQ_NONBLOCK 1
793 #define NLIB_MQ_LOCKFREE 2
804 typedef struct nlib_mq_attr_ {
820 int prio, nlib_time abstime);
834 #define NLIB_THREAD_INVALID (nlib_thread)(0) // NOLINT
836 #ifndef NLIB_SPINLOCK_HAS_NATIVE
840 #ifndef NLIB_THREAD_ATTR_HAS_NATIVE
841 struct nlib_thread_attr_ {
851 struct nlib_thread_attr_ {
896 void* __restrict stack_addr,
899 void** __restrict stack_addr,
903 #define NLIB_THREAD_ATTR_KEY_DETACHSTATE (1)
904 #define NLIB_THREAD_ATTR_KEY_STACKSIZE (2)
905 #define NLIB_THREAD_ATTR_KEY_PRIORITY (4)
906 #define NLIB_THREAD_ATTR_KEY_AFFINITY (5)
914 #ifndef NN_PLATFORM_CTR
922 #elif defined(pthread_cleanup_push)
923 # define nlib_thread_cleanup_push(fn, arg) pthread_cleanup_push(fn, arg)
924 # define nlib_thread_cleanup_pop(exec) pthread_cleanup_pop(exec)
925 #elif !defined(NN_PLATFORM_CTR)
926 struct nlib_thread_cleanup_handler_ {
929 struct nlib_thread_cleanup_handler_* next;
931 #define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \
932 struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, NULL }; \
933 nlib_thread_cleanup_push_(&_thread_cleanup_handler)
934 #define nlib_thread_cleanup_pop(exec) nlib_thread_cleanup_pop_(exec); }
936 NLIB_VIS_PUBLIC void nlib_thread_cleanup_push_(
struct nlib_thread_cleanup_handler_* handler);
954 void*
const* __restrict buf,
960 NLIB_LOG_UNKNOWN = 0,
974 typedef enum nlib_log_key {
975 NLIB_LOG_ATTR_UNKNOWN = 0,
976 NLIB_LOG_ATTR_STDOUT,
977 NLIB_LOG_ATTR_STDERR,
978 NLIB_LOG_ATTR_MSVC_TRACE,
979 NLIB_LOG_ATTR_SYSLOG,
980 NLIB_LOG_ATTR_NLIB_FD,
984 #ifndef NLIB_ATTRIBUTE_PRINTF
985 # define NLIB_ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y)))
989 const char* __restrict fmt, ...)
990 NLIB_ATTRIBUTE_PRINTF(3, 4) NLIB_NONNULL;
992 const
char* __restrict fmt, va_list ap) NLIB_NONNULL;
1000 # define NLIB_FD_O_RDONLY O_RDONLY
1002 # define NLIB_FD_O_RDONLY (0x0000)
1006 # define NLIB_FD_O_WRONLY O_WRONLY
1008 # define NLIB_FD_O_WRONLY (0x0001)
1012 # define NLIB_FD_O_RDWR O_RDWR
1014 # define NLIB_FD_O_RDWR (0x0002)
1018 # define NLIB_FD_O_CREAT O_CREAT
1020 # define NLIB_FD_O_CREAT (0x0100)
1024 # define NLIB_FD_O_TRUNC O_TRUNC
1026 # define NLIB_FD_O_TRUNC (0x0800)
1030 # define NLIB_FD_O_APPEND O_APPEND
1032 # define NLIB_FD_O_APPEND (0x0008)
1036 # define NLIB_SEEK_SET SEEK_SET
1038 # define NLIB_SEEK_SET 0
1042 # define NLIB_SEEK_CUR SEEK_CUR
1044 # define NLIB_SEEK_CUR 1
1052 #define NLIB_FD_INVALID (-1)
1055 nlib_fd* fd,
const char* native_path,
unsigned int flags,
const void* extra)
1059 size_t* __restrict result, nlib_fd fd,
void* __restrict buf,
size_t count)
NLIB_NONNULL;
1061 size_t* __restrict result, nlib_fd fd,
const void* __restrict buf,
size_t count)
NLIB_NONNULL;
1063 nlib_offset* result, nlib_fd fd, nlib_offset offset,
int whence)
NLIB_NONNULL;
1065 void* __restrict buf,
size_t count,
1068 const void* __restrict buf,
1069 size_t count, nlib_offset offset)
1082 struct nlib_fd_iovec_ {
1086 typedef struct nlib_fd_iovec_ nlib_fd_iovec;
1088 const nlib_fd_iovec* __restrict iov,
1091 const nlib_fd_iovec* __restrict iov,
1094 const nlib_fd_iovec* __restrict iov,
1098 const nlib_fd_iovec* __restrict iov,
1108 const char* __restrict new_path)
1114 typedef struct nlib_dir_ nlib_dir;
1115 typedef struct nlib_dirent_ {
1120 const char* __restrict native_path)
1136 uint64_t* __restrict free_bytes_available,
1137 uint64_t* __restrict total_bytes,
1143 #if defined(_MSC_VER) || defined(NLIB_UNIX)
1144 #define NLIB_SOCKET_ENABLED
1147 # define NLIB_AF_INET AF_INET
1151 # define NLIB_AF_INET6 AF_INET6
1155 # define NLIB_SOCK_STREAM SOCK_STREAM
1159 # define NLIB_SOCK_DGRAM SOCK_DGRAM
1163 # define NLIB_SOCK_RAW SOCK_RAW
1167 # define NLIB_SOCK_RDM SOCK_RDM
1172 typedef int nlib_sock;
1173 #define NLIB_SOCKET_INVALID (nlib_sock)(-1) // NOLINT
1177 typedef struct sockaddr nlib_sockaddr;
1178 typedef struct sockaddr_in nlib_sockaddr_in;
1179 typedef struct sockaddr_in6 nlib_sockaddr_in6;
1183 nlib_sockaddr* __restrict addr,
int* __restrict addrlen);
1186 #ifdef MSG_DONTROUTE
1187 # define NLIB_MSG_DONTROUTE MSG_DONTROUTE
1191 # define NLIB_MSG_OOB MSG_OOB
1195 const void* __restrict buf,
1196 size_t len,
int flags);
1198 const void* __restrict buf,
size_t len,
int flags,
1199 const nlib_sockaddr* __restrict dest_addr,
int addrlen);
1202 # define NLIB_MSG_PEEK MSG_PEEK
1206 # define NLIB_MSG_WAITALL MSG_WAITALL
1210 size_t len,
int flags);
1212 void* __restrict buf,
size_t len,
int flags,
1213 nlib_sockaddr* __restrict dest_addr,
int* __restrict addrlen);
1217 # define SHUT_RD SD_RECEIVE
1218 # define SHUT_WR SD_SEND
1219 # define SHUT_RDWR SD_BOTH
1223 # define NLIB_SHUT_RD SHUT_RD
1227 # define NLIB_SHUT_WR SHUT_WR
1231 # define NLIB_SHUT_RDWR SHUT_RDWR
1241 # define NLIB_INADDR_ANY INADDR_ANY
1244 #ifdef IN6ADDR_ANY_INIT
1245 # define NLIB_IN6ADDR_ANY_INIT IN6ADDR_ANY_INIT
1248 #ifdef INADDR_LOOPBACK
1249 # define NLIB_INADDR_LOOPBACK INADDR_LOOPBACK
1252 #ifdef IN6ADDR_LOOPBACK_INIT
1253 # define NLIB_IN6ADDR_LOOPBACK_INIT IN6ADDR_LOOPBACK_INIT
1256 typedef struct in_addr nlib_in_addr;
1257 typedef struct in6_addr nlib_in6_addr;
1280 typedef int eai_error_t;
1281 typedef struct addrinfo nlib_addrinfo;
1282 NLIB_VIS_PUBLIC eai_error_t nlib_getaddrinfo(
const char* __restrict node,
1283 const char* __restrict service,
1284 const nlib_addrinfo* __restrict hints,
1285 nlib_addrinfo** __restrict res);
1289 # define NLIB_SOL_SOCKET SOL_SOCKET
1293 # define NLIB_IPPROTO_TCP IPPROTO_TCP
1297 # define NLIB_SO_KEEPALIVE SO_KEEPALIVE
1301 # define NLIB_SO_LINGER SO_LINGER
1305 # define NLIB_SO_OOBINLINE SO_OOBINLINE
1309 # define NLIB_SO_RCVBUF SO_RCVBUF
1313 # define NLIB_SO_REUSEADDR SO_REUSEADDR
1317 # define NLIB_SO_RCVTIMEO SO_RCVTIMEO
1321 # define NLIB_SO_SNDBUF SO_SNDBUF
1325 # define NLIB_SO_SNDTIMEO SO_SNDTIMEO
1329 # define NLIB_TCP_NODELAY TCP_NODELAY
1333 void* __restrict optval,
int* __restrict optlen);
1335 const void* optval,
int optlen);
1337 typedef fd_set nlib_fd_set;
1339 nlib_fd_set* __restrict writefds,
1340 nlib_fd_set* __restrict exceptfds, nlib_duration duration);
1342 #define NLIB_FD_CLR FD_CLR
1343 #define NLIB_FD_ISSET FD_ISSET
1344 #define NLIB_FD_SET FD_SET
1345 #define NLIB_FD_ZERO FD_ZERO
1357 # warning Do not define EDQUOT. nlib may not work correctly.
1374 #ifndef NLIB_SKIP_ERRNO_DEFINE
1376 #define NLIB_E_BASE 2000
1390 # define EACCES 9973
1396 # define EADDRINUSE 9902
1401 #ifndef EADDRNOTAVAIL
1402 # define EADDRNOTAVAIL 9903
1407 #ifndef EAFNOSUPPORT
1408 # define EAFNOSUPPORT 9901
1414 # define EAGAIN 9976
1420 # define EALREADY 9907
1432 # define EBADMSG 9905
1444 # define ECANCELED 9927
1450 # define ECHILD 9963
1455 #ifndef ECONNABORTED
1456 # define ECONNABORTED 9906
1461 #ifndef ECONNREFUSED
1462 # define ECONNREFUSED 9908
1468 # define ECONNRESET 9909
1474 # define EDEADLK 9975
1479 #ifndef EDESTADDRREQ
1480 # define EDESTADDRREQ 9910
1492 # define EDQUOT (NLIB_E_BASE + 19)
1498 # define EEXIST 9955
1504 # define EFAULT 9948
1515 #ifndef EHOSTUNREACH
1516 # define EHOSTUNREACH 9911
1528 # define EILSEQ 9945
1534 # define EINPROGRESS 9928
1546 # define EINVAL 9943
1558 # define EISCONN 9904
1564 # define EISDIR 9962
1576 # define EMFILE 9978
1582 # define EMLINK 9979
1588 # define EMSGSIZE 9913
1594 # define EMULTIHOP (NLIB_E_BASE + 36)
1599 #ifndef ENAMETOOLONG
1600 # define ENAMETOOLONG 9957
1606 # define ENETDOWN 9914
1612 # define ENETRESET 9915
1618 # define ENETUNREACH 9916
1624 # define ENFILE 9977
1630 # define ENOBUFS 9917
1636 # define ENODATA 9919
1642 # define ENODEV 9967
1648 # define ENOENT 9968
1654 # define ENOEXEC 9954
1660 # define ENOLCK 9964
1666 # define ENOLINK 9918
1672 # define ENOMEM 9971
1678 # define ENOMSG 9920
1684 # define ENOPROTOOPT 9921
1690 # define ENOSPC 9965
1702 # define ENOSTR 9924
1708 # define ENOSYS 9942
1714 # define ENOTCONN 9925
1720 # define ENOTDIR 9970
1726 # define ENOTEMPTY 9953
1731 #ifndef ENOTRECOVERABLE
1732 # define ENOTRECOVERABLE 9934
1738 # define ENOTSOCK 9923
1744 # define ENOTSUP 9926
1750 # define ENOTTY 9958
1762 # define EOPNOTSUPP 9929
1768 # define EOVERFLOW 9940
1774 # define EOWNERDEAD 9931
1792 # define EPROTO 9932
1797 #ifndef EPROTONOSUPPORT
1798 # define EPROTONOSUPPORT 9933
1804 # define EPROTOTYPE 9941
1810 # define ERANGE 9944
1822 # define ESPIPE 9960
1834 # define ESTALE (NLIB_E_BASE + 75)
1846 # define ETIMEDOUT 9938
1852 # define ETXTBSY 9936
1858 # define EWOULDBLOCK 9930
1866 #endif // NLIB_SKIP_ERRNO_DEFINE
1871 #ifndef NLIB_SPINLOCK_HAS_NATIVE
1872 #define NLIB_SPINLOCK_INITIALIZER (0)
1874 #ifndef NN_PLATFORM_CTR
1882 int32_t expected = 0;
1885 nlib_spinlock_lock_(lock);
1889 int32_t expected = 0;
1897 #ifdef NN_PLATFORM_CTR
1900 int32_t expected = 1;
1904 nlib_spinlock_unlock_(lock);
1914 _Printf_format_string_
const char* __restrict fmt, va_list args)
NLIB_NONNULL_4;
1916 _Printf_format_string_
const char* __restrict fmt,
1917 ...) NLIB_ATTRIBUTE_PRINTF(4, 5) NLIB_NONNULL_4;
1919 _Printf_format_string_ const
char* __restrict fmt, va_list args) NLIB_NONNULL_3;
1921 _Printf_format_string_ const
char* __restrict fmt,
1922 ...) NLIB_ATTRIBUTE_PRINTF(3, 4) NLIB_NONNULL_3;
1925 _Printf_format_string_ const
char* fmt, ...) NLIB_ATTRIBUTE_PRINTF(1, 2) NLIB_NONNULL_1;
1929 _Printf_format_string_ const
wchar_t* __restrict fmt,
1930 va_list args) NLIB_NONNULL_4;
1932 nlib_snwprintf(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
1933 _Printf_format_string_ const
wchar_t* __restrict fmt, ...) NLIB_NONNULL_4;
1935 _Printf_format_string_ const
wchar_t* __restrict fmt,
1936 va_list args) NLIB_NONNULL_3;
1938 _Printf_format_string_ const
wchar_t* __restrict fmt,
1939 ...) NLIB_NONNULL_3;
1944 _Printf_format_string_ const
char* __restrict fmt,
1945 va_list args) NLIB_NONNULL_4;
1947 nlib_snprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
size_t size,
1948 _Printf_format_string_ const
char* __restrict fmt, ...)
1949 NLIB_ATTRIBUTE_PRINTF(4, 5) NLIB_NONNULL_4;
1951 nlib_vsnwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
1952 _Printf_format_string_ const
wchar_t* __restrict fmt,
1953 va_list args) NLIB_NONNULL_4;
1955 nlib_snwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
1956 _Printf_format_string_ const
wchar_t* __restrict fmt,
1957 ...) NLIB_NONNULL_4;
1970 static errno_t nlib_memcpy(
void* __restrict s1,
size_t s1max,
const void* __restrict s2,
1979 const char* __restrict range,
1985 NLIB_VIS_PUBLIC const void* nlib_memchr_set(
const void* __restrict s,
const char* __restrict set,
1987 NLIB_VIS_PUBLIC const void* nlib_memchr_set_not(
const void* __restrict s,
1990 NLIB_VIS_PUBLIC_ALT
const char*
nlib_skipws(
size_t* __restrict cnt_lf,
1991 const char** __restrict last_lf,
2013 const wchar_t* __restrict s2,
2024 const wchar_t* __restrict s2,
2061 NLIB_VIS_PUBLIC_ALT
void nlib_free(
void* ptr);
2079 # define NLIB_MEMCPY(a, b, c) memcpy((a), (b), (c))
2082 #ifndef NLIB_MEMMOVE
2083 # define NLIB_MEMMOVE(a, b, c) memmove((a), (b), (c))
2087 # define NLIB_MEMSET(a, b, c) memset((a), (b), (c))
2090 #ifndef NLIB_C_INLINE
2091 # define NLIB_C_INLINE __inline
2096 #ifndef NLIB_NONNULL_ENABLED
2097 if (!s1 || !s2)
return ERANGE;
2100 NLIB_MEMSET(s1, 0, s1max);
2103 NLIB_MEMCPY(s1, s2, n);
2109 #ifndef NLIB_NONNULL_ENABLED
2110 if (!s1 || !s2)
return ERANGE;
2112 if (s1max < n)
return ERANGE;
2113 NLIB_MEMMOVE(s1, s2, n);
2118 NLIB_EINVAL_IFNULL(buf);
2119 NLIB_MEMSET(buf, ch, n);
2148 #if defined(__INTELLISENSE__)
2149 # define NLIB_NOEXCEPT
2150 #elif defined(NLIB_CXX11_NOEXCEPT)
2151 # define NLIB_NOEXCEPT noexcept
2152 #elif !defined(NLIB_NOEXCEPT)
2153 # define NLIB_NOEXCEPT throw()
2156 #ifdef NLIB_CXX11_NEW_CHARACTER_TYPES
2169 nlib_utf16_t* lower,
2187 extern "C" NLIB_VIS_PUBLIC_ALT
size_t nlib_utf16len_(
const uint16_t* str)
NLIB_NONNULL;
2188 extern "C" NLIB_VIS_PUBLIC_ALT
size_t
2189 nlib_utf16nlen_(
const uint16_t* str,
size_t maxsize)
NLIB_NONNULL;
2191 nlib_utf16cpy_(uint16_t* s1,
size_t s1max,
const uint16_t* s2)
NLIB_NONNULL;
2193 nlib_utf16ncpy_(uint16_t* s1,
size_t s1max,
const uint16_t* s2,
size_t n)
NLIB_NONNULL;
2195 return nlib_utf16len_(reinterpret_cast<const uint16_t*>(str));
2199 return nlib_utf16nlen_(reinterpret_cast<const uint16_t*>(str), maxsize);
2202 const nlib_utf16_t* s2) NLIB_NOEXCEPT {
2203 return nlib_utf16cpy_(reinterpret_cast<uint16_t*>(s1), s1max,
2204 reinterpret_cast<const uint16_t*>(s2));
2207 const nlib_utf16_t* s2,
size_t n) NLIB_NOEXCEPT {
2208 return nlib_utf16ncpy_(reinterpret_cast<uint16_t*>(s1), s1max,
2209 reinterpret_cast<const uint16_t*>(s2), n);
2212 extern "C" NLIB_VIS_PUBLIC_ALT
size_t nlib_utf32len_(
const uint32_t* str)
NLIB_NONNULL;
2213 extern "C" NLIB_VIS_PUBLIC_ALT
size_t nlib_utf32nlen_(
const uint32_t* str,
2216 nlib_utf32cpy_(uint32_t* s1,
size_t s1max,
const uint32_t* s2)
NLIB_NONNULL;
2218 nlib_utf32ncpy_(uint32_t* s1,
size_t s1max,
const uint32_t* s2,
size_t n)
NLIB_NONNULL;
2220 return nlib_utf32len_(reinterpret_cast<const uint32_t*>(str));
2224 return nlib_utf32nlen_(reinterpret_cast<const uint32_t*>(str), maxsize);
2227 const nlib_utf32_t* s2) NLIB_NOEXCEPT {
2228 return nlib_utf32cpy_(reinterpret_cast<uint32_t*>(s1), s1max,
2229 reinterpret_cast<const uint32_t*>(s2));
2232 const nlib_utf32_t* s2,
size_t n) NLIB_NOEXCEPT {
2233 return nlib_utf32ncpy_(reinterpret_cast<uint32_t*>(s1), s1max,
2234 reinterpret_cast<const uint32_t*>(s2), n);
2238 nlib_utf16cplen_ex_(
size_t* count,
size_t* len,
const uint16_t* str)
NLIB_NONNULL_3;
2241 size_t* count,
const nlib_utf16_t* str) NLIB_NOEXCEPT {
2242 return nlib_utf16cplen_ex_(count, NULL, reinterpret_cast<const uint16_t*>(str));
2245 size_t* count,
size_t* len,
const nlib_utf16_t* str) NLIB_NOEXCEPT {
2246 return nlib_utf16cplen_ex_(count, len, reinterpret_cast<const uint16_t*>(str));
2253 nlib_vsnprintf(
size_t* count,
char (&buf)[N], _Printf_format_string_
const char* fmt,
2254 va_list args) NLIB_NOEXCEPT {
2260 _Printf_format_string_
const char* fmt, ...) NLIB_NOEXCEPT {
2262 va_start(args, fmt);
2270 nlib_vsnwprintf(
size_t* count,
wchar_t (&buf)[N], _Printf_format_string_
const wchar_t* fmt,
2271 va_list args) NLIB_NOEXCEPT {
2277 _Printf_format_string_
const wchar_t* fmt, ...) NLIB_NOEXCEPT {
2279 va_start(args, fmt);
2287 nlib_vsnprintf_fallback(
size_t* count,
char (&buf)[N], _Printf_format_string_
const char* fmt,
2288 va_list args) NLIB_NOEXCEPT {
2289 return nlib_vsnprintf_fallback(count, buf, N, fmt, args);
2294 _Printf_format_string_
const char* fmt, ...) NLIB_NOEXCEPT {
2296 va_start(args, fmt);
2297 errno_t e = nlib_vsnprintf_fallback(count, buf, N, fmt, args);
2304 _Printf_format_string_
const wchar_t* fmt,
2305 va_list args) NLIB_NOEXCEPT {
2306 return nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
2311 _Printf_format_string_
const wchar_t* fmt, ...) NLIB_NOEXCEPT {
2313 va_start(args, fmt);
2314 errno_t e = nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
2336 nlib_wcsncpy(
wchar_t (&s1)[N],
const wchar_t* s2,
size_t n) NLIB_NOEXCEPT {
2357 nlib_wcsncat(
wchar_t (&s1)[N],
const wchar_t* s2,
size_t n) NLIB_NOEXCEPT {
2363 size_t* result,
char (&utf8)[N],
const wchar_t* wcstr) NLIB_NOEXCEPT {
2369 size_t* result,
wchar_t (&wcstr)[N],
const char* utf8) NLIB_NOEXCEPT {
2375 size_t* utf8count,
char (&utf8)[N],
const nlib_utf16_t* utf16) NLIB_NOEXCEPT {
2381 size_t* utf16count, nlib_utf16_t (&utf16)[N],
const char* utf8) NLIB_NOEXCEPT {
2387 size_t* utf8count,
char (&utf8)[N],
const nlib_utf32_t* utf32) NLIB_NOEXCEPT {
2393 size_t* utf32count,
nlib_utf32_t(&utf32)[N],
const char* utf8) NLIB_NOEXCEPT {
2397 #if !defined(NN_PLATFORM_CTR) && !defined(CAFE)
2404 #endif // INCLUDE_NN_NLIB_PLATFORM_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
メッセージキューの設定や現在の状態を格納する構造体です。