16 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_ 17 #define INCLUDE_NN_NLIB_PLATFORM_H_ 20 # error Sorry, ILP64 not supported 24 #define NLIB_VERSION_YEAR 2016 25 #define NLIB_VERSION_YEAR_SHORT 16 26 #define NLIB_VERSION_DATE 1222 27 #define NLIB_VERSION 20161222 30 # ifndef __STDC_FORMAT_MACROS 32 # pragma message(__FILE__ ": __STDC_FORMAT_MACROS not defined, compile may fail") 33 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE) 34 # warning __STDC_FORMAT_MACROS not defined, compile may fail 36 # define __STDC_FORMAT_MACROS 39 #ifndef __STDC_WANT_LIB_EXT1__ 40 # define __STDC_WANT_LIB_EXT1__ 1 44 # define NLIB_UNUSED(x) (void)(x) 48 # define __has_builtin(x) 0 52 # define __has_feature(x) 0 55 #ifndef __has_cpp_attribute 56 # define __has_cpp_attribute(x) 0 59 #ifndef __has_attribute 60 # define __has_attribute(x) 0 63 #ifndef __has_declspec_attribute 64 # define __has_declspec_attribute(x) 0 68 # define __has_include(x) 0 71 #if __has_feature(thread_sanitizer) 72 # define NLIB_NO_TSAN __attribute__((no_sanitize("thread"))) 77 #if __has_feature(address_sanitizer) 78 # define NLIB_NO_ASAN __attribute__((no_sanitize("address"))) 83 #if __has_feature(memory_sanitizer) 84 # define NLIB_NO_MSAN __attribute__((no_sanitize("memory"))) 93 #if !defined(NLIB_THREAD_AA_) && defined(__clang__) && \ 94 (!defined(SWIG)) && __has_attribute(capability) 95 #define NLIB_THREAD_AA_(x) __attribute__((x)) 97 #ifdef NLIB_THREAD_AA_ 98 #undef NLIB_THREAD_AA_ 100 #define NLIB_THREAD_AA_(x) 103 #define NLIB_CAPABILITY(x) NLIB_THREAD_AA_(capability(x)) 104 #define NLIB_SCOPED_CAPABILITY NLIB_THREAD_AA_(scoped_lockable) 105 #define NLIB_GUARDED_BY(x) NLIB_THREAD_AA_(guarded_by(x)) 106 #define NLIB_PT_GUARDED_BY(x) NLIB_THREAD_AA_(pt_guarded_by(x)) 107 #define NLIB_ACQUIRED_BEFORE(...) NLIB_THREAD_AA_(acquired_before(__VA_ARGS__)) 108 #define NLIB_ACQUIRED_AFTER(...) NLIB_THREAD_AA_(acquired_after(__VA_ARGS__)) 109 #define NLIB_REQUIRES(...) NLIB_THREAD_AA_(requires_capability(__VA_ARGS__)) 110 #define NLIB_REQUIRES_SHARED(...) NLIB_THREAD_AA_(requires_shared_capability(__VA_ARGS__)) 111 #define NLIB_ACQUIRE(...) NLIB_THREAD_AA_(acquire_capability(__VA_ARGS__)) 112 #define NLIB_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(acquire_shared_capability(__VA_ARGS__)) 113 #define NLIB_RELEASE(...) NLIB_THREAD_AA_(release_capability(__VA_ARGS__)) 114 #define NLIB_RELEASE_SHARED(...) NLIB_THREAD_AA_(release_shared_capability(__VA_ARGS__)) 115 #define NLIB_TRY_ACQUIRE(...) NLIB_THREAD_AA_(try_acquire_capability(__VA_ARGS__)) 116 #define NLIB_TRY_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(try_acquire_shared_capability(__VA_ARGS__)) 117 #define NLIB_EXCLUDES(...) NLIB_THREAD_AA_(locks_excluded(__VA_ARGS__)) 118 #define NLIB_ASSERT_CAPABILITY(x) NLIB_THREAD_AA_(assert_capability(x)) 119 #define NLIB_ASSERT_SHARED_CAPABILITY(x) NLIB_THREAD_AA_(assert_shared_capability(x)) 120 #define NLIB_RETURN_CAPABILITY(x) NLIB_THREAD_AA_(lock_returned(x)) 121 #define NLIB_NO_THREAD_SAFETY_ANALYSIS NLIB_THREAD_AA_(no_thread_safety_analysis) 129 #if defined(NLIB_RENAME_CAPI) 130 #ifndef NLIB_CFUNC_PREFIX 131 # define NLIB_CFUNC_PREFIX mypfx 134 # define NLIB_CAPI__(p, q) p ## q 135 # define NLIB_CAPI_(p, q) NLIB_CAPI__(p, q) 136 # define NLIB_CAPI(x) NLIB_CAPI_(NLIB_CFUNC_PREFIX, x) 139 #define nlib_error_string NLIB_CAPI(nlib_error_string) 140 #define nlib_get_native_last_error NLIB_CAPI(nlib_get_native_last_error) 141 #define nlib_getversion NLIB_CAPI(nlib_getversion) 142 #define nlib_compiler_version NLIB_CAPI(nlib_compiler_version) 143 #define nlib_crc32 NLIB_CAPI(nlib_crc32) 144 #define nlib_crc32c NLIB_CAPI(nlib_crc32c) 145 #define nlib_epochtime NLIB_CAPI(nlib_epochtime) 146 #define nlib_ticktime NLIB_CAPI(nlib_ticktime) 147 #define nlib_sleep NLIB_CAPI(nlib_sleep) 148 #define nlib_timer_create NLIB_CAPI(nlib_timer_create) 149 #define nlib_timer_settime NLIB_CAPI(nlib_timer_settime) 150 #define nlib_timer_gettime NLIB_CAPI(nlib_timer_gettime) 151 #define nlib_timer_delete NLIB_CAPI(nlib_timer_delete) 152 #define nlib_gen_random NLIB_CAPI(nlib_gen_random) 153 #define nlib_mempagesize NLIB_CAPI(nlib_mempagesize) 154 #define nlib_virtual_alloc NLIB_CAPI(nlib_virtual_alloc) 155 #define nlib_virtual_free NLIB_CAPI(nlib_virtual_free) 156 #define nlib_physical_alloc NLIB_CAPI(nlib_physical_alloc) 157 #define nlib_physical_free NLIB_CAPI(nlib_physical_free) 158 #define nlib_mlock NLIB_CAPI(nlib_mlock) 159 #define nlib_munlock NLIB_CAPI(nlib_munlock) 160 #define nlib_tls_alloc NLIB_CAPI(nlib_tls_alloc) 161 #define nlib_tls_free NLIB_CAPI(nlib_tls_free) 162 #define nlib_tls_setvalue NLIB_CAPI(nlib_tls_setvalue) 163 #define nlib_tls_getvalue NLIB_CAPI(nlib_tls_getvalue) 164 #define nlib_mutex_init NLIB_CAPI(nlib_mutex_init) 165 #define nlib_mutex_recursive_init NLIB_CAPI(nlib_mutex_recursive_init) 166 #define nlib_mutex_recursive_timed_init NLIB_CAPI(nlib_mutex_recursive_timed_init) 167 #define nlib_mutex_lock NLIB_CAPI(nlib_mutex_lock) 168 #define nlib_mutex_trylock NLIB_CAPI(nlib_mutex_trylock) 169 #define nlib_mutex_trylock_for NLIB_CAPI(nlib_mutex_trylock_for) 170 #define nlib_mutex_unlock NLIB_CAPI(nlib_mutex_unlock) 171 #define nlib_mutex_destroy NLIB_CAPI(nlib_mutex_destroy) 172 #define nlib_semaphore_init NLIB_CAPI(nlib_semaphore_init) 173 #define nlib_semaphore_wait NLIB_CAPI(nlib_semaphore_wait) 174 #define nlib_semaphore_trywait NLIB_CAPI(nlib_semaphore_trywait) 175 #define nlib_semaphore_trywait_for NLIB_CAPI(nlib_semaphore_trywait_for) 176 #define nlib_semaphore_post NLIB_CAPI(nlib_semaphore_post) 177 #define nlib_semaphore_post_ex NLIB_CAPI(nlib_semaphore_post_ex) 178 #define nlib_semaphore_destroy NLIB_CAPI(nlib_semaphore_destroy) 179 #define nlib_cond_init NLIB_CAPI(nlib_cond_init) 180 #define nlib_cond_signal NLIB_CAPI(nlib_cond_signal) 181 #define nlib_cond_broadcast NLIB_CAPI(nlib_cond_broadcast) 182 #define nlib_cond_wait NLIB_CAPI(nlib_cond_wait) 183 #define nlib_cond_wait_for NLIB_CAPI(nlib_cond_wait_for) 184 #define nlib_cond_wait_until NLIB_CAPI(nlib_cond_wait_until) 185 #define nlib_cond_destroy NLIB_CAPI(nlib_cond_destroy) 186 #define nlib_rwlock_init NLIB_CAPI(nlib_rwlock_init) 187 #define nlib_rwlock_destroy NLIB_CAPI(nlib_rwlock_destroy) 188 #define nlib_rwlock_rdlock NLIB_CAPI(nlib_rwlock_rdlock) 189 #define nlib_rwlock_tryrdlock NLIB_CAPI(nlib_rwlock_tryrdlock) 190 #define nlib_rwlock_tryrdlock_for NLIB_CAPI(nlib_rwlock_tryrdlock_for) 191 #define nlib_rwlock_tryrdlock_until NLIB_CAPI(nlib_rwlock_tryrdlock_until) 192 #define nlib_rwlock_rdunlock NLIB_CAPI(nlib_rwlock_rdunlock) 193 #define nlib_rwlock_wrlock NLIB_CAPI(nlib_rwlock_wrlock) 194 #define nlib_rwlock_trywrlock NLIB_CAPI(nlib_rwlock_trywrlock) 195 #define nlib_rwlock_trywrlock_for NLIB_CAPI(nlib_rwlock_trywrlock_for) 196 #define nlib_rwlock_trywrlock_until NLIB_CAPI(nlib_rwlock_trywrlock_until) 197 #define nlib_rwlock_wrunlock NLIB_CAPI(nlib_rwlock_wrunlock) 198 #define nlib_condrwlock_init NLIB_CAPI(nlib_condrwlock_init) 199 #define nlib_condrwlock_destroy NLIB_CAPI(nlib_condrwlock_destroy) 200 #define nlib_condrwlock_signal NLIB_CAPI(nlib_condrwlock_signal) 201 #define nlib_condrwlock_broadcast NLIB_CAPI(nlib_condrwlock_broadcast) 202 #define nlib_condrwlock_wait NLIB_CAPI(nlib_condrwlock_wait) 203 #define nlib_condrwlock_wait_for NLIB_CAPI(nlib_condrwlock_wait_for) 204 #define nlib_condrwlock_wait_until NLIB_CAPI(nlib_condrwlock_wait_until) 205 #define nlib_barrier_init NLIB_CAPI(nlib_barrier_init) 206 #define nlib_barrier_destroy NLIB_CAPI(nlib_barrier_destroy) 207 #define nlib_barrier_wait NLIB_CAPI(nlib_barrier_wait) 208 #define nlib_once NLIB_CAPI(nlib_once) 209 #define nlib_tryonce NLIB_CAPI(nlib_tryonce) 210 #define nlib_mq_open NLIB_CAPI(nlib_mq_open) 211 #define nlib_mq_getattr NLIB_CAPI(nlib_mq_getattr) 212 #define nlib_mq_close NLIB_CAPI(nlib_mq_close) 213 #define nlib_mq_readonly NLIB_CAPI(nlib_mq_readonly) 214 #define nlib_mq_send NLIB_CAPI(nlib_mq_send) 215 #define nlib_mq_send_until NLIB_CAPI(nlib_mq_send_until) 216 #define nlib_mq_receive NLIB_CAPI(nlib_mq_receive) 217 #define nlib_mq_receive_until NLIB_CAPI(nlib_mq_receive_until) 218 #define nlib_mq_drop NLIB_CAPI(nlib_mq_drop) 219 #define nlib_yield NLIB_CAPI(nlib_yield) 220 #define nlib_thread_create NLIB_CAPI(nlib_thread_create) 221 #define nlib_thread_join NLIB_CAPI(nlib_thread_join) 222 #define nlib_thread_detach NLIB_CAPI(nlib_thread_detach) 223 #define nlib_thread_self NLIB_CAPI(nlib_thread_self) 224 #define nlib_thread_getconcurrency NLIB_CAPI(nlib_thread_getconcurrency) 225 #define nlib_thread_getid NLIB_CAPI(nlib_thread_getid) 226 #define nlib_thread_equal NLIB_CAPI(nlib_thread_equal) 227 #define nlib_thread_getcpu NLIB_CAPI(nlib_thread_getcpu) 228 #define nlib_thread_setaffinity NLIB_CAPI(nlib_thread_setaffinity) 229 #define nlib_thread_setname NLIB_CAPI(nlib_thread_setname) 230 #define nlib_thread_getname NLIB_CAPI(nlib_thread_getname) 231 #define nlib_thread_attr_init NLIB_CAPI(nlib_thread_attr_init) 232 #define nlib_thread_attr_setint NLIB_CAPI(nlib_thread_attr_setint) 233 #define nlib_thread_attr_getint NLIB_CAPI(nlib_thread_attr_getint) 234 #define nlib_thread_attr_setptr NLIB_CAPI(nlib_thread_attr_setptr) 235 #define nlib_thread_attr_getptr NLIB_CAPI(nlib_thread_attr_getptr) 236 #define nlib_thread_attr_setstack NLIB_CAPI(nlib_thread_attr_setstack) 237 #define nlib_thread_attr_getstack NLIB_CAPI(nlib_thread_attr_getstack) 238 #define nlib_thread_attr_destroy NLIB_CAPI(nlib_thread_attr_destroy) 239 #define nlib_thread_getpriority NLIB_CAPI(nlib_thread_getpriority) 240 #define nlib_thread_setpriority NLIB_CAPI(nlib_thread_setpriority) 241 #define nlib_thread_priority_min NLIB_CAPI(nlib_thread_priority_min) 242 #define nlib_thread_priority_max NLIB_CAPI(nlib_thread_priority_max) 243 #define nlib_thread_priority_default NLIB_CAPI(nlib_thread_priority_default) 244 #define nlib_thread_exit NLIB_CAPI(nlib_thread_exit) 245 #define nlib_thread_exit_cpp NLIB_CAPI(nlib_thread_exit_cpp) 246 #define nlib_thread_cleanup_push_ NLIB_CAPI(nlib_thread_cleanup_push_) 247 #define nlib_thread_cleanup_pop_ NLIB_CAPI(nlib_thread_cleanup_pop_) 248 #define nlib_write_stdout NLIB_CAPI(nlib_write_stdout) 249 #define nlib_write_stderr NLIB_CAPI(nlib_write_stderr) 250 #define nlib_debug_break NLIB_CAPI(nlib_debug_break) 251 #define nlib_debug_backtrace NLIB_CAPI(nlib_debug_backtrace) 252 #define nlib_debug_backtrace_gettext NLIB_CAPI(nlib_debug_backtrace_gettext) 253 #define nlib_getenv NLIB_CAPI(nlib_getenv) 254 #define nlib_log_print NLIB_CAPI(nlib_log_print) 255 #define nlib_log_vprint NLIB_CAPI(nlib_log_vprint) 256 #define nlib_log_attr_setint NLIB_CAPI(nlib_log_attr_setint) 257 #define nlib_fd_open NLIB_CAPI(nlib_fd_open) 258 #define nlib_fd_close NLIB_CAPI(nlib_fd_close) 259 #define nlib_fd_read NLIB_CAPI(nlib_fd_read) 260 #define nlib_fd_write NLIB_CAPI(nlib_fd_write) 261 #define nlib_fd_seek NLIB_CAPI(nlib_fd_seek) 262 #define nlib_fd_pread NLIB_CAPI(nlib_fd_pread) 263 #define nlib_fd_pwrite NLIB_CAPI(nlib_fd_pwrite) 264 #define nlib_fd_truncate NLIB_CAPI(nlib_fd_truncate) 265 #define nlib_fd_getsize NLIB_CAPI(nlib_fd_getsize) 266 #define nlib_fd_flush NLIB_CAPI(nlib_fd_flush) 267 #define nlib_fd_sync NLIB_CAPI(nlib_fd_sync) 268 #define nlib_fd_native_handle NLIB_CAPI(nlib_fd_native_handle) 269 #define nlib_fd_readv NLIB_CAPI(nlib_fd_readv) 270 #define nlib_fd_writev NLIB_CAPI(nlib_fd_writev) 271 #define nlib_fd_preadv NLIB_CAPI(nlib_fd_preadv) 272 #define nlib_fd_pwritev NLIB_CAPI(nlib_fd_pwritev) 273 #define nlib_unlink NLIB_CAPI(nlib_unlink) 274 #define nlib_remove NLIB_CAPI(nlib_remove) 275 #define nlib_mkdir NLIB_CAPI(nlib_mkdir) 276 #define nlib_rmdir NLIB_CAPI(nlib_rmdir) 277 #define nlib_rename NLIB_CAPI(nlib_rename) 278 #define nlib_dir_open NLIB_CAPI(nlib_dir_open) 279 #define nlib_dir_close NLIB_CAPI(nlib_dir_close) 280 #define nlib_dir_read NLIB_CAPI(nlib_dir_read) 281 #define nlib_is_dir NLIB_CAPI(nlib_is_dir) 282 #define nlib_exist_path NLIB_CAPI(nlib_exist_path) 283 #define nlib_disk_freespace NLIB_CAPI(nlib_disk_freespace) 284 #define nlib_basename NLIB_CAPI(nlib_basename) 285 #define nlib_dirname NLIB_CAPI(nlib_dirname) 286 #define nlib_mkostemps NLIB_CAPI(nlib_mkostemps) 287 #define nlib_fd_fileid NLIB_CAPI(nlib_fd_fileid) 288 #define nlib_readlink NLIB_CAPI(nlib_readlink) 289 #define nlib_spinlock_lock_ NLIB_CAPI(nlib_spinlock_lock_) 290 #define nlib_spinlock_unlock_ NLIB_CAPI(nlib_spinlock_unlock_) 291 #define nlib_vsnprintf NLIB_CAPI(nlib_vsnprintf) 292 #define nlib_snprintf NLIB_CAPI(nlib_snprintf) 293 #define nlib_vdprintf NLIB_CAPI(nlib_vdprintf) 294 #define nlib_dprintf NLIB_CAPI(nlib_dprintf) 295 #define nlib_printf NLIB_CAPI(nlib_printf) 296 #define nlib_vsnwprintf NLIB_CAPI(nlib_vsnwprintf) 297 #define nlib_snwprintf NLIB_CAPI(nlib_snwprintf) 298 #define nlib_vdwprintf NLIB_CAPI(nlib_vdwprintf) 299 #define nlib_dwprintf NLIB_CAPI(nlib_dwprintf) 300 #define nlib_wprintf NLIB_CAPI(nlib_wprintf) 301 #define nlib_vsnprintf_fallback NLIB_CAPI(nlib_vsnprintf_fallback) 302 #define nlib_snprintf_fallback NLIB_CAPI(nlib_snprintf_fallback) 303 #define nlib_vsnwprintf_fallback NLIB_CAPI(nlib_vsnwprintf_fallback) 304 #define nlib_snwprintf_fallback NLIB_CAPI(nlib_snwprintf_fallback) 305 #define nlib_memcmp NLIB_CAPI(nlib_memcmp) 306 #define nlib_memchr NLIB_CAPI(nlib_memchr) 307 #define nlib_memrchr NLIB_CAPI(nlib_memrchr) 308 #define nlib_memchr_not NLIB_CAPI(nlib_memchr_not) 309 #define nlib_memchr_range_not NLIB_CAPI(nlib_memchr_range_not) 310 #define nlib_memchr_lt NLIB_CAPI(nlib_memchr_lt) 311 #define nlib_memchr_gt NLIB_CAPI(nlib_memchr_gt) 312 #define nlib_memchr_mb NLIB_CAPI(nlib_memchr_mb) 313 #define nlib_memspn NLIB_CAPI(nlib_memspn) 314 #define nlib_memcspn NLIB_CAPI(nlib_memcspn) 315 #define nlib_memccpy NLIB_CAPI(nlib_memccpy) 316 #define nlib_skipws NLIB_CAPI(nlib_skipws) 317 #define nlib_strlen NLIB_CAPI(nlib_strlen) 318 #define nlib_strnlen NLIB_CAPI(nlib_strnlen) 319 #define nlib_strcpy NLIB_CAPI(nlib_strcpy) 320 #define nlib_strncpy NLIB_CAPI(nlib_strncpy) 321 #define nlib_strchr NLIB_CAPI(nlib_strchr) 322 #define nlib_strrchr NLIB_CAPI(nlib_strrchr) 323 #define nlib_strchr_mb NLIB_CAPI(nlib_strchr_mb) 324 #define nlib_wcslen NLIB_CAPI(nlib_wcslen) 325 #define nlib_wcsnlen NLIB_CAPI(nlib_wcsnlen) 326 #define nlib_wcscpy NLIB_CAPI(nlib_wcscpy) 327 #define nlib_wcsncpy NLIB_CAPI(nlib_wcsncpy) 328 #define nlib_strcat NLIB_CAPI(nlib_strcat) 329 #define nlib_strncat NLIB_CAPI(nlib_strncat) 330 #define nlib_wcscat NLIB_CAPI(nlib_wcscat) 331 #define nlib_wcsncat NLIB_CAPI(nlib_wcsncat) 332 #define nlib_strto_int8 NLIB_CAPI(nlib_strto_int8) 333 #define nlib_strto_int16 NLIB_CAPI(nlib_strto_int16) 334 #define nlib_strto_int32 NLIB_CAPI(nlib_strto_int32) 335 #define nlib_strto_int64 NLIB_CAPI(nlib_strto_int64) 336 #define nlib_strto_uint8 NLIB_CAPI(nlib_strto_uint8) 337 #define nlib_strto_uint16 NLIB_CAPI(nlib_strto_uint16) 338 #define nlib_strto_uint32 NLIB_CAPI(nlib_strto_uint32) 339 #define nlib_strto_uint64 NLIB_CAPI(nlib_strto_uint64) 340 #define nlib_strto_double NLIB_CAPI(nlib_strto_double) 341 #define nlib_strto_float NLIB_CAPI(nlib_strto_float) 342 #define nlib_strto_int32_fallback NLIB_CAPI(nlib_strto_int32_fallback) 343 #define nlib_strto_int64_fallback NLIB_CAPI(nlib_strto_int64_fallback) 344 #define nlib_strto_uint32_fallback NLIB_CAPI(nlib_strto_uint32_fallback) 345 #define nlib_strto_uint64_fallback NLIB_CAPI(nlib_strto_uint64_fallback) 346 #define nlib_strto_double_fallback NLIB_CAPI(nlib_strto_double_fallback) 347 #define nlib_strto_float_fallback NLIB_CAPI(nlib_strto_float_fallback) 348 #define nlib_wide_to_utf8 NLIB_CAPI(nlib_wide_to_utf8) 349 #define nlib_utf8_to_wide NLIB_CAPI(nlib_utf8_to_wide) 350 #define nlib_strcplen NLIB_CAPI(nlib_strcplen) 351 #define nlib_memcplen NLIB_CAPI(nlib_memcplen) 352 #define nlib_wcscplen NLIB_CAPI(nlib_wcscplen) 353 #define nlib_swapendian_16 NLIB_CAPI(nlib_swapendian_16) 354 #define nlib_swapendian_32 NLIB_CAPI(nlib_swapendian_32) 355 #define nlib_swapendian_64 NLIB_CAPI(nlib_swapendian_64) 356 #define nlib_malloc NLIB_CAPI(nlib_malloc) 357 #define nlib_free NLIB_CAPI(nlib_free) 358 #define nlib_calloc NLIB_CAPI(nlib_calloc) 359 #define nlib_realloc NLIB_CAPI(nlib_realloc) 360 #define nlib_malloc_size NLIB_CAPI(nlib_malloc_size) 361 #define nlib_free_size NLIB_CAPI(nlib_free_size) 362 #define nlib_free_size_ NLIB_CAPI(nlib_free_size_) 363 #define nlib_memalign NLIB_CAPI(nlib_memalign) 365 #define nlib_utf16cplen_ex_ NLIB_CAPI(nlib_utf16cplen_ex_) 366 #define nlib_utf16cpy_ NLIB_CAPI(nlib_utf16cpy_) 367 #define nlib_utf16len_ NLIB_CAPI(nlib_utf16len_) 368 #define nlib_utf16ncpy_ NLIB_CAPI(nlib_utf16ncpy_) 369 #define nlib_utf16nlen_ NLIB_CAPI(nlib_utf16nlen_) 370 #define nlib_utf16_to_utf32char NLIB_CAPI(nlib_utf16_to_utf32char) 371 #define nlib_utf16_to_utf8 NLIB_CAPI(nlib_utf16_to_utf8) 372 #define nlib_utf32char_to_utf16 NLIB_CAPI(nlib_utf32char_to_utf16) 373 #define nlib_utf32char_to_utf8 NLIB_CAPI(nlib_utf32char_to_utf8) 374 #define nlib_utf32cplen NLIB_CAPI(nlib_utf32cplen) 375 #define nlib_utf32cpy_ NLIB_CAPI(nlib_utf32cpy_) 376 #define nlib_utf32len_ NLIB_CAPI(nlib_utf32len_) 377 #define nlib_utf32ncpy_ NLIB_CAPI(nlib_utf32ncpy_) 378 #define nlib_utf32nlen_ NLIB_CAPI(nlib_utf32nlen_) 379 #define nlib_utf32_to_utf8 NLIB_CAPI(nlib_utf32_to_utf8) 380 #define nlib_utf8_to_utf16 NLIB_CAPI(nlib_utf8_to_utf16) 381 #define nlib_utf8_to_utf32 NLIB_CAPI(nlib_utf8_to_utf32) 382 #define nlib_utf8_to_utf32char NLIB_CAPI(nlib_utf8_to_utf32char) 383 #define nlib_memutf8_to_utf16 NLIB_CAPI(nlib_memutf8_to_utf16) 384 #define nlib_memutf8_to_utf32 NLIB_CAPI(nlib_memutf8_to_utf32) 385 #define nlib_memutf16_to_utf8 NLIB_CAPI(nlib_memutf16_to_utf8) 386 #define nlib_memutf32_to_utf8 NLIB_CAPI(nlib_memutf32_to_utf8) 387 #define nlib_memutf8_to_wide NLIB_CAPI(nlib_memutf8_to_wide) 388 #define nlib_memwide_to_utf8 NLIB_CAPI(nlib_memwide_to_utf8) 390 #define nlib_socket NLIB_CAPI(nlib_socket) 391 #define nlib_bind NLIB_CAPI(nlib_bind) 392 #define nlib_listen NLIB_CAPI(nlib_listen) 393 #define nlib_accept NLIB_CAPI(nlib_accept) 394 #define nlib_accept_for NLIB_CAPI(nlib_accept_for) 395 #define nlib_connect NLIB_CAPI(nlib_connect) 396 #define nlib_connect_for NLIB_CAPI(nlib_connect_for) 397 #define nlib_send NLIB_CAPI(nlib_send) 398 #define nlib_sendto NLIB_CAPI(nlib_sendto) 399 #define nlib_sendmsg NLIB_CAPI(nlib_sendmsg) 400 #define nlib_recv NLIB_CAPI(nlib_recv) 401 #define nlib_recvfrom NLIB_CAPI(nlib_recvfrom) 402 #define nlib_recvmsg NLIB_CAPI(nlib_recvmsg) 403 #define nlib_closesocket NLIB_CAPI(nlib_closesocket) 404 #define nlib_shutdownsocket NLIB_CAPI(nlib_shutdownsocket) 405 #define nlib_inet_pton NLIB_CAPI(nlib_inet_pton) 406 #define nlib_inet_ntop NLIB_CAPI(nlib_inet_ntop) 407 #define nlib_getaddrinfo NLIB_CAPI(nlib_getaddrinfo) 408 #define nlib_freeaddrinfo NLIB_CAPI(nlib_freeaddrinfo) 409 #define nlib_getsockopt NLIB_CAPI(nlib_getsockopt) 410 #define nlib_setsockopt NLIB_CAPI(nlib_setsockopt) 411 #define nlib_select NLIB_CAPI(nlib_select) 412 #define nlib_poll NLIB_CAPI(nlib_poll) 413 #define nlib_getnameinfo NLIB_CAPI(nlib_getnameinfo) 414 #define nlib_getsockname NLIB_CAPI(nlib_getsockname) 415 #define nlib_getpeername NLIB_CAPI(nlib_getpeername) 416 #define nlib_setnonblocking NLIB_CAPI(nlib_setnonblocking) 419 #define nlib_utf8_nbytes_table NLIB_CAPI(nlib_utf8_nbytes_table) 420 #define nlib_hex_char_table NLIB_CAPI(nlib_hex_char_table) 421 #define nlib_memcmp_generic NLIB_CAPI(nlib_memcmp_generic) 422 #define nlib_memchr_generic NLIB_CAPI(nlib_memchr_generic) 423 #define nlib_memrchr_generic NLIB_CAPI(nlib_memrchr_generic) 424 #define nlib_memchr_not_generic NLIB_CAPI(nlib_memchr_not_generic) 425 #define nlib_memchr_range_not_generic NLIB_CAPI(nlib_memchr_range_not_generic) 426 #define nlib_memchr_lt_generic NLIB_CAPI(nlib_memchr_lt_generic) 427 #define nlib_memchr_gt_generic NLIB_CAPI(nlib_memchr_gt_generic) 428 #define nlib_memchr_mb_generic NLIB_CAPI(nlib_memchr_mb_generic) 429 #define nlib_strlen_generic NLIB_CAPI(nlib_strlen_generic) 430 #define nlib_skipws_generic NLIB_CAPI(nlib_skipws_generic) 431 #define nlib_strnlen_generic NLIB_CAPI(nlib_strnlen_generic) 432 #define nlib_strchr_generic NLIB_CAPI(nlib_strchr_generic) 433 #define nlib_strrchr_generic NLIB_CAPI(nlib_strrchr_generic) 434 #define nlib_swapendian_16_generic NLIB_CAPI(nlib_swapendian_16_generic) 435 #define nlib_swapendian_32_generic NLIB_CAPI(nlib_swapendian_32_generic) 436 #define nlib_swapendian_64_generic NLIB_CAPI(nlib_swapendian_64_generic) 437 #define nlib_utf16len_generic NLIB_CAPI(nlib_utf16len_generic) 438 #define nlib_utf16nlen_generic NLIB_CAPI(nlib_utf16nlen_generic) 439 #define nlib_utf32len_generic NLIB_CAPI(nlib_utf32len_generic) 440 #define nlib_utf32nlen_generic NLIB_CAPI(nlib_utf32nlen_generic) 441 #define nlib_utf16cplen_ex_generic NLIB_CAPI(nlib_utf16cplen_ex_generic) 442 #define nlib_fd_impl NLIB_CAPI(nlib_fd_impl) 444 #define utf16chr_mb_simd NLIB_CAPI(utf16chr_mb_simd) 445 #define nlib_strchr_simd NLIB_CAPI(nlib_strchr_simd) 446 #define nlib_strrchr_simd NLIB_CAPI(nlib_strrchr_simd) 447 #define nlib_memchr_simd NLIB_CAPI(nlib_memchr_simd) 448 #define nlib_memrchr_simd NLIB_CAPI(nlib_memrchr_simd) 449 #define nlib_memchr_not_simd NLIB_CAPI(nlib_memchr_not_simd) 450 #define nlib_memchr_range_not_simd NLIB_CAPI(nlib_memchr_range_not_simd) 451 #define nlib_memchr_lt_simd NLIB_CAPI(nlib_memchr_lt_simd) 452 #define nlib_memchr_gt_simd NLIB_CAPI(nlib_memchr_gt_simd) 453 #define nlib_memchr_mb_simd NLIB_CAPI(nlib_memchr_mb_simd) 454 #define nlib_skipws_simd NLIB_CAPI(nlib_skipws_simd) 455 #define nlib_strlen_simd NLIB_CAPI(nlib_strlen_simd) 456 #define nlib_strnlen_simd NLIB_CAPI(nlib_strnlen_simd) 457 #define nlib_utf16len_simd NLIB_CAPI(nlib_utf16len_simd) 458 #define nlib_utf16nlen_simd NLIB_CAPI(nlib_utf16nlen_simd) 459 #define nlib_utf16cplen_ex_simd NLIB_CAPI(nlib_utf16cplen_ex_simd) 460 #define nlib_memcmp_simd NLIB_CAPI(nlib_memcmp_simd) 461 #define nlib_swapendian_16_simd NLIB_CAPI(nlib_swapendian_16_simd) 462 #define nlib_swapendian_32_simd NLIB_CAPI(nlib_swapendian_32_simd) 463 #define nlib_swapendian_64_simd NLIB_CAPI(nlib_swapendian_64_simd) 466 #define nlib_mount_host_nx NLIB_CAPI(nlib_mount_host_nx) 472 #define NLIB_CAPI(x) x 475 #define NLIB_STRINGIFY_(s) #s 476 #define NLIB_STRINGIFY(s) NLIB_STRINGIFY_(s) 478 #if defined(_MSC_VER) 479 # include "nn/nlib/Platform_win32.h" 480 #elif defined(__linux__) || \ 481 defined(__FreeBSD__) || \ 482 defined(__CYGWIN__) || \ 483 (defined(__APPLE__) && defined(__MACH__)) 487 # include "nn/nlib/Platform_unix.h" 488 #elif defined(NN_PLATFORM_CTR) 489 # include "nn/nlib/Platform_ctr.h" 491 # include "nn/nlib/Platform_cafe.h" 492 #elif defined(__NX__) 493 # include "nn/nlib/Platform_nx.h" 496 #if defined(_MSC_VER) && defined(n_EXPORTS) 497 #undef NLIB_VIS_PUBLIC 498 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 501 #ifndef __analysis_assume 502 # define __analysis_assume(expr) 505 #ifndef _Printf_format_string_ 506 # define _Printf_format_string_ 509 #if defined(__ARM_NEON__) || defined(__aarch64__) 530 #if defined(NLIB_SSE41) || defined(NLIB_NEON) 533 # include <arm_neon.h> 536 # include <smmintrin.h> 539 # include <nmmintrin.h> 543 #if defined(__ARM_ACLE) 544 #include <arm_acle.h> 551 # define RSIZE_MAX 0x7FFFFFFFL 553 # define RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL 558 # define NLIB_WARN(exp) ("WARNING: " exp) 568 #ifndef __PRIS_PREFIX 569 # define __PRIS_PREFIX "z" 573 # define PRIdS __PRIS_PREFIX "d" 577 # define PRIxS __PRIS_PREFIX "x" 581 # define PRIuS __PRIS_PREFIX "u" 585 # define PRIXS __PRIS_PREFIX "X" 589 # define PRIoS __PRIS_PREFIX "o" 593 # define NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else __builtin_unreachable() 596 #ifdef NLIB_NONNULL_ENABLED 597 # define NLIB_EINVAL_IFNULL(p) 599 # define NLIB_EINVAL_IFNULL(p) if (!p) return EINVAL 602 #ifndef NLIB_C_INLINE 603 # define NLIB_C_INLINE __inline 616 #ifdef NLIB_HAS_STDHEADER_INTTYPES 617 # include <inttypes.h> 620 #if defined(__LP64__) && __LP64__ == 1 630 #ifndef NLIB_VIS_PUBLIC_ALT 631 #define NLIB_VIS_PUBLIC_ALT NLIB_VIS_PUBLIC 634 #ifndef NLIB_EXPIMP_TEMPLATE 635 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_STATIC_ASSERT(sizeof(char) == 1) 665 #if defined(__INTELLISENSE__) 666 #define NLIB_ATOMIC_RELAXED (0) 667 #define NLIB_ATOMIC_ACQUIRE (1) 668 #define NLIB_ATOMIC_RELEASE (2) 669 #define NLIB_ATOMIC_ACQ_REL (3) 670 #define NLIB_ATOMIC_SEQ_CST (7) 676 int32_t val,
int memorder);
682 int success_memorder,
683 int failure_memorder);
711 int64_t desired,
int weak,
712 int success_memorder,
int failure_memorder);
739 int weak,
int success_memorder,
int failure_memorder);
747 #ifndef NLIB_TIMESPEC_HAS_NATIVE 766 #define NLIB_TO_TIMESPEC(tm, t) \ 767 (tm)->tv_sec = (time_t)((t) / (1000 * 10000)); \ 768 (tm)->tv_nsec = ((long)((t) % (1000 * 10000)) * 100) // NOLINT 770 #define NLIB_FROM_TIMESPEC(tm, t) \ 771 t = (int64_t)((tm)->tv_sec) * (1000 * 10000) + ((tm)->tv_nsec / 100) 777 NLIB_TO_TIMESPEC(tm, t);
785 NLIB_TO_TIMESPEC(tm, d);
791 NLIB_FROM_TIMESPEC(tm, d);
795 #if !defined(NLIB_TIMER_HAS_NATIVE) 797 #elif defined(_MSC_VER) 799 #elif defined(__linux__) 805 struct nlib_timerspec_ {
806 nlib_duration due_time;
807 nlib_duration interval;
809 typedef struct nlib_timerspec_ nlib_timerspec;
811 struct nlib_timerspec {
817 void* param, uint32_t flags);
819 nlib_timerspec* old_value);
824 #define NLIB_TIMER_SHORTTERM_TASK 0x00000001 825 #define NLIB_TIMER_LONGTERM_TASK 0x00000002 845 #define NLIB_PHYSICAL_ALLOC_PROT_NONE 0 846 #define NLIB_PHYSICAL_ALLOC_PROT_READ 1 847 #define NLIB_PHYSICAL_ALLOC_PROT_WRITE 2 848 #define NLIB_PHYSICAL_ALLOC_PROT_EXEC 4 854 #define NLIB_TLS_INVALID (nlib_tls)(-1) 856 #ifdef NLIB_PTHREAD_nlib_tls_alloc 875 #ifdef NLIB_PTHREAD_nlib_tls_alloc 877 return pthread_key_create(tls, destr);
880 #ifdef NLIB_PTHREAD_nlib_tls_free 882 return pthread_key_delete(tls);
887 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 893 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 895 return pthread_setspecific(tls, value);
899 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 906 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 908 *value = pthread_getspecific(tls);
917 #ifdef NLIB_PTHREAD_nlib_mutex_init 925 #ifdef NLIB_PTHREAD_nlib_mutex_init 927 return pthread_mutex_init(mutex, NULL);
933 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
936 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
938 #ifdef NLIB_PTHREAD_nlib_mutex_lock 951 #ifdef NLIB_PTHREAD_nlib_mutex_lock 953 return pthread_mutex_lock(mutex);
958 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 965 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 967 return pthread_mutex_trylock(mutex);
973 nlib_duration delta) NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *mutex);
974 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 980 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 982 return pthread_mutex_unlock(mutex);
986 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 993 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 995 return pthread_mutex_destroy(mutex);
1000 const struct timespec* tm)
1001 NLIB_TRY_ACQUIRE(0, *mutex) {
1002 nlib_duration delta;
1003 NLIB_FROM_TIMESPEC(tm, delta);
1026 nlib_duration duration;
1027 NLIB_FROM_TIMESPEC(tm, duration);
1035 #ifdef NLIB_PTHREAD_nlib_cond_init 1043 #ifdef NLIB_PTHREAD_nlib_cond_init 1045 return pthread_cond_init(cond, NULL);
1049 #ifdef NLIB_PTHREAD_nlib_cond_signal 1055 #ifdef NLIB_PTHREAD_nlib_cond_signal 1057 return pthread_cond_signal(cond);
1061 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 1067 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 1069 return pthread_cond_broadcast(cond);
1073 #ifdef NLIB_PTHREAD_nlib_cond_wait 1100 NLIB_NONNULL NLIB_REQUIRES(*mutex);
1101 #ifdef NLIB_PTHREAD_nlib_cond_wait 1102 static NLIB_C_INLINE
1104 return pthread_cond_wait(cond, mutex);
1112 nlib_duration duration) NLIB_NONNULL NLIB_REQUIRES(*mutex);
1117 nlib_time abstime) NLIB_NONNULL NLIB_REQUIRES(*mutex);
1119 #ifdef NLIB_PTHREAD_nlib_cond_destroy 1125 #ifdef NLIB_PTHREAD_nlib_cond_destroy 1127 return pthread_cond_destroy(cond);
1131 static NLIB_C_INLINE
1133 NLIB_REQUIRES(*mutex) {
1135 NLIB_FROM_TIMESPEC(tm, d);
1139 static NLIB_C_INLINE
1141 const struct timespec* tm) NLIB_REQUIRES(*mutex) {
1143 NLIB_FROM_TIMESPEC(tm, d);
1150 #ifndef NLIB_RWLOCK_HAS_NATIVE 1151 struct nlib_rwlock_ {
1156 NLIB_CAPABILITY(
"mutex")
1159 #define NLIB_RWLOCK_INITIALIZER { \ 1161 { NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER, NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER }, \ 1162 NLIB_COND_INITIALIZER } 1165 #ifdef NLIB_PTHREAD_nlib_rwlock_init 1172 #ifdef NLIB_PTHREAD_nlib_rwlock_init 1174 return pthread_rwlock_init(rwlock, NULL);
1178 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 1184 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 1186 return pthread_rwlock_destroy(rwlock);
1190 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 1196 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 1198 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1199 return pthread_rwlock_rdlock(rwlock);
1203 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 1209 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1210 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 1212 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1213 return pthread_rwlock_tryrdlock(rwlock);
1219 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1222 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1224 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 1230 NLIB_NONNULL NLIB_RELEASE_SHARED(*rwlock);
1231 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 1233 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1234 return pthread_rwlock_unlock(rwlock);
1238 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 1244 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 1246 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1247 return pthread_rwlock_wrlock(rwlock);
1251 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 1257 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 1259 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1260 return pthread_rwlock_trywrlock(rwlock);
1266 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
1269 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
1271 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 1277 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 1279 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1280 return pthread_rwlock_unlock(rwlock);
1284 static NLIB_C_INLINE
1286 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1288 NLIB_FROM_TIMESPEC(tm, d);
1292 static NLIB_C_INLINE
1294 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1296 NLIB_FROM_TIMESPEC(tm, d);
1300 static NLIB_C_INLINE
1302 NLIB_TRY_ACQUIRE(0, *rwlock) {
1304 NLIB_FROM_TIMESPEC(tm, d);
1308 static NLIB_C_INLINE
1310 NLIB_TRY_ACQUIRE(0, *rwlock) {
1312 NLIB_FROM_TIMESPEC(tm, d);
1317 #if defined(_MSC_VER) && defined(NLIB_RWLOCK_HAS_NATIVE) 1318 typedef struct nlib_condrwlock_ {
1319 CONDITION_VARIABLE cond;
1321 #define NLIB_CONDRWLOCK_INITIALIZER { CONDITION_VARIABLE_INIT } 1323 typedef struct nlib_condrwlock_ {
1327 #define NLIB_CONDRWLOCK_INITIALIZER { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER } 1335 nlib_rwlock* __restrict rwlock,
1338 nlib_rwlock* __restrict rwlock,
1339 nlib_duration duration,
1342 nlib_rwlock* __restrict rwlock,
1347 nlib_rwlock* rwlock,
1348 const struct timespec* tm,
1351 NLIB_FROM_TIMESPEC(tm, d);
1356 nlib_rwlock* rwlock,
1357 const struct timespec* tm,
1360 NLIB_FROM_TIMESPEC(tm, d);
1367 #ifndef NLIB_BARRIER_HAS_NATIVE 1368 struct nlib_barrier_ {
1376 #ifdef NLIB_PTHREAD_nlib_barrier_init 1382 #ifdef NLIB_PTHREAD_nlib_barrier_init 1384 return pthread_barrier_init(barrier, NULL, count);
1388 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1394 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1396 return pthread_barrier_destroy(barrier);
1405 struct nlib_onceflag_ {
1409 #define NLIB_ONCE_INIT { 0 } 1428 typedef struct nlib_mq_ {
1434 #define NLIB_MQ_BLOCK 0 1435 #define NLIB_MQ_NONBLOCK 1 1436 #define NLIB_MQ_LOCKFREE 2 1447 typedef struct nlib_mq_attr_ {
1477 #if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || defined(_M_AMD64) 1479 #elif defined(__ARM_ACLE) 1486 #define NLIB_THREAD_INVALID (nlib_thread)(0) // NOLINT 1488 #ifndef NLIB_SPINLOCK_HAS_NATIVE 1492 #ifndef NLIB_THREAD_ATTR_HAS_NATIVE 1493 struct nlib_thread_attr_ {
1504 struct nlib_thread_attr_ {
1505 pthread_attr_t attr;
1522 #ifdef NLIB_PTHREAD_nlib_thread_join 1528 #ifdef NLIB_PTHREAD_nlib_thread_join 1530 return pthread_join(thread, NULL);
1534 #ifdef NLIB_PTHREAD_nlib_thread_detach 1540 #ifdef NLIB_PTHREAD_nlib_thread_detach 1542 return pthread_detach(thread);
1546 #ifdef NLIB_PTHREAD_nlib_thread_self 1552 #ifdef NLIB_PTHREAD_nlib_thread_self 1554 *thread = pthread_self();
1562 #ifdef NLIB_PTHREAD_nlib_thread_equal 1568 #ifdef NLIB_PTHREAD_nlib_thread_equal 1570 return pthread_equal(th1, th2);
1578 #ifdef NLIB_PTHREAD_nlib_thread_getname 1584 #ifdef NLIB_PTHREAD_nlib_thread_getname 1586 return pthread_getname_np(thread, name, len);
1611 void** __restrict stack_addr,
size_t* __restrict stack_size)
1615 #define NLIB_THREAD_ATTR_KEY_DETACHSTATE (1) 1616 #define NLIB_THREAD_ATTR_KEY_STACKSIZE (2) 1617 #define NLIB_THREAD_ATTR_KEY_PRIORITY (4) 1618 #define NLIB_THREAD_ATTR_KEY_AFFINITY (5) 1619 #define NLIB_THREAD_ATTR_KEY_EXPLICIT_SCHED (6) 1627 #ifndef NN_PLATFORM_CTR 1635 #elif defined(pthread_cleanup_push) 1636 # define nlib_thread_cleanup_push(fn, arg) pthread_cleanup_push(fn, arg) 1637 # define nlib_thread_cleanup_pop(exec) pthread_cleanup_pop(exec) 1638 #elif !defined(NN_PLATFORM_CTR) 1639 struct nlib_thread_cleanup_handler_ {
1640 void (*func)(
void*);
1642 struct nlib_thread_cleanup_handler_* next;
1644 #define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \ 1645 struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, NULL }; \ 1646 nlib_thread_cleanup_push_(&_thread_cleanup_handler) 1647 #define nlib_thread_cleanup_pop(exec) nlib_thread_cleanup_pop_(exec); } 1649 NLIB_VIS_PUBLIC void nlib_thread_cleanup_push_(
struct nlib_thread_cleanup_handler_* handler);
1671 void*
const* __restrict buf,
size_t count)
NLIB_NONNULL;
1677 NLIB_LOG_UNKNOWN = 0,
1691 typedef enum nlib_log_key {
1692 NLIB_LOG_ATTR_UNKNOWN = 0,
1693 NLIB_LOG_ATTR_STDOUT,
1694 NLIB_LOG_ATTR_STDERR,
1695 NLIB_LOG_ATTR_MSVC_TRACE,
1696 NLIB_LOG_ATTR_SYSLOG,
1697 NLIB_LOG_ATTR_NLIB_FD,
1701 #ifndef NLIB_ATTRIBUTE_PRINTF 1702 # define NLIB_ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y))) 1706 const char* __restrict fmt, ...)
1715 #ifndef NLIB_FD_O_RDONLY 1719 # define NLIB_FD_O_RDONLY O_RDONLY 1722 #ifndef NLIB_FD_O_WRONLY 1726 # define NLIB_FD_O_WRONLY O_WRONLY 1729 #ifndef NLIB_FD_O_RDWR 1733 # define NLIB_FD_O_RDWR O_RDWR 1736 #ifndef NLIB_FD_O_APPEND 1740 # define NLIB_FD_O_APPEND O_APPEND 1743 #ifndef NLIB_FD_O_CREAT 1747 # define NLIB_FD_O_CREAT O_CREAT 1750 #ifndef NLIB_FD_O_TRUNC 1754 # define NLIB_FD_O_TRUNC O_TRUNC 1757 #ifndef NLIB_FD_O_EXCL 1761 # define NLIB_FD_O_EXCL O_EXCL 1764 #ifndef NLIB_SEEK_SET 1768 # define NLIB_SEEK_SET SEEK_SET 1771 #ifndef NLIB_SEEK_CUR 1775 # define NLIB_SEEK_CUR SEEK_CUR 1783 #define NLIB_FD_INVALID (-1) 1790 errno_t nlib_fd_open(nlib_fd* fd,
const char* native_path,
unsigned int flags, ...) NLIB_NONNULL_1;
1799 errno_t nlib_fd_read(
size_t* __restrict result, nlib_fd fd,
void* __restrict buf,
size_t count)
1824 #if !defined(NLIB_IOVEC_HAS_NATIVE) 1825 struct nlib_fd_iovec_ {
1829 typedef struct nlib_fd_iovec_ nlib_fd_iovec;
1831 typedef struct iovec nlib_fd_iovec;
1834 errno_t nlib_fd_readv(
size_t* __restrict result, nlib_fd fd,
const nlib_fd_iovec* __restrict iov,
1849 unsigned int flags);
1853 errno_t nlib_rename(
const char* __restrict old_path,
const char* __restrict new_path);
1858 typedef struct nlib_dir_ nlib_dir;
1859 typedef struct nlib_dirent_ {
1880 uint64_t* __restrict free_bytes_available,
1881 uint64_t* __restrict total_bytes,
1882 uint64_t* __restrict total_free_bytes);
1888 struct nlib_fileid_ {
1889 #if defined(_MSC_VER) 1891 #elif defined(NLIB_UNIX) 1898 typedef struct nlib_fileid_ nlib_fileid;
1906 #if defined(_MSC_VER) || defined(NLIB_UNIX) 1907 #define NLIB_SOCKET_ENABLED 1911 typedef int nlib_sock;
1912 #define NLIB_SOCKET_INVALID (nlib_sock)(-1) // NOLINT 1914 #if defined(_MSC_VER) 1915 #define NLIB_SOCK_NONBLOCK 0x8000 1916 #elif defined(SOCK_NONBLOCK) 1917 #define NLIB_SOCK_NONBLOCK SOCK_NONBLOCK 1919 #define NLIB_SOCK_NONBLOCK O_NONBLOCK 1922 #if !defined(TCP_FASTOPEN) && defined(_MSC_VER) 1924 # define TCP_FASTOPEN 15 1929 typedef struct sockaddr nlib_sockaddr;
1930 typedef struct sockaddr_in nlib_sockaddr_in;
1931 typedef struct sockaddr_in6 nlib_sockaddr_in6;
1933 struct nlib_msghdr_ {
1935 uint32_t msg_namelen;
1936 nlib_fd_iovec* msg_iov;
1939 size_t msg_controllen;
1942 typedef struct nlib_msghdr_ nlib_msghdr;
1943 #define NLIB_CMSG_FIRSTHDR(msgh) \ 1944 ((msgh)->msg_controllen >= sizeof(WSACMSGHDR) ? \ 1945 (LPWSACMSGHDR)(msgh)->msg_control : (LPWSACMSGHDR)NULL) 1946 #define NLIB_CMSG_NXTHDR(msg, cmsg) \ 1947 ( ((cmsg) == NULL) ? NLIB_CMSG_FIRSTHDR(msg) \ 1948 : ( ( ((PUCHAR)(cmsg) + \ 1949 WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len) + \ 1950 sizeof(WSACMSGHDR) ) > \ 1951 (PUCHAR)((msg)->msg_control) + \ 1952 (msg)->msg_controllen) \ 1953 ? (LPWSACMSGHDR)NULL \ 1954 : (LPWSACMSGHDR)((PUCHAR)(cmsg) + \ 1955 WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len)) ) ) 1956 #define NLIB_CMSG_SPACE(length) WSA_CMSG_SPACE(length) 1957 #define NLIB_CMSG_LEN(length) WSA_CMSG_LEN(length) 1958 #define NLIB_CMSG_DATA(cmsg) WSA_CMSG_DATA(cmsg) 1960 typedef struct msghdr nlib_msghdr;
1961 #define NLIB_CMSG_FIRSTHDR(msgh) CMSG_FIRSTHDR(msgh) 1962 #define NLIB_CMSG_NXTHDR(msgh, cmsg) CMSG_NXTHDR(msgh, cmsg) 1964 #define NLIB_CMSG_SPACE(length) CMSG_SPACE(length) 1965 #define NLIB_CMSG_LEN(length) CMSG_LEN(length) 1966 #define NLIB_CMSG_DATA(cmsg) CMSG_DATA(cmsg) 1968 typedef struct cmsghdr nlib_cmsghdr;
1972 errno_t nlib_accept(nlib_sock* __restrict s, nlib_sock sockfd, nlib_sockaddr* __restrict addr,
1973 uint32_t* __restrict addrlen,
int flags);
1975 errno_t nlib_accept_for(nlib_sock* __restrict s, nlib_sock sockfd, nlib_sockaddr* __restrict addr,
1976 uint32_t* __restrict addrlen,
int flags, nlib_duration timeout);
1978 errno_t nlib_connect(nlib_sock sockfd,
const nlib_sockaddr* addr, uint32_t addrlen);
1980 errno_t nlib_connect_for(nlib_sock sockfd,
const nlib_sockaddr* addr, uint32_t addrlen,
1981 int flags, nlib_duration timeout);
1984 errno_t nlib_sendto(
size_t* __restrict size, nlib_sock sockfd,
const void* __restrict buf,
1985 size_t len,
int flags,
const nlib_sockaddr* __restrict dest_addr,
1988 errno_t nlib_sendmsg(
size_t* __restrict size, nlib_sock sockfd,
const nlib_msghdr* msg,
int flags);
1989 static NLIB_C_INLINE
1990 errno_t nlib_send(
size_t* __restrict size, nlib_sock sockfd,
const void* __restrict buf,
1991 size_t len,
int flags) {
1992 return nlib_sendto(size, sockfd, buf, len, flags, NULL, 0);
1996 errno_t nlib_recvfrom(
size_t* __restrict size, nlib_sock sockfd,
1997 void* __restrict buf,
size_t len,
int flags,
1998 nlib_sockaddr* __restrict dest_addr,
1999 uint32_t* __restrict addrlen);
2001 errno_t nlib_recvmsg(
size_t* __restrict size, nlib_sock sockfd, nlib_msghdr* msg,
int flags);
2002 static NLIB_C_INLINE
2003 errno_t nlib_recv(
size_t* __restrict size, nlib_sock sockfd,
void* __restrict buf,
size_t len,
2005 return nlib_recvfrom(size, sockfd, buf, len, flags, NULL, NULL);
2011 # define SHUT_RD SD_RECEIVE 2012 # define SHUT_WR SD_SEND 2013 # define SHUT_RDWR SD_BOTH 2018 #ifndef NLIB_LITTLE_ENDIAN 2019 static NLIB_C_INLINE uint32_t nlib_htonl(uint32_t hostlong) {
return hostlong; }
2020 static NLIB_C_INLINE uint16_t nlib_htons(uint16_t hostshort) {
return hostshort; }
2021 static NLIB_C_INLINE uint32_t nlib_ntohl(uint32_t netlong) {
return netlong; }
2022 static NLIB_C_INLINE uint16_t nlib_ntohs(uint16_t netshort) {
return netshort; }
2024 static NLIB_C_INLINE uint32_t nlib_htonl(uint32_t hostlong) {
2026 return _byteswap_ulong(hostlong);
2028 return __builtin_bswap32(hostlong);
2031 static NLIB_C_INLINE uint16_t nlib_htons(uint16_t hostshort) {
2033 return _byteswap_ushort(hostshort);
2035 return ((hostshort & 0xFF) << 8) | ((hostshort >> 8) & 0xFF);
2038 static NLIB_C_INLINE uint32_t nlib_ntohl(uint32_t netlong) {
2040 return _byteswap_ulong(netlong);
2042 return __builtin_bswap32(netlong);
2045 static NLIB_C_INLINE uint16_t nlib_ntohs(uint16_t netshort) {
2047 return _byteswap_ushort(netshort);
2049 return ((netshort & 0xFF) << 8) | ((netshort >> 8) & 0xFF);
2054 typedef struct in_addr nlib_in_addr;
2055 typedef struct in6_addr nlib_in6_addr;
2078 typedef int eai_error_t;
2079 typedef struct addrinfo nlib_addrinfo;
2081 eai_error_t nlib_getaddrinfo(
const char* __restrict node,
const char* __restrict service,
2082 const nlib_addrinfo* __restrict hints,
2083 nlib_addrinfo** __restrict res);
2085 eai_error_t nlib_getnameinfo(
const nlib_sockaddr* __restrict sa, uint32_t salen,
2086 char* __restrict host, uint32_t hostlen,
2087 char* __restrict serv, uint32_t servlen,
int flags);
2091 errno_t nlib_getsockopt(nlib_sock sockfd,
int level,
int optname,
void* __restrict optval,
2092 uint32_t* __restrict optlen);
2094 errno_t nlib_setsockopt(nlib_sock sockfd,
int level,
int optname,
const void* optval,
2097 typedef fd_set nlib_fd_set;
2099 errno_t nlib_select(
size_t* __restrict n,
int nfds, nlib_fd_set* __restrict readfds,
2100 nlib_fd_set* __restrict writefds,
2101 nlib_fd_set* __restrict exceptfds, nlib_duration timeout);
2103 #define NLIB_FD_CLR FD_CLR 2104 #define NLIB_FD_ISSET FD_ISSET 2106 #define NLIB_FD_SET(fd, set) FD_SET((SOCKET)fd, set) 2108 #define NLIB_FD_SET FD_SET 2110 #define NLIB_FD_ZERO FD_ZERO 2112 #if defined(_MSC_VER) 2113 struct nlib_pollfd_ {
2118 typedef struct nlib_pollfd_ nlib_pollfd;
2120 typedef struct pollfd nlib_pollfd;
2123 errno_t nlib_poll(
size_t* __restrict n, nlib_pollfd* __restrict fds, uint32_t nfds,
2124 nlib_duration timeout);
2127 #define NLIB_MSG_DONTWAIT (0x4000) 2129 #define NLIB_MSG_DONTWAIT MSG_DONTWAIT 2133 #define NLIB_MSG_FASTOPEN MSG_FASTOPEN 2135 #define NLIB_MSG_FASTOPEN 0x20000000 2140 errno_t nlib_getsockname(nlib_sock sockfd, nlib_sockaddr* __restrict addr,
2141 uint32_t* __restrict addrlen);
2143 errno_t nlib_getpeername(nlib_sock sockfd, nlib_sockaddr* __restrict addr,
2144 uint32_t* __restrict addrlen);
2157 # warning Do not define EDQUOT. nlib may not work correctly. 2174 #ifndef NLIB_SKIP_ERRNO_DEFINE 2176 #define NLIB_E_BASE 2000 2190 # define EACCES 9973 2196 # define EADDRINUSE 9902 2201 #ifndef EADDRNOTAVAIL 2202 # define EADDRNOTAVAIL 9903 2207 #ifndef EAFNOSUPPORT 2208 # define EAFNOSUPPORT 9901 2214 # define EAGAIN 9976 2220 # define EALREADY 9907 2232 # define EBADMSG 9905 2244 # define ECANCELED 9927 2250 # define ECHILD 9963 2255 #ifndef ECONNABORTED 2256 # define ECONNABORTED 9906 2261 #ifndef ECONNREFUSED 2262 # define ECONNREFUSED 9908 2268 # define ECONNRESET 9909 2274 # define EDEADLK 9975 2279 #ifndef EDESTADDRREQ 2280 # define EDESTADDRREQ 9910 2292 # define EDQUOT (NLIB_E_BASE + 19) 2298 # define EEXIST 9955 2304 # define EFAULT 9948 2315 #ifndef EHOSTUNREACH 2316 # define EHOSTUNREACH 9911 2328 # define EILSEQ 9945 2334 # define EINPROGRESS 9928 2346 # define EINVAL 9943 2358 # define EISCONN 9904 2364 # define EISDIR 9962 2376 # define EMFILE 9978 2382 # define EMLINK 9979 2388 # define EMSGSIZE 9913 2394 # define EMULTIHOP (NLIB_E_BASE + 36) 2399 #ifndef ENAMETOOLONG 2400 # define ENAMETOOLONG 9957 2406 # define ENETDOWN 9914 2412 # define ENETRESET 9915 2418 # define ENETUNREACH 9916 2424 # define ENFILE 9977 2430 # define ENOBUFS 9917 2436 # define ENODATA 9919 2442 # define ENODEV 9967 2448 # define ENOENT 9968 2454 # define ENOEXEC 9954 2460 # define ENOLCK 9964 2466 # define ENOLINK 9918 2472 # define ENOMEM 9971 2478 # define ENOMSG 9920 2484 # define ENOPROTOOPT 9921 2490 # define ENOSPC 9965 2502 # define ENOSTR 9924 2508 # define ENOSYS 9942 2514 # define ENOTCONN 9925 2520 # define ENOTDIR 9970 2526 # define ENOTEMPTY 9953 2531 #ifndef ENOTRECOVERABLE 2532 # define ENOTRECOVERABLE 9934 2538 # define ENOTSOCK 9923 2544 # define ENOTSUP 9926 2550 # define ENOTTY 9958 2562 # define EOPNOTSUPP 9929 2568 # define EOVERFLOW 9940 2574 # define EOWNERDEAD 9931 2592 # define EPROTO 9932 2597 #ifndef EPROTONOSUPPORT 2598 # define EPROTONOSUPPORT 9933 2604 # define EPROTOTYPE 9941 2610 # define ERANGE 9944 2622 # define ESPIPE 9960 2634 # define ESTALE (NLIB_E_BASE + 75) 2646 # define ETIMEDOUT 9938 2652 # define ETXTBSY 9936 2658 # define EWOULDBLOCK 9930 2666 #endif // NLIB_SKIP_ERRNO_DEFINE 2671 #ifndef NLIB_SPINLOCK_HAS_NATIVE 2672 #define NLIB_SPINLOCK_INITIALIZER (0) 2674 #ifndef NN_PLATFORM_CTR 2687 #if defined(__arm__) 2688 #if __has_builtin(__builtin_arm_ldrex) 2689 int R5 = __builtin_arm_ldrex(lock);
2691 int R5 = __ldrex(lock);
2694 #if __has_builtin(__builtin_arm_strex) 2695 if (__builtin_arm_strex(1, lock) == 0) {
2697 if (__strex(1, lock) == 0) {
2699 #if !defined(NN_PLATFORM_CTR) 2707 nlib_spinlock_lock_(lock);
2709 int32_t expected = 0;
2712 nlib_spinlock_lock_(lock);
2717 #if defined(__arm__) 2718 #if __has_builtin(__builtin_arm_ldrex) 2719 int R5 = __builtin_arm_ldrex(lock);
2721 int R5 = __ldrex(lock);
2724 #if __has_builtin(__builtin_arm_strex) 2725 if (__builtin_arm_strex(1, lock) == 0) {
2727 if (__strex(1, lock) == 0) {
2729 #if !defined(NN_PLATFORM_CTR) 2739 int32_t expected = 0;
2748 #if defined(NN_PLATFORM_CTR) 2751 int32_t expected = 1;
2755 nlib_spinlock_unlock_(lock);
2757 #if defined(__arm__) 2769 _Printf_format_string_
const char* __restrict fmt, va_list args)
2773 _Printf_format_string_
const char* __restrict fmt, ...)
2777 _Printf_format_string_
const char* __restrict fmt, va_list args)
2781 _Printf_format_string_
const char* __restrict fmt, ...)
2785 int nlib_printf(_Printf_format_string_
const char* fmt, ...)
2790 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2794 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
2798 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2802 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
NLIB_NONNULL_3;
2807 errno_t nlib_vsnprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
size_t size,
2808 _Printf_format_string_
const char* __restrict fmt, va_list args)
2811 errno_t nlib_snprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
2812 size_t size, _Printf_format_string_
const char* __restrict fmt, ...)
2815 errno_t nlib_vsnwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
2816 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2819 errno_t nlib_snwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
2820 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
2828 static errno_t nlib_memcpy(
void* __restrict s1,
size_t s1max,
const void* __restrict s2,
size_t n)
2833 void*
nlib_memccpy(
void* __restrict dest,
size_t dest_size,
const void* __restrict src,
2836 #ifdef NLIB_LIBC_nlib_memcmp 2842 #ifdef NLIB_LIBC_nlib_memcmp 2843 static NLIB_C_INLINE
int nlib_memcmp(
const void* buf1,
const void* buf2,
size_t n) {
2844 return memcmp(buf1, buf2, n);
2848 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr(
const void* s,
int c,
size_t n)
2850 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memrchr(
const void* s,
int c,
size_t n)
2852 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_not(
const void* s,
int c,
size_t n)
2857 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_lt(
const void* s,
int c,
size_t n)
2859 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_gt(
const void* s,
int c,
size_t n)
2862 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_mb(
const void* s,
size_t n)
2865 const char* __restrict
set,
size_t n)
2868 const char* __restrict
set,
size_t n)
2873 const char*
nlib_skipws(
size_t* __restrict cnt_lf,
const char** __restrict last_lf,
2876 #ifdef NLIB_LIBC_nlib_strlen 2882 #ifdef NLIB_LIBC_nlib_strlen 2883 static NLIB_C_INLINE
size_t nlib_strlen(
const char* s) {
return strlen(s); }
2886 #ifdef NLIB_LIBC_nlib_strnlen 2892 #ifdef NLIB_LIBC_nlib_strnlen 2893 static NLIB_C_INLINE
size_t nlib_strnlen(
const char* s,
size_t maxsize) {
2894 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2895 return strnlen_s(s, maxsize);
2897 return strnlen(s, maxsize);
2902 #ifdef NLIB_LIBC_nlib_strcpy 2908 #ifdef NLIB_LIBC_nlib_strcpy 2909 static NLIB_C_INLINE
2911 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2912 return strcpy_s(s1, s1max, s2);
2919 #ifdef NLIB_LIBC_nlib_strncpy 2924 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n)
2926 #ifdef NLIB_LIBC_nlib_strncpy 2927 static NLIB_C_INLINE
2928 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n) {
2929 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2930 return strncpy_s(s1, s1max, s2, n);
2937 #ifdef NLIB_LIBC_nlib_strchr 2943 #ifdef NLIB_LIBC_nlib_strchr 2944 static NLIB_C_INLINE
const char*
nlib_strchr(
const char* s,
int c) {
return strchr(s, c); }
2947 #ifdef NLIB_LIBC_nlib_strrchr 2953 #ifdef NLIB_LIBC_nlib_strrchr 2954 static NLIB_C_INLINE
const char*
nlib_strrchr(
const char* s,
int c) {
return strrchr(s, c); }
2963 return (
const char*)p;
2969 #ifdef NLIB_LIBC_nlib_wcslen 2975 #ifdef NLIB_LIBC_nlib_wcslen 2976 static NLIB_C_INLINE
size_t nlib_wcslen(
const wchar_t* s) {
return wcslen(s); }
2979 #ifdef NLIB_LIBC_nlib_wcsnlen 2985 #ifdef NLIB_LIBC_nlib_wcsnlen 2986 static NLIB_C_INLINE
size_t nlib_wcsnlen(
const wchar_t* s,
size_t maxsize) {
2987 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2988 return wcsnlen_s(s, maxsize);
2990 return wcsnlen(s, maxsize);
2995 #ifdef NLIB_LIBC_nlib_wcscpy 3000 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2)
3002 #ifdef NLIB_LIBC_nlib_wcscpy 3003 static NLIB_C_INLINE
3004 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2) {
3005 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3006 return wcscpy_s(s1, s1max, s2);
3013 #ifdef NLIB_LIBC_nlib_wcsncpy 3018 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n)
3020 #ifdef NLIB_LIBC_nlib_wcsncpy 3021 static NLIB_C_INLINE
3022 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n) {
3023 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3024 return wcsncpy_s(s1, s1max, s2, n);
3067 static NLIB_C_INLINE
3072 if (e != 0 && e != ERANGE)
return e;
3073 if (tmp > 127 || tmp < -128) {
3074 *result = tmp < 0 ? -128 : 127;
3077 *result = (int8_t)tmp;
3080 static NLIB_C_INLINE
3085 if (e != 0 && e != ERANGE)
return e;
3086 if (tmp > 32767 || tmp < -32768) {
3087 *result = tmp < 0 ? -32768 : 32767;
3090 *result = (int16_t)tmp;
3093 static NLIB_C_INLINE
3098 if (e != 0 && e != ERANGE)
return e;
3103 *result = (uint8_t)tmp;
3106 static NLIB_C_INLINE
3111 if (e != 0 && e != ERANGE)
return e;
3116 *result = (uint16_t)tmp;
3128 char* __restrict to,
size_t to_size,
3129 const wchar_t* __restrict from,
size_t from_size)
3133 wchar_t* __restrict to,
size_t to_size,
3134 const char* __restrict from,
size_t from_size)
3140 errno_t nlib_strcplen(
size_t* __restrict codepoint_count,
3141 size_t* __restrict supplementary_codepoint_count,
3142 size_t* __restrict len,
3144 #define nlib_strcplen2 nlib_strcplen 3147 size_t* __restrict supplementary_codepoint_count,
3148 size_t* __restrict from_read,
3149 const char* __restrict from,
3170 NLIB_VIS_PUBLIC_ALT
void nlib_free(
void* ptr);
3193 # define NLIB_MEMCPY(a, b, c) memcpy((a), (b), (c)) 3196 #ifndef NLIB_MEMMOVE 3197 # define NLIB_MEMMOVE(a, b, c) memmove((a), (b), (c)) 3201 # define NLIB_MEMSET(a, b, c) memset((a), (b), (c)) 3221 return (
'0' <= ch && ch <=
'9') || (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
3224 return (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
3226 static NLIB_C_INLINE
int nlib_isblank(
int ch) {
return ch ==
' ' || ch ==
'\t'; }
3227 static NLIB_C_INLINE
int nlib_iscntrl(
int ch) {
return (ch >= 0 && ch <= 0x1F) || ch == 0x7F; }
3228 static NLIB_C_INLINE
int nlib_isdigit(
int ch) {
return (
'0' <= ch && ch <=
'9'); }
3229 static NLIB_C_INLINE
int nlib_isgraph(
int ch) {
return ch >= 0x21 && ch <= 0x7E; }
3230 static NLIB_C_INLINE
int nlib_islower(
int ch) {
return (ch >=
'a' && ch <=
'z'); }
3231 static NLIB_C_INLINE
int nlib_isprint(
int ch) {
return ch >= 0x20 && ch <= 0x7E; }
3232 static NLIB_C_INLINE
int nlib_ispunct(
int ch) {
return (ch >= 0x00 && ch <= 0x20) || ch == 0x7F; }
3234 return ((ch) ==
' ' || (ch) ==
'\t' || (ch) ==
'\n');
3236 static NLIB_C_INLINE
int nlib_isupper(
int ch) {
return (ch >=
'A' && ch <=
'Z'); }
3238 return (
unsigned int)(ch -
'0') < 10u ||
3239 (
unsigned int)((ch | 0x20) -
'a') < 6u;
3242 return (ch >=
'A' && ch <=
'Z') ? ch + (
'a' -
'A') : ch;
3245 return (ch >=
'a' && ch <=
'z') ? ch - (
'a' -
'A') : ch;
3250 static NLIB_C_INLINE
3252 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3253 return memcpy_s(s1, s1max, s2, n);
3255 #ifndef NLIB_NONNULL_ENABLED 3256 if (!s1 || !s2)
return ERANGE;
3259 NLIB_MEMSET(s1, 0, s1max);
3262 NLIB_MEMCPY(s1, s2, n);
3268 static NLIB_C_INLINE
3270 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3271 return memmove_s(s1, s1max, s2, n);
3273 #ifndef NLIB_NONNULL_ENABLED 3274 if (!s1 || !s2)
return ERANGE;
3276 if (s1max < n)
return ERANGE;
3277 NLIB_MEMMOVE(s1, s2, n);
3282 static NLIB_C_INLINE
3284 NLIB_EINVAL_IFNULL(buf);
3285 NLIB_MEMSET(buf, ch, n);
3292 #if defined(NLIB_SSE42) 3294 return _mm_popcnt_u32(x);
3297 return _mm_popcnt_u32(x);
3301 return (
int)_mm_popcnt_u64(x);
3303 uint32_t lo = (uint32_t)(x & 0xFFFFFFFFU);
3304 uint32_t hi = (uint32_t)((x >> 32) & 0xFFFFFFFFU);
3305 return _mm_popcnt_u32(lo) + _mm_popcnt_u32(hi);
3308 #elif defined(NLIB_NEON) 3310 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3312 return vaddv_u8(x0);
3314 uint8x8_t x1 = vpadd_u8(x0, x0);
3315 return vget_lane_u8(x1, 0);
3319 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3321 return vaddv_u8(x0);
3323 uint8x8_t x1 = vpadd_u8(x0, x0);
3324 uint8x8_t x2 = vpadd_u8(x1, x1);
3325 return vget_lane_u8(x2, 0);
3329 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3331 return vaddv_u8(x0);
3333 uint8x8_t x1 = vpadd_u8(x0, x0);
3334 uint8x8_t x2 = vpadd_u8(x1, x1);
3335 uint8x8_t x3 = vpadd_u8(x2, x2);
3336 return vget_lane_u8(x3, 0);
3342 return _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
3343 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3346 return _nlib_popcnt_array[(x >> 56) & 0xFF] + _nlib_popcnt_array[(x >> 48) & 0xFF] +
3347 _nlib_popcnt_array[(x >> 40) & 0xFF] + _nlib_popcnt_array[(x >> 32) & 0xFF] +
3348 _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
3349 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3352 return _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3355 #define nlib_popcnt(x) nlib_popcnt32(x) 3365 #if defined(_MSC_VER) 3368 return _BitScanReverse(&cnt, x) ? (int)(31 - cnt) : 32;
3373 return _BitScanForward(&cnt, x) ? cnt : 32;
3378 return _BitScanReverse64(&cnt, x) ? (int)(63 - cnt) : 64;
3382 DWORD dw = (DWORD)(x >> 32);
3383 if (_BitScanReverse(&cnt, dw)) {
3384 return (
int)(31 - cnt);
3387 return _BitScanReverse(&cnt, dw) ?
3388 (int)(63 - cnt) : 64;
3395 return _BitScanForward64(&cnt, x) ? cnt : 64;
3398 DWORD dw = (DWORD)(x);
3399 if (_BitScanForward(&cnt, dw)) {
3402 dw = (DWORD)(x >> 32);
3403 return _BitScanForward(&cnt, dw) ?
3404 (int)(32 + cnt) : 64;
3413 unsigned int dw = (
unsigned int)(x >> 32);
3418 dw = (
unsigned int)(x);
3424 #elif defined(NN_PLATFORM_CTR) 3435 #define nlib_clz(x) nlib_clz32(x) 3436 #define nlib_ctz(x) nlib_ctz32(x) 3438 static size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max)
3440 static NLIB_C_INLINE
3441 size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max) {
3442 #if defined(__FreeBSD__) 3443 return strlcpy(s1, s2, s1max);
3447 NLIB_MEMCPY(s1, s2, len + 1);
3449 NLIB_MEMCPY(s1, s2, s1max - 1);
3450 s1[s1max - 1] =
'\0';
3460 #if __has_builtin(__builtin_bitreverse32) 3461 return __builtin_bitreverse32(x);
3462 #elif __has_builtin(__builtin_arm_rbit) 3463 return __builtin_arm_rbit(x);
3464 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 3467 x = ((x & 0x55555555UL) << 1) | ((x >> 1) & 0x55555555UL);
3468 x = ((x & 0x33333333UL) << 2) | ((x >> 2) & 0x33333333UL);
3469 x = ((x & 0x0F0F0F0FUL) << 4) | ((x >> 4) & 0x0F0F0F0FUL);
3471 x = _byteswap_ulong(x);
3472 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 3473 x = (x << 24) | ((x & 0xFF00) << 8) |
3474 ((x >> 8) & 0xFF00) | (x >> 24);
3476 x = __builtin_bswap32(x);
3483 #if __has_builtin(__builtin_bitreverse64) 3484 return __builtin_bitreverse64(x);
3485 #elif __has_builtin(__builtin_arm_rbit64) 3486 return __builtin_arm_rbit64(x);
3487 #elif __has_builtin(__builtin_arm_rbit) 3488 return __builtin_arm_rbit(x >> 32) |
3489 (((uint64_t)__builtin_arm_rbit(x)) << 32);
3490 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 3491 return __rbit(x >> 32) |
3492 (((uint64_t)__rbit(x)) << 32);
3494 x = ((x & 0x5555555555555555ULL) << 1) | ((x >> 1) & 0x5555555555555555ULL);
3495 x = ((x & 0x3333333333333333ULL) << 2) | ((x >> 2) & 0x3333333333333333ULL);
3496 x = ((x & 0x0F0F0F0F0F0F0F0FULL) << 4) | ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL);
3498 x = _byteswap_uint64(x);
3499 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 3502 ((x & 0xFF00U) << 40) |
3503 ((x & 0xFF0000U) << 24) |
3504 ((x & 0xFF000000U) << 8) |
3505 ((x >> 8) & 0xFF000000U) |
3506 ((x >> 24) & 0xFF0000U) |
3507 ((x >> 40) & 0xFF00U) |
3510 x = __builtin_bswap64(x);
3524 #if defined(_MSC_VER) 3525 #if defined(n_EXPORTS) 3526 #undef NLIB_VIS_PUBLIC 3527 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 3528 #elif defined(nx_misc_EXPORTS) 3529 # undef NLIB_VIS_PUBLIC 3530 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 3534 #endif // INCLUDE_NN_NLIB_PLATFORM_H_
Structure to store the settings and current status of a message queue.