nlib
|
The most basic nlib API that has C linkage. More...
Files | |
file | Platform.h |
Basic APIs are declared with a C linkage. | |
Classes | |
struct | nlib_timerspec |
Specifies the time to elapse before the timer initially starts up and the interval between the subsequent startups. If 0 is specified for the both values, the timer stops. More... | |
struct | nlib_mq_attr |
Structure to store the settings and current status of a message queue. More... | |
Macros | |
#define | RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL |
Defines a value somewhat smaller than the maximum value of size_t . More... | |
Typedefs | |
typedef unsigned char | nlib_byte_t |
This type will be defined as std::byte in a typedef of C++17 or later. | |
typedef int32_t | nlib_long_compatible_t |
Defines an integer type that is compatible with long using typedef . | |
typedef uint32_t | nlib_ulong_compatible_t |
Defines an integer type that is compatible with unsigned long using typedef . | |
Version | |
Macros and functions for getting the | |
#define | NLIB_VERSION 20170516 |
Defines the version number. Defines numerical values that correspond to the year, month, and day of the release. | |
#define | NLIB_VERSION_YEAR 2017 |
Defines an integer that corresponds to the year portion of the version number. | |
#define | NLIB_VERSION_YEAR_SHORT 17 |
Defines an integer that corresponds to the lower two digits of the year portion of the version number. | |
#define | NLIB_VERSION_DATE 0516 |
Defines an integer that corresponds to the month portion of the version number. | |
#define | nlib_getversion NLIB_CAPI(nlib_getversion) |
Dynamically gets the nlib version. More... | |
#define | nlib_compiler_version NLIB_CAPI(nlib_compiler_version) |
Dynamically obtains the compiler version used to compile nlib. More... | |
CRC-32, CRC-32C | |
Calculates quickly using dedicated instructions if SSE or NEON is available. | |
uint32_t | nlib_crc32 (uint32_t crc32, const void *p, size_t n) |
This function calculates the CRC-32 checksum value for data. More... | |
uint32_t | nlib_crc32c (uint32_t crc32c, const void *p, size_t n) |
This function calculates the CRC-32C checksum value for data. More... | |
Memory Fences | |
Low-level primitives for synchronizing memory access when programming for multicore processors. | |
#define | NLIB_MEMORY_ORDER_RELEASE __atomic_thread_fence(__ATOMIC_RELEASE) |
A memory fence. Corresponds to atomic_thread_fence(memory_order_release) in C++11. | |
#define | NLIB_MEMORY_ORDER_ACQUIRE __atomic_thread_fence(__ATOMIC_ACQUIRE) |
A memory fence. Corresponds to atomic_thread_fence(memory_order_acquire) in C++11. | |
#define | NLIB_MEMORY_ORDER_ACQ_REL __atomic_thread_fence(__ATOMIC_ACQ_REL) |
A memory fence. Corresponds to atomic_thread_fence(memory_order_acq_rel) in C++11. | |
#define | NLIB_MEMORY_ORDER_SEQ_CST __atomic_thread_fence(__ATOMIC_SEQ_CST) |
A memory fence. Corresponds to atomic_thread_fence(memory_order_seq_cst) in C++11. | |
Attributes | |
A macro for handling differences in attributes in every compiler. | |
#define | NLIB_WARN(exp) ("WARNING: " exp) |
Outputs a warning. More... | |
#define | NLIB_ALWAYS_INLINE inline __attribute__((always_inline)) |
Indicates that the compiler is forced to perform inline expansion of functions. More... | |
#define | NLIB_NEVER_INLINE __attribute__((__noinline__)) |
Indicates that the compiler does not perform inline expansion of functions. More... | |
#define | NLIB_LIKELY(x) __builtin_expect(!!(x), 1) |
Indicates to the compiler that condition x is likely to be true. More... | |
#define | NLIB_UNLIKELY(x) __builtin_expect(!!(x), 0) |
Indicates to the compiler that condition x is likely to be false. More... | |
#define | NLIB_CHECK_RESULT __attribute__((warn_unused_result)) |
Indicates that the caller of the function must check the returned value. More... | |
#define | NLIB_NORETURN __attribute__((noreturn)) |
Indicates that the process will not return from functions. More... | |
#define | NLIB_NONNULL __attribute__((nonnull)) |
Indicates that you cannot specify NULL for all arguments. More... | |
#define | NLIB_NONNULL_1 __attribute__((nonnull (1))) |
Indicates that you cannot specify NULL for the first argument. More... | |
#define | NLIB_NONNULL_2 __attribute__((nonnull (2))) |
Indicates that you cannot specify NULL for the second argument. More... | |
#define | NLIB_NONNULL_3 __attribute__((nonnull (3))) |
Indicates that you cannot specify NULL for the third argument. More... | |
#define | NLIB_NONNULL_4 __attribute__((nonnull (4))) |
Indicates that you cannot specify NULL for the fourth argument. More... | |
#define | NLIB_NONNULL_5 __attribute__((nonnull (5))) |
Indicates that you cannot specify NULL for the fifth argument. More... | |
#define | NLIB_ATTRIBUTE_MALLOC __attribute__((malloc)) |
Defines __attribute__((malloc)) if it is available for use. More... | |
#define | NLIB_ATTRIBUTE_PURE __attribute__((pure)) |
Defines __attribute__((pure)) if it is available for use. More... | |
#define | NLIB_ATTRIBUTE_CONST __attribute__((const)) |
Defines __attribute__((const)) if it is available for use. More... | |
#define | NLIB_DEPRECATED __attribute__((deprecated)) |
Indicates that a function or something has been deprecated. More... | |
#define | NLIB_DEPRECATED_MSG(msg) __attribute__((deprecated)) |
Indicates that a function or something has been deprecated. More... | |
#define | NLIB_WEAKSYMBOL __attribute__((weak)) |
Used for defining weak symbols. More... | |
#define | NLIB_VIS_HIDDEN __attribute__((visibility("hidden"))) |
Symbols for functions and classes are not made available outside of the library. More... | |
#define | NLIB_VIS_PUBLIC __attribute__((visibility("default"))) |
Symbols for functions and classes are made available outside of the library. More... | |
#define | NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else __builtin_unreachable() /* NOLINT */ |
Indicates that cond is true and provides tips for optimizing the compiler. More... | |
Macros for evaluating the environment | |
#define | NLIB_LITTLE_ENDIAN |
Defined if the environment is little endian-based. | |
#define | NLIB_64BIT |
Defined if the environment is 64-bit architecture-based. | |
Errors | |
#define | nlib_get_native_last_error NLIB_CAPI(nlib_get_native_last_error) |
Returns the last generated native error code. More... | |
const char * | nlib_error_string (errno_t e) |
Returns a string literal corresponding to the error value of nlib . More... | |
template<class T > | |
bool | nlib_is_error (const T &obj) noexcept |
Returns true when the process result or object status is in an erroneous condition. More... | |
typedef int | errno_t |
Indicates with an int -type typedef that a POSIX error value is returned as the return value. | |
Time and Duration | |
Functions for getting times and durations, and sleeping based on times and durations. | |
errno_t | nlib_epochtime (nlib_time *t) |
Gets the current time. More... | |
errno_t | nlib_ticktime (nlib_duration *t) |
Gets the elapsed time since the system was last started. More... | |
errno_t | nlib_sleep (nlib_duration t) |
Sleeps for the duration of t. More... | |
static errno_t | nlib_epochtime_timespec (struct timespec *tm) |
A version taking the timespec structure as the argument of nlib_epochtime() . | |
static errno_t | nlib_ticktime_timespec (struct timespec *tm) |
A version taking the timespec structure as the argument of nlib_ticktime() . | |
static errno_t | nlib_sleep_timespec (const struct timespec *tm) |
A version taking the timespec structure as the argument of nlib_sleep() . | |
typedef int64_t | nlib_time |
The type expressing the time in increments of 100 ns from the zero starting point of 1970-01-01. A 64-bit signed integer. | |
typedef int64_t | nlib_duration |
The type expressing the time in increments of 100 ns. A 64-bit signed integer. | |
A timer | |
errno_t | nlib_timer_create (nlib_timer *timer, nlib_timer_callback callback, void *param, uint32_t flags) |
Creates a timer. More... | |
errno_t | nlib_timer_settime (nlib_timer timer, const nlib_timerspec *new_value, nlib_timerspec *old_value) |
Starts or suspends the timer. More... | |
errno_t | nlib_timer_gettime (nlib_timer timer, nlib_timerspec *curr_value) |
Obtains the current timer settings. More... | |
errno_t | nlib_timer_delete (nlib_timer timer, int wait_completion, nlib_timer_callback completion_callback) |
Deletes a timer. More... | |
typedef uint32_t | nlib_timer |
The ID of the timer used with nlib_timer_create() and nlib_timer_delete() . | |
typedef void(* | nlib_timer_callback) (nlib_timer timer, void *param) |
The type of callback functions set with nlib_timer_create() . | |
nlib_duration | nlib_timerspec::due_time |
Specifies the time to elapse before the timer initially starts up. | |
nlib_duration | nlib_timerspec::interval |
Specifies the interval between the startups of the timer following its initial startup. If 0 is specified, the time works as a one-shot timer. | |
Random Value Generation | |
NLIB_CHECK_RESULT errno_t | nlib_gen_random (void *buf, size_t size) |
Generates a random value of size bytes and stores it in buf. More... | |
Allocation of Memory From the Operating System | |
Allows OS to allocate and free virtual memory spaces and to allocate and free physical memory. | |
errno_t | nlib_mempagesize (size_t *size) |
Gets the page size. More... | |
errno_t | nlib_virtual_alloc (void **ptr, size_t size) |
Allocates virtual memory address space. More... | |
errno_t | nlib_virtual_free (void *ptr, size_t size) |
Frees the allocated virtual memory address space. More... | |
errno_t | nlib_physical_alloc (void *ptr, size_t size, int prot) |
Allocates physical memory. More... | |
errno_t | nlib_physical_free (void *ptr, size_t size) |
Frees the allocated physical memory. More... | |
errno_t | nlib_mlock (void *addr, size_t len) |
The specified memory region is not swapped out. More... | |
errno_t | nlib_munlock (void *addr, size_t len) |
The specified memory region can be swapped out. More... | |
TLS | |
Thread local storage (TLS) is a mechanism for accessing different memory for each thread. | |
#define | NLIB_TLS_INVALID (nlib_tls)(-1) |
Value indicating the ID of an invalid TLS slot. | |
NLIB_CHECK_RESULT errno_t | nlib_tls_alloc (nlib_tls *tls, nlib_tls_destructor destr) |
Allocates a new ID for the specified TLS slot. More... | |
errno_t | nlib_tls_free (nlib_tls tls) |
Frees the ID corresponding to the TLS slot. More... | |
errno_t | nlib_tls_setvalue (nlib_tls tls, const void *value) |
Stores a value in a TLS slot. More... | |
errno_t | nlib_tls_getvalue (nlib_tls tls, void **value) |
Gets the value from a TLS slot. More... | |
typedef pthread_key_t | nlib_tls |
The type for TLS slot IDs. | |
typedef void(* | nlib_tls_destructor) (void *tls_value) |
The type for the TLS destructor function called when the thread is ended. More... | |
Spinlock | |
#define | NLIB_SPINLOCK_INITIALIZER (0) |
Macro for statically initializing nlib_spinlock. | |
static void | nlib_spinlock_init (nlib_spinlock *lock) |
Initializes the spinlock. More... | |
static void | nlib_spinlock_lock (nlib_spinlock *lock) |
Locks the spinlock. Behavior is undefined if a recursive lock is performed. More... | |
static errno_t | nlib_spinlock_trylock (nlib_spinlock *lock) |
Locks the spinlock. Returns 0 if successful or EBUSY if fails. More... | |
static void | nlib_spinlock_unlock (nlib_spinlock *lock) |
Unlocks the spinlock. More... | |
typedef int32_t | nlib_spinlock |
Spinlock variable type. Used by statically initializing with NLIB_SPINLOCK_INITIALIZER . More... | |
Mutex | |
#define | NLIB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER |
A macro for statically initializing nlib_mutex . | |
#define | NLIB_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
A macro for statically initializing nlib_mutex . Makes it a recursive mutex. | |
#define | NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
A macro for statically initializing nlib_mutex . Makes it a recursive mutex that can time out. | |
errno_t | nlib_mutex_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex) |
Initializes a mutex. More... | |
errno_t | nlib_mutex_recursive_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex) |
Initializes a recursive mutex. More... | |
errno_t | nlib_mutex_recursive_timed_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex) |
Initializes a mutex that is recursive and can time out. More... | |
errno_t | nlib_mutex_lock (nlib_mutex *mutex) NLIB_ACQUIRE(*mutex) |
Locks the specified mutex. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mutex_trylock (nlib_mutex *mutex) NLIB_TRY_ACQUIRE(0 |
Locks mutex, but only if it is not locked. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mutex_trylock_for (nlib_mutex *mutex, nlib_duration delta) NLIB_TRY_ACQUIRE(0 |
Locks the specified mutex. Times out. More... | |
static errno_t | nlib_mutex_trylock_for_timespec (nlib_mutex *mutex, const struct timespec *tm) NLIB_TRY_ACQUIRE(0 |
A version taking the timespec structure as the argument of nlib_mutex_trylock_for() . | |
errno_t | nlib_mutex_unlock (nlib_mutex *mutex) NLIB_RELEASE(*mutex) |
Unlocks the specified mutex. More... | |
errno_t | nlib_mutex_destroy (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex) |
Destroys the specified mutex object and frees any associated resources. More... | |
typedef pthread_mutex_t | nlib_mutex |
The type for mutex variables. More... | |
Semaphores | |
errno_t | nlib_semaphore_init (nlib_semaphore *sem, int initial_count) |
Initializes the semaphore object specified by sem. More... | |
errno_t | nlib_semaphore_wait (nlib_semaphore *sem) |
Waits until the semaphore count is no longer 0 and decrements the semaphore count by 1. More... | |
NLIB_CHECK_RESULT errno_t | nlib_semaphore_trywait (nlib_semaphore *sem) |
Decrements the semaphore count by 1 if the count is not 0 . More... | |
NLIB_CHECK_RESULT errno_t | nlib_semaphore_trywait_for (nlib_semaphore *sem, nlib_duration duration) |
Decrements the semaphore count by 1 if the count is not 0 . If 0 , waits for the period specified by duration. More... | |
static errno_t | nlib_semaphore_trywait_for_timespec (nlib_semaphore *sem, const struct timespec *tm) |
A version taking the timespec structure as the argument of nlib_semaphore_trywait_for() . | |
errno_t | nlib_semaphore_post (nlib_semaphore *sem, int *previous_count) |
Increments the semaphore count by 1. More... | |
errno_t | nlib_semaphore_post_ex (nlib_semaphore *sem, int release_count, int *previous_count) |
Increments the semaphore count by the amount specified by releaseCount. More... | |
errno_t | nlib_semaphore_destroy (nlib_semaphore *sem) |
Destroys the semaphore count. More... | |
typedef sem_t | nlib_semaphore |
The type for a semaphore object. More... | |
Condition Variables | |
Provides an interface that is based on the | |
#define | NLIB_COND_INITIALIZER PTHREAD_COND_INITIALIZER |
Constant for statically initializing nlib_cond . | |
errno_t | nlib_cond_init (nlib_cond *cond) |
Initializes a condition variable. More... | |
errno_t | nlib_cond_signal (nlib_cond *cond) |
Resumes the execution of one thread that is waiting for condition variable cond. More... | |
errno_t | nlib_cond_broadcast (nlib_cond *cond) |
Resumes the execution of all threads that are waiting for the conditional variable cond. More... | |
errno_t | nlib_cond_wait (nlib_cond *cond, nlib_mutex *mutex) NLIB_REQUIRES(*mutex) |
Unlocks mutex and waits for a condition variable. It then relocks mutex after execution resumes. More... | |
NLIB_CHECK_RESULT errno_t | nlib_cond_wait_for (nlib_cond *cond, nlib_mutex *mutex, nlib_duration duration) NLIB_REQUIRES(*mutex) |
Unlocks mutex and waits for just the duration amount of time for a condition variable. It then relocks mutex after execution resumes. More... | |
static errno_t | nlib_cond_wait_for_timespec (nlib_cond *cond, nlib_mutex *mutex, const struct timespec *tm) NLIB_REQUIRES(*mutex) |
A version taking the timespec structure as the argument of nlib_cond_wait_for() . | |
NLIB_CHECK_RESULT errno_t | nlib_cond_wait_until (nlib_cond *cond, nlib_mutex *mutex, nlib_time abstime) NLIB_REQUIRES(*mutex) |
Unlocks mutex and waits until abstime for a condition variable. It then relocks mutex after execution resumes. More... | |
static errno_t | nlib_cond_wait_until_timespec (nlib_cond *cond, nlib_mutex *mutex, const struct timespec *tm) NLIB_REQUIRES(*mutex) |
A version taking the timespec structure as the argument of nlib_cond_wait_until() . | |
errno_t | nlib_cond_destroy (nlib_cond *cond) |
Destroys a condition variable object. More... | |
typedef pthread_cond_t | nlib_cond |
The type for a condition variable object. More... | |
Read-Write Locks | |
A mechanism for allowing multiple readers to access a read-write lock at the same time, and for allowing only exclusive access by the writer when updating. | |
#define | NLIB_RWLOCK_INITIALIZER |
Constant for statically initializing nlib_rwlock . | |
errno_t | nlib_rwlock_init (nlib_rwlock *rwlock) NLIB_EXCLUDES(*rwlock) |
Initializes a read-write lock object. More... | |
errno_t | nlib_rwlock_destroy (nlib_rwlock *rwlock) NLIB_EXCLUDES(*rwlock) |
Destroys a read-write lock object. More... | |
errno_t | nlib_rwlock_rdlock (nlib_rwlock *rwlock) NLIB_ACQUIRE_SHARED(*rwlock) |
Gets the read lock, and enters the critical section. Blocks until it can get a lock. More... | |
errno_t | nlib_rwlock_tryrdlock (nlib_rwlock *rwlock) NLIB_TRY_ACQUIRE_SHARED(0 |
Gets the read lock, and attempts to enter the critical section. More... | |
errno_t | nlib_rwlock_tryrdlock_for (nlib_rwlock *rwlock, nlib_duration duration) NLIB_TRY_ACQUIRE_SHARED(0 |
Gets the read lock, and attempts to enter the critical section. Times out. More... | |
static errno_t | nlib_rwlock_tryrdlock_for_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE_SHARED(0 |
A version taking the timespec structure as the argument of nlib_rwlock_tryrdlock_for() . | |
errno_t | nlib_rwlock_tryrdlock_until (nlib_rwlock *rwlock, nlib_time abstime) NLIB_TRY_ACQUIRE_SHARED(0 |
Gets the read lock, and attempts to enter the critical section. Times out. More... | |
static errno_t | nlib_rwlock_tryrdlock_until_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE_SHARED(0 |
A version taking the timespec structure as the argument of nlib_rwlock_tryrdlock_until() . | |
errno_t | nlib_rwlock_rdunlock (nlib_rwlock *rwlock) NLIB_RELEASE_SHARED(*rwlock) |
Releases the read lock. More... | |
errno_t | nlib_rwlock_wrlock (nlib_rwlock *rwlock) NLIB_ACQUIRE(*rwlock) |
Gets a write lock, and enters the critical section. Blocks until it can get a lock. More... | |
errno_t | nlib_rwlock_trywrlock (nlib_rwlock *rwlock) NLIB_TRY_ACQUIRE(0 |
Gets a write lock, and attempts to enter the critical section. More... | |
errno_t | nlib_rwlock_trywrlock_for (nlib_rwlock *rwlock, nlib_duration duration) NLIB_TRY_ACQUIRE(0 |
Gets a write lock, and attempts to enter the critical section. Times out. More... | |
static errno_t | nlib_rwlock_trywrlock_for_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE(0 |
A version taking the timespec structure as the argument of nlib_rwlock_trywrlock_for() . | |
errno_t | nlib_rwlock_trywrlock_until (nlib_rwlock *rwlock, nlib_time abstime) NLIB_TRY_ACQUIRE(0 |
Gets a write lock, and attempts to enter the critical section. Times out. More... | |
static errno_t | nlib_rwlock_trywrlock_until_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE(0 |
A version taking the timespec structure as the argument of nlib_rwlock_trywrlock_until() . | |
errno_t | nlib_rwlock_wrunlock (nlib_rwlock *rwlock) NLIB_RELEASE(*rwlock) |
Releases a write lock. More... | |
typedef struct nlib_rwlock_ | nlib_rwlock |
The type for a read-write lock object. More... | |
Conditional Variable for Read-Write Locks | |
#define | NLIB_CONDRWLOCK_INITIALIZER { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER } |
Constant for statically initializing nlib_condrwlock . | |
errno_t | nlib_condrwlock_init (nlib_condrwlock *cond) |
Initializes a read-write lock conditional variable. More... | |
errno_t | nlib_condrwlock_destroy (nlib_condrwlock *cond) |
Destroys a read-write lock conditional variable. More... | |
errno_t | nlib_condrwlock_signal (nlib_condrwlock *cond) |
Resumes the execution of one thread that is waiting for the read-write lock conditional variable cond. More... | |
errno_t | nlib_condrwlock_broadcast (nlib_condrwlock *cond) |
Resumes the execution of all threads that are waiting for the read-write lock conditional variable cond. More... | |
errno_t | nlib_condrwlock_wait (nlib_condrwlock *cond, nlib_rwlock *rwlock, int rdlock) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes. More... | |
errno_t | nlib_condrwlock_wait_for (nlib_condrwlock *cond, nlib_rwlock *rwlock, nlib_duration duration, int rdlock) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes. More... | |
static errno_t | nlib_condrwlock_wait_for_timespec (nlib_condrwlock *cond, nlib_rwlock *rwlock, const struct timespec *tm, int rdlock) |
A version taking the imespec structure as the argument of nlib_condrwlock_wait_for_timespec() . | |
errno_t | nlib_condrwlock_wait_until (nlib_condrwlock *cond, nlib_rwlock *rwlock, nlib_time abstime, int rdlock) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes. More... | |
static errno_t | nlib_condrwlock_wait_until_timespec (nlib_condrwlock *cond, nlib_rwlock *rwlock, const struct timespec *tm, int rdlock) |
A version taking the timespec structure as the argument of nlib_condrwlock_wait_until_timespec() . | |
typedef struct nlib_condrwlock_ | nlib_condrwlock |
Type of the conditional variable for read-write locks. More... | |
Barriers | |
Synchronizes multiple threads to the end of a particular task. Can be used repeatedly. | |
errno_t | nlib_barrier_init (nlib_barrier *barrier, unsigned int count) |
Initializes a barrier object. More... | |
errno_t | nlib_barrier_destroy (nlib_barrier *barrier) |
Destroys a barrier object. More... | |
errno_t | nlib_barrier_wait (nlib_barrier *barrier) |
Waits for a thread. More... | |
typedef struct nlib_barrier_ | nlib_barrier |
The type for a barrier object. More... | |
Macros for Atomic Functions | |
#define | NLIB_ATOMIC_RELAXED __ATOMIC_RELAXED |
Similar to __ATOMIC_RELAXED of gcc or std::memory_order_relaxed of C++11. | |
#define | NLIB_ATOMIC_ACQUIRE __ATOMIC_ACQUIRE |
Similar to __ATOMIC_ACQUIRE of gcc or std::memory_order_acquire of C++11. | |
#define | NLIB_ATOMIC_RELEASE __ATOMIC_RELEASE |
Similar to __ATOMIC_RELEASE of gcc or std::memory_order_release of C++11. | |
#define | NLIB_ATOMIC_ACQ_REL __ATOMIC_ACQ_REL |
Similar to __ATOMIC_ACQ_REL of gcc or std::memory_order_acq_rel of C++11. | |
#define | NLIB_ATOMIC_SEQ_CST __ATOMIC_SEQ_CST |
Similar to __ATOMIC_SEQ_CST of gcc or std::memory_order_seq_cst of C++11. | |
Atomic Functions (32 bit) | |
Specify one of
| |
int32_t | nlib_atomic_load32 (const int32_t *ptr, int memorder) |
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc. | |
void | nlib_atomic_store32 (int32_t *ptr, int32_t val, int memorder) |
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of gcc. | |
int32_t | nlib_atomic_exchange32 (int32_t *ptr, int32_t val, int memorder) |
Swaps values in an atomic operation. Its behavior is similar to the one for __atomic_exchange_n() of gcc. | |
int | nlib_atomic_compare_exchange32 (int32_t *ptr, int32_t *expected, int32_t desired, int weak, int success_memorder, int failure_memorder) |
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n() of gcc. | |
int32_t | nlib_atomic_add_fetch32 (int32_t *ptr, int32_t val, int memorder) |
Adds atomic values. Its behavior is similar to the one for __atomic_add_fetch() of gcc. | |
int32_t | nlib_atomic_sub_fetch32 (int32_t *ptr, int32_t val, int memorder) |
Subtracts atomic values. Its behavior is similar to the one for __atomic_sub_fetch() of gcc. | |
int32_t | nlib_atomic_and_fetch32 (int32_t *ptr, int32_t val, int memorder) |
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_and_fetch() of gcc. | |
int32_t | nlib_atomic_xor_fetch32 (int32_t *ptr, int32_t val, int memorder) |
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_xor_fetch() of gcc. | |
int32_t | nlib_atomic_or_fetch32 (int32_t *ptr, int32_t val, int memorder) |
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_or_fetch() of gcc. | |
int32_t | nlib_atomic_fetch_add32 (int32_t *ptr, int32_t val, int memorder) |
Adds atomic values. Its behavior is similar to the one for __atomic_fetch_add() of gcc. | |
int32_t | nlib_atomic_fetch_sub32 (int32_t *ptr, int32_t val, int memorder) |
Subtracts atomic values. Its behavior is similar to the one for __atomic_fetch_sub() of gcc. | |
int32_t | nlib_atomic_fetch_and32 (int32_t *ptr, int32_t val, int memorder) |
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_fetch_and() of gcc. | |
int32_t | nlib_atomic_fetch_xor32 (int32_t *ptr, int32_t val, int memorder) |
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_fetch_xor() of gcc. | |
int32_t | nlib_atomic_fetch_or32 (int32_t *ptr, int32_t val, int memorder) |
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_fetch_or() of gcc. | |
Atomic Functions (64 bit) | |
Specify one of
| |
int64_t | nlib_atomic_load64 (const int64_t *ptr, int memorder) |
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc. | |
void | nlib_atomic_store64 (int64_t *ptr, int64_t val, int memorder) |
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of gcc. | |
int64_t | nlib_atomic_exchange64 (int64_t *ptr, int64_t val, int memorder) |
Swaps values in an atomic operation. Its behavior is similar to the one for __atomic_exchange_n() of gcc. | |
int | nlib_atomic_compare_exchange64 (int64_t *ptr, int64_t *expected, int64_t desired, int weak, int success_memorder, int failure_memorder) |
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n() of gcc. | |
int64_t | nlib_atomic_add_fetch64 (int64_t *ptr, int64_t val, int memorder) |
Adds atomic values. Its behavior is similar to the one for __atomic_add_fetch() of gcc. | |
int64_t | nlib_atomic_sub_fetch64 (int64_t *ptr, int64_t val, int memorder) |
Subtracts atomic values. Its behavior is similar to the one for __atomic_sub_fetch() of gcc. | |
int64_t | nlib_atomic_and_fetch64 (int64_t *ptr, int64_t val, int memorder) |
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_and_fetch() of gcc. | |
int64_t | nlib_atomic_xor_fetch64 (int64_t *ptr, int64_t val, int memorder) |
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_xor_fetch() of gcc. | |
int64_t | nlib_atomic_or_fetch64 (int64_t *ptr, int64_t val, int memorder) |
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_or_fetch() of gcc. | |
int64_t | nlib_atomic_fetch_add64 (int64_t *ptr, int64_t val, int memorder) |
Adds atomic values. Its behavior is similar to the one for __atomic_fetch_add() of gcc. | |
int64_t | nlib_atomic_fetch_sub64 (int64_t *ptr, int64_t val, int memorder) |
Subtracts atomic values. Its behavior is similar to the one for __atomic_fetch_sub() of gcc. | |
int64_t | nlib_atomic_fetch_and64 (int64_t *ptr, int64_t val, int memorder) |
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_fetch_and() of gcc. | |
int64_t | nlib_atomic_fetch_xor64 (int64_t *ptr, int64_t val, int memorder) |
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_fetch_xor() of gcc. | |
int64_t | nlib_atomic_fetch_or64 (int64_t *ptr, int64_t val, int memorder) |
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_fetch_or() of gcc. | |
Atomic Functions (pointer type) | |
Specify one of
| |
void * | nlib_atomic_loadptr (void *const *ptr, int memorder) |
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc. | |
void | nlib_atomic_storeptr (void **ptr, void *val, int memorder) |
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of gcc. | |
void * | nlib_atomic_exchangeptr (void **ptr, void *val, int memorder) |
Swaps values in an atomic manner. Its behavior is similar to the one for __atomic_exchange_n() of gcc. | |
int | nlib_atomic_compare_exchangeptr (void **ptr, void **expected, void *desired, int weak, int success_memorder, int failure_memorder) |
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n() of gcc. | |
Memory Barrier | |
Specify one of
| |
void | nlib_atomic_thread_fence (int memorder) |
Places the specified memory barrier. | |
One-Time Execution | |
A mechanism for guaranteeing that a particular process is executed only once. | |
#define | NLIB_ONCE_INIT { 0 } |
The value for statically initializing nlib_onceflag . | |
errno_t | nlib_once (nlib_onceflag *flag, nlib_oncefunc func) |
Ensures that func is executed only one time at most. More... | |
typedef struct nlib_onceflag_ | nlib_onceflag |
The structure to use with nlib_once . | |
typedef void(* | nlib_oncefunc) (void) |
The type for functions to execute with nlib_once . | |
Message Queue | |
See | |
NLIB_CHECK_RESULT errno_t | nlib_mq_open (nlib_mq *mq, const nlib_mq_attr *attr) |
Creates a message queue to be used to exchange messages across threads. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_getattr (nlib_mq mq, nlib_mq_attr *attr) |
Obtains the attribute set to the message queue indicated with a handle. More... | |
errno_t | nlib_mq_close (nlib_mq mq) |
Closes the message queue indicated with a handle. More... | |
errno_t | nlib_mq_readonly (nlib_mq mq) |
Sets the message queue indicated with a handle as receive-only. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_send (nlib_mq mq, nlib_mq_msg msg, int prio) |
Sends a message to a queue. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_send_until (nlib_mq mq, nlib_mq_msg msg, int prio, nlib_time abstime) |
Sends a messages with a time-out set to the queue. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_receive (nlib_mq mq, nlib_mq_msg *msg, int *prio) |
Receives a message from a queue. It is the user's responsibility to delete the received messages using a destructor function. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_receive_until (nlib_mq mq, nlib_mq_msg *msg, int *prio, nlib_time abstime) |
Receives a message with a time-out set from a queue. It is the user's responsibility to delete the received messages using a destructor function. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mq_drop (nlib_mq mq, nlib_mq_msg *msg, int *prio) |
Receives a message with the lowest priority from a queue. It is the user's responsibility to delete the received messages using a destructor function. More... | |
typedef int32_t | nlib_mq |
Handle associated with a message queue. If the handle is cleared to zero (using memset() ), it will always be an invalid handle. | |
typedef void * | nlib_mq_msg |
Type of messages stored in a message queue. | |
typedef void(* | nlib_mq_msg_destructor) (nlib_mq_msg) |
Destructor function for messages taken from a message queue. | |
int32_t | nlib_mq_attr::flag |
Settings to be used when creating a message queue. More... | |
int32_t | nlib_mq_attr::max_msg |
When creating a message queue, you can set the maximum number of messages. | |
int32_t | nlib_mq_attr::cur_msg |
For a queue other than a lock-free queue, you can obtain the number of messages that are currently in that message queue. | |
nlib_mq_msg_destructor | nlib_mq_attr::destructor |
A destructor function for a message taken from a message queue can be set or obtained. | |
Threads | |
#define | NLIB_THREAD_INVALID (nlib_thread)(0) |
Value indicating an invalid thread. | |
#define | nlib_yield NLIB_CAPI(nlib_yield) |
Relinquishes thread execution rights. More... | |
#define | nlib_thread_exit NLIB_CAPI(nlib_thread_exit) |
Ends the called thread. More... | |
#define | nlib_thread_exit_cpp NLIB_CAPI(nlib_thread_exit_cpp) |
Ends the called thread. More... | |
static void | nlib_pause (void) |
Waits for a very short time. More... | |
NLIB_CHECK_RESULT errno_t | nlib_thread_create (nlib_thread *thread, const nlib_thread_attr *attr, nlib_thread_func func, void *arg) |
Creates and executes a new thread. More... | |
errno_t | nlib_thread_join (nlib_thread thread) |
Waits for the thread to terminate. More... | |
errno_t | nlib_thread_detach (nlib_thread thread) |
Detaches an executing thread. More... | |
errno_t | nlib_thread_self (nlib_thread *thread) |
Stores the nlib_thread value corresponding to the executing thread. More... | |
errno_t | nlib_thread_getconcurrency (unsigned int *num_cpu) |
Gets the number of hardware threads. More... | |
errno_t | nlib_thread_getid (nlib_thread_id *id) |
Stores a unique integer value corresponding to the executing thread. More... | |
int | nlib_thread_equal (nlib_thread th1, nlib_thread th2) |
Checks whether two threads point to the same thread. More... | |
errno_t | nlib_thread_getcpu (int *result) |
Gets the CPU on which the called thread is executing. More... | |
errno_t | nlib_thread_setaffinity (nlib_thread thread, uint32_t affinity) |
Sets a processor affinity mask for the specified thread. More... | |
errno_t | nlib_thread_setname (nlib_thread thread, const char *name) |
Attaches a name to the thread. More... | |
errno_t | nlib_thread_getname (nlib_thread thread, char *name, size_t len) |
Gets the thread name. More... | |
errno_t | nlib_thread_attr_init (nlib_thread_attr *attr) |
Initializes a thread attribute object and sets it to the default. More... | |
errno_t | nlib_thread_attr_setint (nlib_thread_attr *attr, int key, int value) |
Sets an integer corresponding to the key of the thread attribute object. More... | |
errno_t | nlib_thread_attr_getint (const nlib_thread_attr *attr, int key, int *value) |
Gets the integer corresponding to the key of the thread attribute object. More... | |
errno_t | nlib_thread_attr_setptr (nlib_thread_attr *attr, int key, void *value) |
Sets a pointer corresponding to the key of the thread attribute object. As of now, returns EINVAL only. More... | |
errno_t | nlib_thread_attr_getptr (const nlib_thread_attr *attr, int key, void **value) |
Gets the pointer corresponding to the key of the thread attribute object. As of now, returns EINVAL only. More... | |
errno_t | nlib_thread_attr_setstack (nlib_thread_attr *attr, void *stack_addr, size_t stack_size) |
Sets a stack setting for thread attribute objects. More... | |
errno_t | nlib_thread_attr_getstack (const nlib_thread_attr *attr, void **stack_addr, size_t *stack_size) |
Obtains a stack setting for thread attribute objects. More... | |
errno_t | nlib_thread_attr_destroy (nlib_thread_attr *attr) |
Destroys a thread-initialization object. More... | |
errno_t | nlib_thread_getpriority (nlib_thread thread, int *priority) |
Gets the current execution priority of the thread. The meaning of the numerical value is implementation-dependent. More... | |
errno_t | nlib_thread_setpriority (nlib_thread thread, int priority) |
Sets the execution priority of the thread. The meaning of the numerical value is implementation-dependent. More... | |
errno_t | nlib_thread_priority_min (int *priority) |
Gets the smallest numerical value that can be specified for the execution priority. More... | |
errno_t | nlib_thread_priority_max (int *priority) |
Gets the largest numerical value that can be specified for the execution priority. More... | |
errno_t | nlib_thread_priority_default (int *priority) |
Gets the default numerical value that can be specified for the execution priority. More... | |
void | nlib_thread_cleanup_push (void(*fn)(void *), void *arg) |
Pushes fn to a dedicated stack. More... | |
void | nlib_thread_cleanup_pop (int exec) |
Deletes the handler at the top of the stack storing the cleanup handler. More... | |
typedef pthread_t | nlib_thread |
The identifier for threads. More... | |
typedef struct nlib_thread_attr_ | nlib_thread_attr |
The thread attribute to apply to a newly created thread. | |
typedef void(* | nlib_thread_func) (void *arg) |
A function to be run on a different thread. More... | |
typedef int | nlib_thread_id |
A unique integer value for each thread. | |
Debugging and Debug Output | |
#define | nlib_debug_break NLIB_CAPI(nlib_debug_break) |
A breakpoint. More... | |
errno_t | nlib_write_stdout (size_t *result, const void *buf, size_t count) |
Writes a string to standard output. More... | |
errno_t | nlib_write_stderr (size_t *result, const void *buf, size_t count) |
Writes a string to standard error output. More... | |
errno_t | nlib_debug_backtrace (size_t *result, void **buffer, size_t count) |
Stores backtraces in the array specified by buffer. More... | |
errno_t | nlib_debug_backtrace_gettext (char *str, size_t strbufsize, void *const *buf, size_t count) |
Creates string information from the data obtained using the nlib_debug_backtrace function. More... | |
errno_t | nlib_getenv (size_t *result, char *buf, size_t bufsize, const char *varname) |
Gets the value for the environment variable as a string. More... | |
Logging | |
kNlibLogVerbose | |
Specifies the output of verbose messages. More... | |
kNlibLogDebug | |
Specifies the output of debug-level messages. More... | |
kNlibLogInfo | |
Specifies the output of information-level messages. More... | |
kNlibLogWarn | |
Specifies the output of warning-level messages. More... | |
kNlibLogError | |
Specifies the output of error-level messages. More... | |
kNlibLogFatal | |
Specifies the output of fatal-level messages. More... | |
kNlibLogLevelEqualOrAbove = 0x10 | |
Uses a bitwise OR to output levels at and above the specified level. Can be used with the nlib_log_attr_setint function. More... | |
kNlibLogLevelEqualOrBelow = 0x20 | |
Uses a bitwise OR to output levels at and below the specified level. Can be used with the nlib_log_attr_setint function. More... | |
kNlibLogLevelAll = 0x30 | |
Specifies all priority levels. Can be used with the nlib_log_attr_setint function. More... | |
enum | nlib_log_priority { , kNlibLogVerbose, kNlibLogDebug, kNlibLogInfo, kNlibLogWarn, kNlibLogError, kNlibLogFatal , kNlibLogLevelEqualOrAbove = 0x10, kNlibLogLevelEqualOrBelow = 0x20, kNlibLogLevelAll = 0x30 } |
Defines the priority (level category) for output. More... | |
int | nlib_log_print (int prio, const char *tag, const char *fmt,...) |
Outputs log messages. More... | |
int | nlib_log_vprint (int prio, const char *tag, const char *fmt, va_list ap) |
Outputs log messages. More... | |
errno_t | nlib_log_attr_setint (int prio, int key, int value) |
Specifies where to output the log for each level of priority. More... | |
kNlibLogVerbose | |
Specifies the output of verbose messages. More... | |
kNlibLogDebug | |
Specifies the output of debug-level messages. More... | |
kNlibLogInfo | |
Specifies the output of information-level messages. More... | |
kNlibLogWarn | |
Specifies the output of warning-level messages. More... | |
kNlibLogError | |
Specifies the output of error-level messages. More... | |
kNlibLogFatal | |
Specifies the output of fatal-level messages. More... | |
kNlibLogLevelEqualOrAbove = 0x10 | |
Uses a bitwise OR to output levels at and above the specified level. Can be used with the nlib_log_attr_setint function. More... | |
kNlibLogLevelEqualOrBelow = 0x20 | |
Uses a bitwise OR to output levels at and below the specified level. Can be used with the nlib_log_attr_setint function. More... | |
kNlibLogLevelAll = 0x30 | |
Specifies all priority levels. Can be used with the nlib_log_attr_setint function. More... | |
Files | |
#define | NLIB_FD_O_RDONLY O_RDONLY |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_WRONLY O_WRONLY |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_RDWR O_RDWR |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_APPEND O_APPEND |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_CREAT O_CREAT |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_TRUNC O_TRUNC |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_FD_O_EXCL O_EXCL |
Used for the flags parameter of the nlib_fd_open function. | |
#define | NLIB_SEEK_SET SEEK_SET |
Used for the whence parameter of the nlib_fd_seek function. | |
#define | NLIB_SEEK_CUR SEEK_CUR |
Used for the whence parameter of the nlib_fd_seek function. | |
#define | NLIB_FD_INVALID (-1) |
A macro defining invalid file descriptors. | |
errno_t | nlib_fd_open (nlib_fd *fd, const char *native_path, unsigned int flags, int mode) |
Opens a file. More... | |
static NLIB_CHECK_RESULT errno_t | nlib_fd_creat (nlib_fd *fd, const char *native_path, int mode) |
Equivalent to nlib_fd_open(fd, native_path, NLIB_FD_O_CREAT | NLIB_FD_O_WRONLY | NLIB_FD_O_EXCL, mode) . Note that it fails if the file already exists. | |
NLIB_CHECK_RESULT errno_t | nlib_fd_close (nlib_fd fd) |
Closes a file. The file descriptor will be released even if an error is returned. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_read (size_t *result, nlib_fd fd, void *buf, size_t count) |
Reads (up to) count bytes from the file descriptor into buf. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_write (size_t *result, nlib_fd fd, const void *buf, size_t count) |
Writes (up to) count bytes from buf to the file descriptor. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_seek (nlib_offset *result, nlib_fd fd, nlib_offset offset, int whence) |
Changes the file offset. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_pread (size_t *result, nlib_fd fd, void *buf, size_t count, nlib_offset offset) |
Reads the file descriptor from the specified offset. The offset for the file descriptor will not be changed. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_pwrite (size_t *result, nlib_fd fd, const void *buf, size_t count, nlib_offset offset) |
Writes to the file descriptor at the specified offset. The offset for the file descriptor will not be changed. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_truncate (nlib_fd fd, nlib_offset length) |
Extends or truncates the file to be the specified size. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_getsize (nlib_offset *size, nlib_fd fd) |
Gets the file size. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_flush (nlib_fd fd) |
Flushes the write to the file descriptor. More... | |
errno_t | nlib_fd_sync (nlib_fd fd) |
Synchronizes the content of a file in memory with what is on the device. More... | |
errno_t | nlib_fd_native_handle (void **native_handle, nlib_fd fd) |
Gets (the equivalent of) the native file handle. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_readv (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt) |
Loads multiple non-continuous buffers from the file associated with fd. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_writev (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt) |
Writes from multiple non-continuous buffers to the file associated with fd. More... | |
NLIB_CHECK_RESULT errno_t | nlib_fd_preadv (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt, nlib_offset offset) |
Same as the nlib_fd_readv function except when the pread or nlib_fd_pread function is used internally. | |
NLIB_CHECK_RESULT errno_t | nlib_fd_pwritev (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt, nlib_offset offset) |
Same as the nlib_fd_writev function except when the pwrite or nlib_fd_pwrite function is used internally. | |
NLIB_CHECK_RESULT errno_t | nlib_unlink (const char *native_path) |
Deletes a file. More... | |
NLIB_CHECK_RESULT errno_t | nlib_mkdir (const char *native_path, unsigned int flags) |
Creates a directory. More... | |
NLIB_CHECK_RESULT errno_t | nlib_rmdir (const char *native_path) |
Deletes a directory. More... | |
NLIB_CHECK_RESULT errno_t | nlib_remove (const char *native_path) |
Deletes a file or directory. Calls nlib_unlink() for a file, or nlib_rmdir() for a directory. | |
NLIB_CHECK_RESULT errno_t | nlib_rename (const char *old_path, const char *new_path) |
Renames a file. More... | |
NLIB_CHECK_RESULT errno_t | nlib_dir_open (nlib_dir *dir, const char *native_path) |
Opens a directory. More... | |
errno_t | nlib_dir_close (nlib_dir dir) |
Closes a directory. More... | |
NLIB_CHECK_RESULT errno_t | nlib_dir_read (nlib_dirent *ent, nlib_dir dir) |
Reads one directory entry, if there are any. More... | |
errno_t | nlib_is_dir (int *result, const char *native_path) |
Checks whether the path is for a directory. Sets 0 in *result and returns 0 if no path exists. More... | |
errno_t | nlib_exist_path (int *result, const char *native_path) |
Checks whether the path exists. More... | |
errno_t | nlib_disk_freespace (const char *native_path, uint64_t *free_bytes_available, uint64_t *total_bytes, uint64_t *total_free_bytes) |
Gets information related to the capacity of the storage region to which the specified path belongs. More... | |
const char * | nlib_basename (const char *path) |
const char * | nlib_dirname (size_t *len, const char *path) |
errno_t | nlib_mkostemps (nlib_fd *fd, char *templ, int suffixlen, int flags) |
Creates a temporary file with a unique name that is hard to be guessed. More... | |
errno_t | nlib_fd_fileid (nlib_fileid *result, nlib_fd fd) |
errno_t | nlib_readlink (size_t *len, const char *native_path, char *buf, size_t bufsize) |
Resolve a symbolic link. More... | |
typedef int64_t | nlib_offset |
The offset to the file. A 64-bit integer. | |
typedef int | nlib_fd |
The original file descriptor of nlib (a 32-bit integer value). More... | |
printf | |
Functions for handling differences with the standard library
| |
#define | PRIdS __PRIS_PREFIX "d" |
Used when a size_t type is shown by printf . Corresponds to %zd . | |
#define | PRIxS __PRIS_PREFIX "x" |
Used when a size_t type is shown by printf . Corresponds to %zx . | |
#define | PRIuS __PRIS_PREFIX "u" |
Used when a size_t type is shown by printf . Corresponds to %zu . | |
#define | PRIXS __PRIS_PREFIX "X" |
Used when a size_t type is shown by printf . Corresponds to %zX . | |
#define | PRIoS __PRIS_PREFIX "o" |
Used when a size_t type is shown by printf . Corresponds to %zo . | |
errno_t | nlib_vsnprintf (size_t *count, char *buf, size_t size, const char *fmt, va_list args) |
A safer form of vsnprintf , with some differences from standard vsnprintf behavior. More... | |
template<size_t N> | |
errno_t | nlib_vsnprintf (size_t *count, char(&buf)[N], const char *fmt, va_list args) noexcept |
The function template version of nlib_vsnprintf . | |
errno_t | nlib_snprintf (size_t *count, char *buf, size_t size, const char *fmt,...) |
A safer form of snprintf . | |
template<size_t N> | |
errno_t | nlib_snprintf (size_t *count, char(&buf)[N], const char *fmt,...) noexcept |
The function template version of nlib_snprintf . | |
errno_t | nlib_vdprintf (nlib_fd fd, size_t *count, const char *fmt, va_list args) |
The version of the vsnprintf function that outputs to a file descriptor. | |
errno_t | nlib_dprintf (nlib_fd fd, size_t *count, const char *fmt,...) |
The version of the snprintf function that outputs to a file descriptor. | |
int | nlib_printf (const char *fmt,...) |
The substitute for the printf function. | |
errno_t | nlib_vsnwprintf (size_t *count, wchar_t *buf, size_t size, const wchar_t *fmt, va_list args) |
A safer form of vswprintf , with some differences from standard vswprintf behavior. More... | |
template<size_t N> | |
errno_t | nlib_vsnwprintf (size_t *count, wchar_t(&buf)[N], const wchar_t *fmt, va_list args) noexcept |
The function template version of nlib_vsnwprintf . | |
errno_t | nlib_snwprintf (size_t *count, wchar_t *buf, size_t size, const wchar_t *fmt,...) |
A safer form of snwprintf . | |
template<size_t N> | |
errno_t | nlib_snwprintf (size_t *count, wchar_t(&buf)[N], const wchar_t *fmt,...) noexcept |
The function template version of nlib_snwprintf . | |
errno_t | nlib_vdwprintf (nlib_fd fd, size_t *count, const wchar_t *fmt, va_list args) |
The version of the vsnwprintf function that outputs to a file descriptor. | |
errno_t | nlib_dwprintf (nlib_fd fd, size_t *count, const wchar_t *fmt,...) |
The version of the snwprintf function that outputs to a file descriptor. | |
int | nlib_wprintf (const wchar_t *fmt,...) |
The substitute for the wprintf function. | |
Copying, comparing, and exploring a memory region. | |
static errno_t | nlib_memcpy (void *s1, size_t s1max, const void *s2, size_t n) |
An implementation corresponding to N1078 memcpy_s . More... | |
static errno_t | nlib_memmove (void *s1, size_t s1max, const void *s2, size_t n) |
An implementation corresponding to N1078 memmove_s . More... | |
static errno_t | nlib_memset (void *buf, int ch, size_t n) |
Makes a function call corresponding to memset(buf, ch, n) . More... | |
void * | nlib_memccpy (void *dest, size_t dest_size, const void *src, size_t src_size, int c) |
Continues copying until c is found. Stops copying when it is found. More... | |
int | nlib_memcmp (const void *buf1, const void *buf2, size_t n) |
Compares the n bytes from the starts of buf1 and buf2 as unsigned char data. More... | |
const void * | nlib_memchr (const void *s, int c, size_t n) |
Searches the n bytes from the start of the memory region (s, s + n) and returns a pointer to byte c. More... | |
const void * | nlib_memrchr (const void *s, int c, size_t n) |
Searches the n bytes from the end of memory region (s, s + n) and returns a pointer to byte c. More... | |
const void * | nlib_memchr_not (const void *s, int c, size_t n) |
Searches the n bytes from the start of memory region(s, s + n) and returns a pointer that does not point to byte c. More... | |
const void * | nlib_memchr_range_not (const void *s, const char *range, size_t n) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to a character not contained in range. More... | |
const void * | nlib_memchr_lt (const void *s, int c, size_t n) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to data having a character less than byte c. More... | |
const void * | nlib_memchr_gt (const void *s, int c, size_t n) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to data having a character larger than byte c. More... | |
const void * | nlib_memchr_mb (const void *s, size_t n) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to the location where 0x80 or more bytes is stored. More... | |
size_t | nlib_memspn (const void *buf, size_t len, const char *set, size_t n) |
Returns the length of the set of sub-bytes from the beginning of buf. The set of sub-bytes consists of only bytes contained in set. More... | |
size_t | nlib_memcspn (const void *buf, size_t len, const char *set, size_t n) |
Returns the length of the set of sub-bytes from the beginning of buf. The set of sub-bytes consists of bytes other than those contained in set. More... | |
Function for null terminated strings. | |
const char * | nlib_skipws (size_t *cnt_lf, const char **last_lf, const char *s, size_t n) |
Searches a string made up of n characters and returns the pointer to the first character found that is not a white-space character. More... | |
size_t | nlib_strlen (const char *s) |
Internally calls strlen() . In some cases, it may operate as an independent implementation. More... | |
size_t | nlib_strnlen (const char *s, size_t maxsize) |
An implementation corresponding to N1078 strnlen_s . More... | |
errno_t | nlib_strcpy (char *s1, size_t s1max, const char *s2) |
An implementation corresponding to N1078 strcpy_s . More... | |
template<size_t N> | |
errno_t | nlib_strcpy (char(&s1)[N], const char *s2) noexcept |
The function template version of nlib_strcpy . | |
template<size_t N> | |
size_t | nlib_strlcpy (char(&s1)[N], const char *s2) noexcept |
Calls the nlib_strlcpy(s1, s2, N) function. | |
errno_t | nlib_strncpy (char *s1, size_t s1max, const char *s2, size_t n) |
An implementation corresponding to N1078 strncpy_s . More... | |
template<size_t N> | |
errno_t | nlib_strncpy (char(&s1)[N], const char *s2, size_t n) noexcept |
The function template version of nlib_strncpy . | |
const char * | nlib_strchr (const char *s, int c) |
Searches for a character from the start of a string. More... | |
const char * | nlib_strrchr (const char *s, int c) |
Searches for a character from the end of a string. More... | |
size_t | nlib_wcslen (const wchar_t *s) |
Makes a call to thewcslen function. In some cases, it may operate as an independent implementation. More... | |
size_t | nlib_wcsnlen (const wchar_t *s, size_t maxsize) |
An implementation corresponding to N1078 wcsnlen_s . More... | |
errno_t | nlib_wcscpy (wchar_t *s1, size_t s1max, const wchar_t *s2) |
An implementation corresponding to N1078 wcscpy_s . More... | |
template<size_t N> | |
errno_t | nlib_wcscpy (wchar_t(&s1)[N], const wchar_t *s2) noexcept |
The function template version of nlib_wcscpy . | |
errno_t | nlib_wcsncpy (wchar_t *s1, size_t s1max, const wchar_t *s2, size_t n) |
An implementation corresponding to N1078 wcsncpy_s . More... | |
template<size_t N> | |
errno_t | nlib_wcsncpy (wchar_t(&s1)[N], const wchar_t *s2, size_t n) noexcept |
The function template version of nlib_wcsncpy . | |
Substitute for <tt>strtol()</tt>. | |
Substitutes for | |
errno_t | nlib_strto_int32 (int32_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the int32_t type. More... | |
errno_t | nlib_strto_int64 (int64_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the int64_t type. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_uint32 (uint32_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the uint32_t type. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_uint64 (uint64_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the uint64_t type. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_double (double *result, const char *nptr, char **endptr) |
Converts a string to the double type. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_float (float *result, const char *nptr, char **endptr) |
Converts a string to the float type. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_int32_fallback (int32_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the int32_t type without using a standard C function. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_int64_fallback (int64_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the int64_t type without using a standard C function. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_uint32_fallback (uint32_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the uint32_t type without using a standard C function. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_uint64_fallback (uint64_t *result, const char *nptr, char **endptr, int base) |
Converts a string to the uint64_t type without using a standard C function. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_double_fallback (double *result, const char *nptr, char **endptr) |
Converts a string to the double type without using a standard C function. For details, see nlib_strto_int32() . | |
errno_t | nlib_strto_float_fallback (float *result, const char *nptr, char **endptr) |
Converts a string to the float type without using a standard C function. For details, see nlib_strto_int32() . | |
Substitute for <tt>ctype.h<tt>. | |
A substitute for functions declared in | |
static int | nlib_isalnum (int ch) |
If ch is an ASCII character '0'-'9', 'A'-'Z', or 'a'-'z', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isalpha (int ch) |
If ch is an ASCII character 'A'-'Z' or 'a'-'z', the function returns non-zero. Othewise, the function returns 0. | |
static int | nlib_isblank (int ch) |
If ch is an ASCII character ' ' or '\t', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_iscntrl (int ch) |
If ch is an ASCII code '0'-'31' or '127', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isdigit (int ch) |
If ch is an ASCII character '0'-'9', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isgraph (int ch) |
If ch is an ASCII character '33'-'126', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_islower (int ch) |
If ch is an ASCII character 'a'-'z', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isprint (int ch) |
If ch is an ASCII character '32'-'126', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_ispunct (int ch) |
If ch is an ASCII character '0'-'32' or '127', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isspace (int ch) |
If ch is an ASCII character ' ', '\t', or '\n', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isupper (int ch) |
If ch is an ASCII character 'A'-'Z', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_isxdigit (int ch) |
If ch is an ASCII character '0'-'9', 'A'-'F', or 'a'-'f', the function returns non-zero. Otherwise, the function returns 0. | |
static int | nlib_tolower (int ch) |
If ch is an ASCII character 'A'-'Z', the function returns its lowercase letter. Otherwise, the function returns ch. | |
static int | nlib_toupper (int ch) |
If ch is an ASCII character 'a'-'z', the function returns its uppercase letter. Otherwise, the function returns ch. | |
Unicode | |
Unicode-related functionality is also implemented in the | |
NLIB_CHECK_RESULT int | nlib_utf16_to_utf32char (nlib_utf32_t *utf32, nlib_utf16_t upper, nlib_utf16_t lower) |
Converts a single code point from UTF-16 into UTF-32. More... | |
NLIB_CHECK_RESULT int | nlib_utf32char_to_utf16 (nlib_utf16_t *upper, nlib_utf16_t *lower, nlib_utf32_t utf32) |
Converts a single UTF-32 character into UTF-16. More... | |
NLIB_CHECK_RESULT int | nlib_utf8_to_utf32char (nlib_utf32_t *utf32, const nlib_utf8_t *utf8) |
Converts UTF-8 into one character's worth of UTF-32. More... | |
NLIB_CHECK_RESULT int | nlib_utf32char_to_utf8 (nlib_utf8_t(&utf8)[4], nlib_utf32_t utf32) |
Converts the UTF-32 for one character into UTF-8. More... | |
errno_t | nlib_wide_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const wchar_t *wcstr) |
Converts a UTF-16/UTF-32 string into a UTF-8 string. More... | |
template<size_t N> | |
errno_t | nlib_wide_to_utf8 (size_t *result, nlib_utf8_t(&utf8)[N], const wchar_t *wcstr) noexcept |
The function template version of nlib_wide_to_utf8 . | |
errno_t | nlib_utf8_to_wide (size_t *wccount, wchar_t *wcstr, size_t buflen, const nlib_utf8_t *utf8) |
Converts a UTF-8 string into a UTF-16/UTF-32 string. More... | |
template<size_t N> | |
errno_t | nlib_utf8_to_wide (size_t *result, wchar_t(&wcstr)[N], const nlib_utf8_t *utf8) noexcept |
The function template version of nlib_utf8_to_wide . | |
errno_t | nlib_utf16_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const nlib_utf16_t *utf16) |
Converts a UTF-16 string into a UTF-8 string. More... | |
template<size_t N> | |
errno_t | nlib_utf16_to_utf8 (size_t *utf8count, nlib_utf8_t(&utf8)[N], const nlib_utf16_t *utf16) noexcept |
The function template version of nlib_utf16_to_utf8 . | |
errno_t | nlib_utf8_to_utf16 (size_t *utf16count, nlib_utf16_t *utf16, size_t buflen, const nlib_utf8_t *utf8) |
Converts a UTF-8 string into a UTF-16 string. The UTF-16 string is null-terminated. More... | |
template<size_t N> | |
errno_t | nlib_utf8_to_utf16 (size_t *utf16count, nlib_utf16_t(&utf16)[N], const nlib_utf8_t *utf8) noexcept |
The function template version of nlib_utf8_to_utf16 . | |
errno_t | nlib_utf32_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const nlib_utf32_t *utf32) |
Converts a UTF-32 string into a UTF-8 string. More... | |
template<size_t N> | |
errno_t | nlib_utf32_to_utf8 (size_t *utf8count, nlib_utf8_t(&utf8)[N], const nlib_utf32_t *utf32) noexcept |
The function template version of nlib_utf32_to_utf8 . | |
errno_t | nlib_utf8_to_utf32 (size_t *utf32count, nlib_utf32_t *utf32, size_t buflen, const nlib_utf8_t *utf8) |
Converts a UTF-8 string into a UTF-32 string. More... | |
template<size_t N> | |
errno_t | nlib_utf8_to_utf32 (size_t *utf32count, nlib_utf32_t(&utf32)[N], const nlib_utf8_t *utf8) noexcept |
The function template version of nlib_utf8_to_utf32 . | |
errno_t | nlib_memutf16_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t *to, size_t to_size, const nlib_utf16_t *from, size_t from_size) NLIB_NONNULL_5 |
Converts a UTF-16 string that is not null terminated to a UTF-8 string. More... | |
template<size_t N> | |
errno_t | nlib_memutf16_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const nlib_utf16_t *from, size_t from_size) noexcept |
The function template version of nlib_memutf16_to_utf8() . | |
errno_t | nlib_memutf8_to_utf16 (size_t *to_count, size_t *from_count, nlib_utf16_t *to, size_t to_size, const nlib_utf8_t *from, size_t from_size) NLIB_NONNULL_5 |
Converts a UTF-8 string that is not null terminated to a UTF-16 string. More... | |
template<size_t N> | |
errno_t | nlib_memutf8_to_utf16 (size_t *to_count, size_t *from_count, nlib_utf16_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept |
The function template version of nlib_memutf8_to_utf16() . | |
errno_t | nlib_memutf32_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t *to, size_t to_size, const nlib_utf32_t *from, size_t from_size) NLIB_NONNULL_5 |
Converts a UTF-32 string that is not null terminated to a UTF-8 string. More... | |
template<size_t N> | |
errno_t | nlib_memutf32_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const nlib_utf32_t *from, size_t from_size) noexcept |
The function template version of nlib_memutf32_to_utf8() . | |
errno_t | nlib_memutf8_to_utf32 (size_t *to_count, size_t *from_count, nlib_utf32_t *to, size_t to_size, const nlib_utf8_t *from, size_t from_size) NLIB_NONNULL_5 |
Converts a UTF-8 string that is not null terminated to a UTF-32 string. More... | |
template<size_t N> | |
errno_t | nlib_memutf8_to_utf32 (size_t *to_count, size_t *from_count, nlib_utf32_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept |
The function template version of nlib_memutf8_to_utf32() . | |
errno_t | nlib_memwide_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t *to, size_t to_size, const wchar_t *from, size_t from_size) NLIB_NONNULL_5 |
Depending on the size of wchar_t , nlib_memutf16_to_utf8() or nlib_memutf32_to_utf8() is called. | |
template<size_t N> | |
errno_t | nlib_memwide_to_utf8 (size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const wchar_t *from, size_t from_size) noexcept |
The function template version of nlib_memwide_to_utf8() . | |
errno_t | nlib_memutf8_to_wide (size_t *to_count, size_t *from_count, wchar_t *to, size_t to_size, const nlib_utf8_t *from, size_t from_size) NLIB_NONNULL_5 |
Depending on the size of wchar_t , nlib_memutf8_to_utf16 or nlib_memutf8_to_utf32 is called. | |
template<size_t N> | |
errno_t | nlib_memutf8_to_wide (size_t *to_count, size_t *from_count, wchar_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept |
The function template version of nlib_memutf8_to_wide() . | |
static NLIB_CHECK_RESULT size_t | nlib_utf16len (const nlib_utf16_t *str) |
Counts the number of nlib_utf16_t -type characters, not including the null character. More... | |
static NLIB_CHECK_RESULT size_t | nlib_utf16nlen (const nlib_utf16_t *str, size_t maxsize) |
The UTF-16 version of the nlib_strnlen function. More... | |
static errno_t | nlib_utf16cpy (nlib_utf16_t *s1, size_t s1max, const nlib_utf16_t *s2) |
The UTF-16 version of the nlib_strcpy function. More... | |
static errno_t | nlib_utf16ncpy (nlib_utf16_t *s1, size_t s1max, const nlib_utf16_t *s2, size_t n) |
The UTF-16 version of the nlib_strcpy function. More... | |
static NLIB_CHECK_RESULT size_t | nlib_utf32len (const nlib_utf32_t *str) |
Counts the number of nlib_utf32_t -type characters, not including the null character. More... | |
static NLIB_CHECK_RESULT size_t | nlib_utf32nlen (const nlib_utf32_t *str, size_t maxsize) |
The UTF-32 version of the nlib_strnlen function. More... | |
static errno_t | nlib_utf32cpy (nlib_utf32_t *s1, size_t s1max, const nlib_utf32_t *s2) |
The UTF-32 version of the nlib_strcpy function. More... | |
static errno_t | nlib_utf32ncpy (nlib_utf32_t *s1, size_t s1max, const nlib_utf32_t *s2, size_t n) |
The UTF-32 version of the nlib_strcpy function. More... | |
NLIB_CHECK_RESULT errno_t | nlib_strcplen (size_t *codepoint_count, size_t *supplementary_codepoint_count, size_t *len, const nlib_utf8_t *str) |
Gets the number of code points contained in the string, the number of supplementary characters contained in the string, and the string length. If the function returns EILSEQ , a value, including the number of code points to the point that cannot be converted, is stored. More... | |
NLIB_CHECK_RESULT errno_t | nlib_wcscplen (size_t *count, const wchar_t *str) |
Gets the number of code points in the string. More... | |
static errno_t | nlib_utf16cplen (size_t *count, const nlib_utf16_t *str) |
Gets the number of code points in the string. More... | |
static errno_t | nlib_utf16cplen_ex (size_t *count, size_t *len, const nlib_utf16_t *str) |
Gets the number of code points in the string. More... | |
NLIB_CHECK_RESULT errno_t | nlib_utf32cplen (size_t *count, const nlib_utf32_t *str) |
Gets the number of code points in the string. More... | |
NLIB_CHECK_RESULT errno_t | nlib_memcplen (size_t *codepoint_count, size_t *supplementary_codepoint_count, size_t *from_read, const nlib_utf8_t *from, size_t from_size) |
Gets the number of code points contained in the string and the number of supplementary characters contained in the string.. More... | |
errno_t | nlib_swapendian_16 (uint16_t *p, size_t count) |
Swaps the endianness. More... | |
errno_t | nlib_swapendian_32 (uint32_t *p, size_t count) |
Swaps the endianness. More... | |
errno_t | nlib_swapendian_64 (uint64_t *p, size_t count) |
Swaps the endianness. More... | |
typedef char | nlib_utf8_t |
Defines char with a typedef . Indicates that it is a UTF-8 string. | |
typedef uint16_t | nlib_utf16_t |
Uses typedef to define as char16_t if that can be used. If not, it uses typedef to define as uint16_t . | |
typedef uint32_t | nlib_utf32_t |
Uses typedef to define as char32_t if that can be used. If not, it uses typedef to define as uint32_t . | |
count leading zeros, count trailing zeros, popcnt, bitreverse | |
static int | nlib_clz32 (uint32_t x) |
Returns the number of consecutive zero bits, with respect to the most significant bit (MSB). More... | |
static int | nlib_clz64 (uint64_t x) |
Returns the number of consecutive zero bits, with respect to the most significant bit (MSB). More... | |
static int | nlib_ctz32 (uint32_t x) |
Returns the number of consecutive zero bits, with respect to the least significant bit (LSB). More... | |
static int | nlib_ctz64 (uint64_t x) |
Returns the number of consecutive zero bits, with respect to the least significant bit (LSB). More... | |
static int | nlib_popcnt32 (uint32_t x) |
Returns the number of bits that are 1 . More... | |
static int | nlib_popcnt64 (uint64_t x) |
Returns the number of bits that are 1 . More... | |
static int | nlib_popcnt16 (uint16_t x) |
Returns the number of bits that are 1 . More... | |
static uint32_t | nlib_bitreverse32 (uint32_t x) |
Reverses the bit order within an entire 32-bit integer. More... | |
static uint64_t | nlib_bitreverse64 (uint64_t x) |
Reverses the bit order within an entire 64-bit integer. More... | |
malloc | |
NLIB_CHECK_RESULT void * | nlib_malloc (size_t size) |
A weak function that calls the C standard function malloc . nlib calls malloc via this function. More... | |
void | nlib_free (void *ptr) |
A weak function that calls the C standard function free . nlib calls free via this function. More... | |
size_t | nlib_malloc_size (const void *ptr) |
Returns the allocated memory size. More... | |
void | nlib_free_size (void *ptr, size_t size) |
Frees memory of a specified size. The default action is to call the nlib_free function. More... | |
NLIB_CHECK_RESULT void * | nlib_calloc (size_t nmemb, size_t size) |
A weak function that calls the C standard function calloc . nlib calls calloc via this function. More... | |
NLIB_CHECK_RESULT void * | nlib_realloc (void *ptr, size_t size) |
A weak function that calls the C standard function realloc . nlib calls realloc via this function. More... | |
NLIB_CHECK_RESULT void * | nlib_memalign (size_t alignment, size_t size) |
A weak function that calls the C standard function memalign . nlib calls memalign via this function. More... | |
The most basic nlib API that has C linkage.
NLIB_ALWAYS_INLINE inline __attribute__((always_inline)) |
Indicates that the compiler is forced to perform inline expansion of functions.
Platform | Definition |
---|---|
Win32 | __forceinline |
Linux | inline __attribute__((always_inline)) |
FreeBSD | inline __attribute__((always_inline)) |
OS X | inline __attribute__((always_inline)) |
CAFE | inline __attribute__((always_inline)) |
CTR | __forceinline |
Definition at line 97 of file Platform_unix.h.
NLIB_ASSUME | ( | cond | ) | switch (0) case 0: default: if (cond) ; else __builtin_unreachable() /* NOLINT */ |
Indicates that cond is true and provides tips for optimizing the compiler.
[in] | cond | An expression assumed to be true. |
switch
statements. Definition at line 256 of file Platform.h.
NLIB_ATTRIBUTE_CONST __attribute__((const)) |
Defines __attribute__((const))
if it is available for use.
Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((const)) |
FreeBSD | __attribute__((const)) |
OS X | __attribute__((const)) |
CAFE | __attribute__((const)) |
CTR | __attribute__((const)) |
Definition at line 113 of file Platform_unix.h.
NLIB_ATTRIBUTE_MALLOC __attribute__((malloc)) |
Defines __attribute__((malloc))
if it is available for use.
Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((malloc)) |
FreeBSD | __attribute__((malloc)) |
OS X | __attribute__((malloc)) |
CAFE | __attribute__((malloc)) |
CTR | __attribute__((malloc)) |
Definition at line 111 of file Platform_unix.h.
NLIB_ATTRIBUTE_PURE __attribute__((pure)) |
Defines __attribute__((pure))
if it is available for use.
Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((pure)) |
FreeBSD | __attribute__((pure)) |
OS X | __attribute__((pure)) |
CAFE | __attribute__((pure)) |
CTR | __attribute__((pure)) |
Definition at line 112 of file Platform_unix.h.
NLIB_CHECK_RESULT __attribute__((warn_unused_result)) |
Indicates that the caller of the function must check the returned value.
Platform | Definition |
---|---|
Win32 | _Check_return_ |
Linux | __attribute__((warn_unused_result)) |
FreeBSD | __attribute__((warn_unused_result)) |
OS X | __attribute__((warn_unused_result)) |
CAFE | __attribute__((warn_unused_result)) |
CTR | Empty string. |
Definition at line 102 of file Platform_unix.h.
nlib_compiler_version NLIB_CAPI(nlib_compiler_version) |
Dynamically obtains the compiler version used to compile nlib.
Compiler | implementation |
---|---|
MSVC | _MSC_FULL_VER |
clang | __clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__ |
gcc | __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ |
armcc | __ARMCC_VERSION |
ghs | __GHS_VERSION_NUMBER |
Definition at line 35 of file Platform_rename.h.
nlib_debug_break NLIB_CAPI(nlib_debug_break) |
A breakpoint.
Platform | Implementation |
---|---|
Win32 | DebugBreak() |
Linux | __builtin_trap() |
FreeBSD | __builtin_trap() |
OS X | __builtin_trap() |
CAFE | OSDebug() |
CTR | nn::dbg::Break() |
Definition at line 142 of file Platform_rename.h.
NLIB_DEPRECATED __attribute__((deprecated)) |
Indicates that a function or something has been deprecated.
Platform | Definition |
---|---|
Win32 | __declspec(deprecated) |
Linux | __attribute__((deprecated)) |
FreeBSD | __attribute__((deprecated)) |
OS X | __attribute__((deprecated)) |
CAFE | __attribute__((deprecated)) |
CTR | Empty string (because prefix format is not possible). |
Definition at line 146 of file Platform_unix.h.
NLIB_DEPRECATED_MSG | ( | msg | ) | __attribute__((deprecated)) |
Indicates that a function or something has been deprecated.
[in] | msg | A warning message. |
Platform | Definition |
---|---|
Win32 | __declspec(deprecated(msg)) |
Linux | __attribute__((deprecated(msg))) |
FreeBSD | __attribute__((deprecated(msg))) |
OS X | __attribute__((deprecated(msg))) |
CAFE | __attribute__((deprecated(msg))) |
CTR | Empty string (because prefix format is not possible). |
Definition at line 149 of file Platform_unix.h.
nlib_get_native_last_error NLIB_CAPI(nlib_get_native_last_error) |
Returns the last generated native error code.
Platform | Implementation |
---|---|
Win32 | GetLastError() |
Linux | Always return 0 . |
FreeBSD | Always return 0 . |
OS X | Always return 0 . |
CAFE | The error value generated by the call to an SDK function inside the nlib_xxxx function. |
CTR | The return value of the GetPrintableBits member function for the error generated by the call to an SDK function inside the nlib_xxxx function. |
Definition at line 33 of file Platform_rename.h.
nlib_getversion NLIB_CAPI(nlib_getversion) |
Dynamically gets the nlib version.
NLIB_VERSION
.nlib
you are using, you may need to change the behavior of the user code at run time. Definition at line 34 of file Platform_rename.h.
NLIB_LIKELY | ( | x | ) | __builtin_expect(!!(x), 1) |
Indicates to the compiler that condition x is likely to be true.
[in] | x | A conditional expression. |
Platform | Definition |
---|---|
Win32 | (x) |
Linux | __builtin_expect(!!(x), 1) |
FreeBSD | __builtin_expect(!!(x), 1) |
OS X | __builtin_expect(!!(x), 1) |
CAFE | __builtin_expect(!!(x), 1) |
CTR | __builtin_expect(!!(x), 1) |
Definition at line 99 of file Platform_unix.h.
NLIB_NEVER_INLINE __attribute__((__noinline__)) |
Indicates that the compiler does not perform inline expansion of functions.
Platform | Definition |
---|---|
Win32 | __declspec(noinline) |
Linux | __attribute__((__noinline__)) |
FreeBSD | __attribute__((__noinline__)) |
OS X | __attribute__((__noinline__)) |
CAFE | __attribute__((__noinline__)) |
CTR | __declspec(noinline) |
Definition at line 98 of file Platform_unix.h.
NLIB_NONNULL __attribute__((nonnull)) |
Indicates that you cannot specify NULL
for all arguments.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull)) |
FreeBSD | __attribute__((nonnull)) |
OS X | __attribute__((nonnull)) |
CAFE | __attribute__((nonnull)) |
CTR | __attribute__((nonnull)) |
Definition at line 104 of file Platform_unix.h.
NLIB_NONNULL_1 __attribute__((nonnull (1))) |
Indicates that you cannot specify NULL
for the first argument.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull (1))) |
FreeBSD | __attribute__((nonnull (1))) |
OS X | __attribute__((nonnull (1))) |
CAFE | __attribute__((nonnull (1))) |
CTR | __attribute__((nonnull (1))) |
Definition at line 105 of file Platform_unix.h.
NLIB_NONNULL_2 __attribute__((nonnull (2))) |
Indicates that you cannot specify NULL
for the second argument.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull (2))) |
FreeBSD | __attribute__((nonnull (2))) |
OS X | __attribute__((nonnull (2))) |
CAFE | __attribute__((nonnull (2))) |
CTR | __attribute__((nonnull (2))) |
Definition at line 106 of file Platform_unix.h.
NLIB_NONNULL_3 __attribute__((nonnull (3))) |
Indicates that you cannot specify NULL
for the third argument.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull (3))) |
FreeBSD | __attribute__((nonnull (3))) |
OS X | __attribute__((nonnull (3))) |
CAFE | __attribute__((nonnull (3))) |
CTR | __attribute__((nonnull (3))) |
Definition at line 107 of file Platform_unix.h.
NLIB_NONNULL_4 __attribute__((nonnull (4))) |
Indicates that you cannot specify NULL
for the fourth argument.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull (4))) |
FreeBSD | __attribute__((nonnull (4))) |
OS X | __attribute__((nonnull (4))) |
CAFE | __attribute__((nonnull (4))) |
CTR | __attribute__((nonnull (4))) |
Definition at line 108 of file Platform_unix.h.
NLIB_NONNULL_5 __attribute__((nonnull (5))) |
Indicates that you cannot specify NULL
for the fifth argument.
NULL
is passed, a warning is output at compile time. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((nonnull (5))) |
FreeBSD | __attribute__((nonnull (5))) |
OS X | __attribute__((nonnull (5))) |
CAFE | __attribute__((nonnull (5))) |
CTR | __attribute__((nonnull (5))) |
Definition at line 109 of file Platform_unix.h.
NLIB_NORETURN __attribute__((noreturn)) |
Indicates that the process will not return from functions.
Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((noreturn)) |
FreeBSD | __attribute__((noreturn)) |
OS X | __attribute__((noreturn)) |
CAFE | __attribute__((noreturn)) |
CTR | __attribute__((noreturn)) |
Definition at line 103 of file Platform_unix.h.
nlib_thread_exit NLIB_CAPI(nlib_thread_exit) |
Ends the called thread.
nlib_thread_cleanup_push()
and nlib_thread_cleanup_pop()
. Platform | Implementation |
---|---|
Win32 | _endthreadex(0) |
Linux | pthread_exit(0) |
FreeBSD | pthread_exit(0) |
OS X | pthread_exit(0) |
CAFE | OSExitThread(0) |
CTR | No implementation found (compiler error). |
Definition at line 136 of file Platform_rename.h.
nlib_thread_exit_cpp NLIB_CAPI(nlib_thread_exit_cpp) |
Ends the called thread.
catch (...)
. In addition, all functions in the caller of this function must not be set to no exceptions (such as noexcept
). Note that behavior is undefined (depending on the platform) when nlib_thread_cleanup_push()
and nlib_thread_cleanup_pop()
are used. Platform | Implementation |
---|---|
Win32 | Throws nlib_unwind_exception. |
Linux | Throws abi::__forced_unwind inside pthread_exit(0). |
FreeBSD | Throws _Unwind_Exception inside pthread_exit(0). |
OS X | Throws nlib_unwind_exception. |
CAFE | No implementation found (compiler error). |
CTR | No implementation found (compiler error). |
nlib_thread_cleanup_push()
is run for Linux and FreeBSD. In addition, for FreeBSD, a thrown (special) C++ exception cannot be caught.Definition at line 137 of file Platform_rename.h.
NLIB_UNLIKELY | ( | x | ) | __builtin_expect(!!(x), 0) |
Indicates to the compiler that condition x is likely to be false.
[in] | x | A conditional expression. |
Platform | Definition |
---|---|
Win32 | (x) |
Linux | __builtin_expect(!!(x), 0) |
FreeBSD | __builtin_expect(!!(x), 0) |
OS X | __builtin_expect(!!(x), 0) |
CAFE | __builtin_expect(!!(x), 0) |
CTR | __builtin_expect(!!(x), 0) |
Definition at line 100 of file Platform_unix.h.
NLIB_VIS_HIDDEN __attribute__((visibility("hidden"))) |
Symbols for functions and classes are not made available outside of the library.
NLIB_VIS_HIDDEN
to set symbols so they are not made available outside the library. You can also make symbols private by default by passing the -fvisibility=hidden
option to the compiler. Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((visibility("hidden"))), or an empty string in the Cygwin environment. |
FreeBSD | __attribute__((visibility("hidden"))) |
OS X | __attribute__((visibility("hidden"))) |
CAFE | Empty string. |
CTR | Empty string. |
Definition at line 88 of file Platform_unix.h.
NLIB_VIS_PUBLIC __attribute__((visibility("default"))) |
Symbols for functions and classes are made available outside of the library.
-fvisibility=hidden
to the compiler to explicitly make the symbols public. You must use this macro in such cases. Platform | Definition |
---|---|
Win32 | __declspec(dllimport) when using the DLL version, or an empty string otherwise. |
Linux | __attribute__((visibility("default"))) , or an empty string in the Cygwin environment. |
FreeBSD | __attribute__((visibility("default"))) |
OS X | __attribute__((visibility("default"))) |
CAFE | Empty string. |
CTR | Empty string. |
Definition at line 89 of file Platform_unix.h.
NLIB_WARN | ( | exp | ) | ("WARNING: " exp) |
Outputs a warning.
[in] | exp | A warning message. |
#pragma
message NLIB_WARN("message")
. Definition at line 221 of file Platform.h.
NLIB_WEAKSYMBOL __attribute__((weak)) |
Used for defining weak symbols.
Platform | Definition |
---|---|
Win32 | Empty string. |
Linux | __attribute__((weak)), or an empty string in the cygwin environment. |
FreeBSD | __attribute__((weak)) |
OS X | __attribute__((weak)) |
CAFE | __attribute__((weak)) |
CTR | __attribute__((weak)) |
Definition at line 90 of file Platform_unix.h.
nlib_yield NLIB_CAPI(nlib_yield) |
Relinquishes thread execution rights.
0
on success.Platform | Implementation |
---|---|
Win32 | Sleep(0) |
Linux | sched_yield() |
FreeBSD | sched_yield() |
OS X | sched_yield() |
CAFE | OSYieldThread() |
CTR | nn::os::Thread::Yield() |
Definition at line 111 of file Platform_rename.h.
RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL |
Defines a value somewhat smaller than the maximum value of size_t
.
size_t
. Definition at line 216 of file Platform.h.
The type for a barrier object.
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | pthread_barrier_t |
FreeBSD | pthread_barrier_t |
OS X | Implemented by nlib . |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
Definition at line 1068 of file Platform.h.
The type for a condition variable object.
Platform | Implementation |
---|---|
Win32 | CONDITION_VARIABLE |
Linux | pthread_cond_t |
FreeBSD | pthread_cond_t |
OS X | pthread_cond_t |
CAFE | OSFastCond |
CTR | nn::os::Event |
Definition at line 242 of file Platform_unix.h.
Type of the conditional variable for read-write locks.
nlib_cond
and nlib_mutex
. However, the Windows conditional variable (CONDITION_VARIABLE
) only has its conditional variable since it can have read-write locks directly. The original file descriptor of nlib
(a 32-bit integer value).
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | In accordance with the native file descriptor. |
FreeBSD | In accordance with the native file descriptor. |
OS X | In accordance with the native file descriptor. |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
Definition at line 1513 of file Platform.h.
The type for mutex variables.
Platform | Implementation |
---|---|
Win32 | HANDLE or CRITICAL_SECTION |
Linux | pthread_mutex_t |
FreeBSD | pthread_mutex_t |
OS X | pthread_mutex_t |
CAFE | OSFastMutex |
CTR | nn::os::CriticalSection |
Definition at line 191 of file Platform_unix.h.
The type for a read-write lock object.
Platform | Implementation |
---|---|
Win32 | SRWLOCK |
Linux | pthread_rwlock_t |
FreeBSD | pthread_rwlock_t |
OS X | pthread_rwlock_t |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
Definition at line 852 of file Platform.h.
The type for a semaphore object.
Platform | Implementation |
---|---|
Win32 | HANDLE |
Linux | sem_t |
FreeBSD | sem_t |
OS X | int (Make sure that it is not sem_t .) |
CAFE | OSSemaphore |
CTR | nn::os::Semaphore |
Definition at line 239 of file Platform_unix.h.
Spinlock variable type. Used by statically initializing with NLIB_SPINLOCK_INITIALIZER
.
Platform | Implementation |
---|---|
Win32 | int32_t |
Linux | int32_t |
FreeBSD | int32_t |
OS X | OSSpinLock |
CAFE | OSSpinLock |
CTR | int32_t |
Definition at line 1201 of file Platform.h.
The identifier for threads.
Platform | Implementation |
---|---|
Win32 | HANDLE |
Linux | pthread_t |
FreeBSD | pthread_t |
OS X | pthread_t |
CAFE | OSThread* |
CTR | nn::os::Thread |
Definition at line 251 of file Platform_unix.h.
void(* nlib_thread_func)(void *arg) |
A function to be run on a different thread.
[in] | arg | The argument passed to the thread. |
Definition at line 1222 of file Platform.h.
void(* nlib_tls_destructor)(void *tls_value) |
The type for the TLS destructor function called when the thread is ended.
[in] | tls_value | The value stored in the TLS slot. |
nlib_tls_setvalue()
in the destructor function, a normal implementation should run a destructor corresponding to the TLS again in order to prevent issues such as memory leaks. Currently, however, no destructor will run again for CTR or cygwin. Definition at line 548 of file Platform.h.
enum nlib_log_priority |
Defines the priority (level category) for output.
nlib_log_print
, nlib_log_vprint
, and nlib_log_attr_setint
functions. Definition at line 1388 of file Platform.h.
nlib_barrier_destroy | ( | nlib_barrier * | barrier | ) |
Destroys a barrier object.
[in] | barrier | A barrier object. |
0 | Success. |
EINVAL | barrier is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | pthread_barrier_destroy() |
FreeBSD | pthread_barrier_destroy() |
OS X | Implemented by nlib . |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_barrier_init | ( | nlib_barrier * | barrier, |
unsigned int | count | ||
) |
Initializes a barrier object.
[in,out] | barrier | A barrier object. |
[in] | count | Number of threads to wait for. |
0 | Success. |
EINVAL | barrier is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | pthread_barrier_init() |
FreeBSD | pthread_barrier_init() |
OS X | Implemented by nlib . |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_barrier_wait | ( | nlib_barrier * | barrier | ) |
Waits for a thread.
[in] | barrier | A barrier object. |
0 | Success (PTHREAD_BARRIER_SERIAL_THREAD will never be returned) |
EINVAL | barrier is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | pthread_barrier_wait() |
FreeBSD | pthread_barrier_wait() |
OS X | Implemented by nlib . |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_basename | ( | const char * | path | ) |
[in] | path | The path string. |
path | return value |
---|---|
"" | "" |
"/" | "" |
"." | "." |
".." | ".." |
"../" | "" |
"./" | "" |
"/usr/lib" | "lib" |
"/usr/" | "" |
"usr" | "usr" |
"sdmc:/test.txt" | "test.txt" |
"C:\\test.txt" | "test.txt"(Windows only) |
|
inlinestatic |
Reverses the bit order within an entire 32-bit integer.
[in] | x | A 32-bit integer. |
Definition at line 2562 of file Platform.h.
|
inlinestatic |
Reverses the bit order within an entire 64-bit integer.
[in] | x | A 64-bit integer. |
Definition at line 2585 of file Platform.h.
nlib_calloc | ( | size_t | nmemb, |
size_t | size | ||
) |
A weak function that calls the C standard function calloc
. nlib calls calloc
via this function.
[in] | nmemb | The number of elements. |
[in] | size | The length of each element, in bytes. |
nlib
memory allocation.
|
inlinestatic |
Returns the number of consecutive zero bits, with respect to the most significant bit (MSB).
[in] | x | The 32-bit value to operate on. |
Platform | Implementation |
---|---|
Win32 | _BitScanReverse() |
Linux | __builtin_clz() |
FreeBSD | __builtin_clz() |
OS X | __builtin_clz() |
CAFE | __CLZ32() |
CTR | __builtin_clz() |
Definition at line 2535 of file Platform.h.
|
inlinestatic |
Returns the number of consecutive zero bits, with respect to the most significant bit (MSB).
[in] | x | The 64-bit value to operate on. |
Platform | Implementation |
---|---|
Win32 | _BitScanReverse64() or _BitScanReverse() |
Linux | __builtin_clzll() |
FreeBSD | __builtin_clzll() |
OS X | __builtin_clzll() |
CAFE | __CLZ32() |
CTR | __builtin_clzll() |
Definition at line 2537 of file Platform.h.
nlib_cond_broadcast | ( | nlib_cond * | cond | ) |
Resumes the execution of all threads that are waiting for the conditional variable cond.
[in] | cond | The condition variable object. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | WakeAllConditionVariable() |
Linux | pthread_cond_broadcast() |
FreeBSD | pthread_cond_broadcast() |
OS X | pthread_cond_broadcast() |
CAFE | OSFastCond_Signal() |
CTR | Event::Signal() |
nlib_cond_destroy | ( | nlib_cond * | cond | ) |
Destroys a condition variable object.
[in] | cond | The condition variable object. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | System calls are not called. |
Linux | pthread_cond_destroy() |
FreeBSD | pthread_cond_destroy() |
OS X | pthread_cond_destroy() |
CAFE | System calls are not called. |
CTR | Event::~Event() |
nlib_cond_init | ( | nlib_cond * | cond | ) |
Initializes a condition variable.
[in] | cond | The condition variable object. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | InitializeConditionVariable() |
Linux | pthread_cond_init() |
FreeBSD | pthread_cond_init() |
OS X | pthread_cond_init() |
CAFE | OSFastCond_Init() |
CTR | Event::TryInitialize(true) |
nlib_cond_signal | ( | nlib_cond * | cond | ) |
Resumes the execution of one thread that is waiting for condition variable cond.
[in] | cond | The condition variable object. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | WakeConditionVariable() |
Linux | pthread_cond_signal() |
FreeBSD | pthread_cond_signal() |
OS X | pthread_cond_signal() |
CAFE | OSFastCond_Signal() |
CTR | Event::Signal() |
nlib_cond_wait | ( | nlib_cond * | cond, |
nlib_mutex * | mutex | ||
) |
Unlocks mutex and waits for a condition variable. It then relocks mutex after execution resumes.
[in] | cond | The condition variable object. |
[in] | mutex | A mutex object. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | SleepConditionVariableCS() |
Linux | pthread_cond_wait() |
FreeBSD | pthread_cond_wait() |
OS X | pthread_cond_wait() |
CAFE | OSFastCond_Wait() |
CTR | Event::Wait() + Event::ClearSignal() |
nlib_cond_wait_for | ( | nlib_cond * | cond, |
nlib_mutex * | mutex, | ||
nlib_duration | duration | ||
) |
Unlocks mutex and waits for just the duration amount of time for a condition variable. It then relocks mutex after execution resumes.
[in] | cond | The condition variable object. |
[in] | mutex | A mutex object. |
[in] | duration | The length of time for the timeout. |
0 | Success. |
ETIMEDOUT | Indicates a timeout. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | SleepConditionVariableCS() |
Linux | pthread_cond_timedwait() - If errno is EINTR , the function is executed again internally. |
FreeBSD | pthread_cond_timedwait() - If errno is EINTR , the function is executed again internally. |
OS X | pthread_cond_timedwait() - If errno is EINTR , the function is executed again internally. |
CAFE | nlib_sleep() |
CTR | Event::Wait() + Event::ClearSignal() |
mutex
object, and then returns 0
. If duration is a negative value, the function returns ETIMEDOUT
. nlib_cond_wait_until | ( | nlib_cond * | cond, |
nlib_mutex * | mutex, | ||
nlib_time | abstime | ||
) |
Unlocks mutex and waits until abstime for a condition variable. It then relocks mutex after execution resumes.
[in] | cond | The condition variable object. |
[in] | mutex | A mutex object. |
[in] | abstime | The time when the timeout occurs. |
0 | Success. |
ETIMEDOUT | Indicates a timeout. |
EINVAL | cond is set to NULL . |
nlib_cond_wait_for
function, which times out after a specified duration of time. Platform | Implementation |
---|---|
Win32 | nlib_epochtime() + nlib_cond_wait_for() |
Linux | pthread_cond_timedwait() |
FreeBSD | pthread_cond_timedwait() |
OS X | pthread_cond_timedwait() |
CAFE | nlib_epochtime() + nlib_sleep() |
CTR | Event::Wait() + Event::ClearSignal() |
0
. If the current time is already past the time set for abstime, the function returns ETIMEDOUT
. nlib_condrwlock_broadcast | ( | nlib_condrwlock * | cond | ) |
Resumes the execution of all threads that are waiting for the read-write lock conditional variable cond.
[in] | cond | A read-write lock conditional variable. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | WakeAllConditionVariable() |
Linux | nlib_mutex_lock(), nlib_cond_broadcast(), nlib_mutex_unlock() |
FreeBSD | nlib_mutex_lock(), nlib_cond_broadcast(), nlib_mutex_unlock() |
OS X | nlib_mutex_lock(), nlib_cond_broadcast(), nlib_mutex_unlock() |
CAFE | nlib_mutex_lock(), nlib_cond_broadcast(), nlib_mutex_unlock() |
CTR | nlib_mutex_lock(), nlib_cond_broadcast(), nlib_mutex_unlock() |
nlib_condrwlock_destroy | ( | nlib_condrwlock * | cond | ) |
Destroys a read-write lock conditional variable.
[in] | cond | A read-write lock conditional variable. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | Does nothing. |
Linux | nlib_mutex_destroy(), nlib_cond_destroy() |
FreeBSD | nlib_mutex_destroy(), nlib_cond_destroy() |
OS X | nlib_mutex_destroy(), nlib_cond_destroy() |
CAFE | nlib_mutex_destroy(), nlib_cond_destroy() |
CTR | nlib_mutex_destroy(), nlib_cond_destroy() |
nlib_condrwlock_init | ( | nlib_condrwlock * | cond | ) |
Initializes a read-write lock conditional variable.
[in] | cond | A read-write lock conditional variable. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | InitializeConditionVariable() |
Linux | nlib_mutex_init(), nlib_cond_init() |
FreeBSD | nlib_mutex_init(), nlib_cond_init() |
OS X | nlib_mutex_init(), nlib_cond_init() |
CAFE | nlib_mutex_init(), nlib_cond_init() |
CTR | nlib_mutex_init(), nlib_cond_init() |
nlib_condrwlock_signal | ( | nlib_condrwlock * | cond | ) |
Resumes the execution of one thread that is waiting for the read-write lock conditional variable cond.
[in] | cond | A read-write lock conditional variable. |
0 | Success. |
EINVAL | cond is set to NULL . |
Platform | Implementation |
---|---|
Win32 | WakeConditionVariable() |
Linux | nlib_mutex_lock(), nlib_cond_signal(), nlib_mutex_unlock() |
FreeBSD | nlib_mutex_lock(), nlib_cond_signal(), nlib_mutex_unlock() |
OS X | nlib_mutex_lock(), nlib_cond_signal(), nlib_mutex_unlock() |
CAFE | nlib_mutex_lock(), nlib_cond_signal(), nlib_mutex_unlock() |
CTR | nlib_mutex_lock(), nlib_cond_signal(), nlib_mutex_unlock() |
nlib_condrwlock_wait | ( | nlib_condrwlock * | cond, |
nlib_rwlock * | rwlock, | ||
int | rdlock | ||
) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes.
[in] | cond | A read-write lock conditional variable. |
[in] | rwlock | Read-write locks. |
[in] | rdlock | Specify 0 for a write lock, or 1 for a read lock. |
0 | Success. |
EINVAL | Indicates that cond or rwlock is NULL . |
Platform | Implementation |
---|---|
Win32 | SleepConditionVariableSRW() |
Linux | nlib_mutex_lock(), nlib_rwlock_rdunlock() or nlib_rwlock_wrunlock(), nlib_cond_wait(), nlib_mutex_unlock(), nlib_rwlock_rdlock() or nlib_rwlock_wrlock() |
FreeBSD | nlib_mutex_lock(), nlib_rwlock_rdunlock() or nlib_rwlock_wrunlock(), nlib_cond_wait(), nlib_mutex_unlock(), nlib_rwlock_rdlock() or nlib_rwlock_wrlock() |
OS X | nlib_mutex_lock(), nlib_rwlock_rdunlock() or nlib_rwlock_wrunlock(), nlib_cond_wait(), nlib_mutex_unlock(), nlib_rwlock_rdlock() or nlib_rwlock_wrlock() |
CAFE | nlib_mutex_lock(), nlib_rwlock_rdunlock() or nlib_rwlock_wrunlock(), nlib_cond_wait(), nlib_mutex_unlock(), nlib_rwlock_rdlock() or nlib_rwlock_wrlock() |
CTR | nlib_mutex_lock(), nlib_rwlock_rdunlock() or nlib_rwlock_wrunlock(), nlib_cond_wait(), nlib_mutex_unlock(), nlib_rwlock_rdlock() or nlib_rwlock_wrlock() |
nlib_condrwlock_wait_for | ( | nlib_condrwlock * | cond, |
nlib_rwlock * | rwlock, | ||
nlib_duration | duration, | ||
int | rdlock | ||
) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes.
[in] | cond | A read-write lock conditional variable. |
[in] | rwlock | Read-write locks. |
[in] | duration | The length of time for the timeout. |
[in] | rdlock | Specify 0 for a write lock, or 1 for a read lock. |
0 | Success. |
ETIMEDOUT | Indicates a timeout. |
EINVAL | Indicates that cond or rwlock is NULL . |
nlib_condrwlock_wait_until | ( | nlib_condrwlock * | cond, |
nlib_rwlock * | rwlock, | ||
nlib_time | abstime, | ||
int | rdlock | ||
) |
Unlocks rwlock and waits for a conditional variable. It then locks rwlock again after the execution resumes.
[in] | cond | A read-write lock conditional variable. |
[in] | rwlock | Read-write locks. |
[in] | abstime | The time when the timeout occurs. |
[in] | rdlock | Specify 0 for a write lock, or 1 for a read lock. |
0 | Success. |
ETIMEDOUT | Indicates a timeout. |
EINVAL | Indicates that cond or rwlock is NULL . |
nlib_crc32 | ( | uint32_t | crc32, |
const void * | p, | ||
size_t | n | ||
) |
This function calculates the CRC-32 checksum value for data.
[in] | crc32 | The previous CRC-32 checksum value (its initial value is 0) |
[in] | p | Pointer to n-byte data. |
[in] | n | Data size. |
Platform | implementation |
---|---|
SSE | Table lookup. |
NEON | __crc32b(),__crc32h(),__crc32w(),__crc32d() |
CAFE | Table lookup. |
CTR | Table lookup. |
nlib_crc32c | ( | uint32_t | crc32c, |
const void * | p, | ||
size_t | n | ||
) |
This function calculates the CRC-32C checksum value for data.
[in] | crc32c | The previous CRC-32C checksum value (its initial value is 0) |
[in] | p | Pointer to n-byte data. |
[in] | n | Data size. |
Platform | implementation |
---|---|
SSE | _mm_crc32_u8(),_mm_crc32_u16(),_mm_crc32_u32(),_mm_crc32_u64() |
NEON | __crc32b(),__crc32h(),__crc32w(),__crc32d() |
CAFE | Table lookup. |
CTR | Table lookup. |
|
inlinestatic |
Returns the number of consecutive zero bits, with respect to the least significant bit (LSB).
[in] | x | The 32-bit value to operate on. |
Platform | Implementation |
---|---|
Win32 | _BitScanForward() |
Linux | __builtin_ctz() |
FreeBSD | __builtin_ctz() |
OS X | __builtin_ctz() |
CAFE | 32 - nlib_clz32(~x & (x - 1)); |
CTR | 32 - nlib_clz32(~x & (x - 1)); |
Definition at line 2536 of file Platform.h.
|
inlinestatic |
Returns the number of consecutive zero bits, with respect to the least significant bit (LSB).
[in] | x | The 64-bit value to operate on. |
Platform | Implementation |
---|---|
Win32 | _BitScanForward64() or _BitScanForward() |
Linux | __builtin_ctzll() |
FreeBSD | __builtin_ctzll() |
OS X | __builtin_ctzll() |
CAFE | 64 - nlib_clz64(~x & (x - 1)); |
CTR | 64 - nlib_clz64(~x & (x - 1)); |
Definition at line 2538 of file Platform.h.
nlib_debug_backtrace | ( | size_t * | result, |
void ** | buffer, | ||
size_t | count | ||
) |
Stores backtraces in the array specified by buffer.
[out] | result | The number of stored backtraces. |
[in,out] | buffer | The buffer where the backtraces are stored. |
[in] | count | The number of backtraces that can be stored in buffer. (The number of void pointers). |
0 | Success. |
ENOTSUP | The feature is not supported. buffer gets filled with zeros. |
EINVAL | When result is 0 , buffer is NULL , or count is 0 . |
Platform | Implementation |
---|---|
Win32 | CaptureStackBackTrace() |
Linux | backtrace(). For cygwin , return ENOTSUP . |
FreeBSD | backtrace() |
OS X | backtrace() |
CAFE | Return ENOTSUP . |
CTR | Returns ENOTSUP . |
nlib_debug_backtrace_gettext | ( | char * | str, |
size_t | strbufsize, | ||
void *const * | buf, | ||
size_t | count | ||
) |
Creates string information from the data obtained using the nlib_debug_backtrace
function.
[out] | str | Buffer for the string. |
[in] | strbufsize | Size of the buffer for the string. |
[in] | buf | The buffer storing the backtraces. |
[in] | count | The number of stored backtraces. |
0 | Success. |
ENOTSUP | The feature is not supported. An empty string gets set in str. |
EINVAL | When str is NULL , strbufsize is 0 , buf is NULL , or count is 0 . |
Platform | Implementation |
---|---|
Win32 | SymFromAddr() |
Linux | backtrace_symbols(). For cygwin , return ENOTSUP . |
FreeBSD | backtrace_symbols() |
OS X | backtrace_symbols() |
CAFE | Returns ENOTSUP . |
CTR | Returns ENOTSUP . |
nlib_dir_close | ( | nlib_dir | dir | ) |
Closes a directory.
[in] | dir | A nlib_dir structure. |
0 | Success. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | FindClose() |
Linux | closedir() |
FreeBSD | closedir() |
OS X | closedir() |
CAFE | FSCloseDir() |
CTR | nn::fs::Directory::Finalize() + nn::fs::Directory::~Directory() |
nlib_dir_open | ( | nlib_dir * | dir, |
const char * | native_path | ||
) |
Opens a directory.
[in] | dir | Pointer to the nlib_dir structure to initialize. |
[in] | native_path | The path name (UTF-8). |
0 | Success. |
EINVAL | Indicates that dir and native_path were NULL . |
ENOENT | No directory exists. |
ENOTDIR | native_path is not a directory. |
ENOMEM | memory allocation failed. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | FindFirstFileW() |
Linux | opendir() |
FreeBSD | opendir() |
OS X | opendir() |
CAFE | FSOpenDir() |
CTR | nn::fs::Directory::Directory() + nn::fs::Directory::TryInitialize() |
nlib_dir_read | ( | nlib_dirent * | ent, |
nlib_dir | dir | ||
) |
Reads one directory entry, if there are any.
[in] | ent | Pointer to a directory entry. |
[in] | dir | A nlib_dir structure. |
0 | Success. |
ENOENT | Reached the end and there are no more files in the directory. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | FindNextFileW() |
Linux | readdir() , dirfd() , fstatat() |
FreeBSD | readdir() , dirfd() , fstatat() |
OS X | readdir() , dirfd() , fstatat() |
CAFE | FSReadDir() |
CTR | nn::fs::Directory::TryRead() |
nlib_dirname | ( | size_t * | len, |
const char * | path | ||
) |
[out] | len | Length of the string representing the directory. |
[in] | path | The path string. |
path | rval[0] .. rval[*len - 1] |
---|---|
"" | "." |
"/" | "/" |
"." | "." |
".." | "." |
"../" | ".." |
"./" | "." |
"/usr/lib" | "/usr" |
"/usr/" | "/usr" |
"usr" | "." |
"sdmc:/test.txt" | "sdmc:" |
"C:\\test.txt" | "C:"(Windows only) |
nlib_disk_freespace | ( | const char * | native_path, |
uint64_t * | free_bytes_available, | ||
uint64_t * | total_bytes, | ||
uint64_t * | total_free_bytes | ||
) |
Gets information related to the capacity of the storage region to which the specified path belongs.
[in] | native_path | The path name (UTF-8). |
[out] | free_bytes_available | The number of bytes available to the calling thread. |
[out] | total_bytes | The total number of bytes of storage. |
[out] | total_free_bytes | The total number of bytes of free storage. |
0 | Success. |
Other | Platform-dependent error (user does not have appropriate access rights, etc.). |
Platform | Implementation |
---|---|
Win32 | GetDiskFreeSpaceExW() |
Linux | statvfs() |
FreeBSD | statvfs() |
OS X | statvfs() |
CAFE | FSGetFreeSpaceSize() |
CTR | nn::fs::GetSdmcSize() |
FSGetFreeSpaceSize
function. nlib_epochtime | ( | nlib_time * | t | ) |
Gets the current time.
[out] | t | Pointer to where the current time is stored. |
0 | Success. |
EINVAL | Indicates that t is NULL . |
Platform | Implementation |
---|---|
Win32 | GetSystemTimeAsFileTime() |
Linux | clock_gettime(CLOCK_REALTIME, now) |
FreeBSD | clock_gettime(CLOCK_REALTIME, now) |
OS X | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock), clock_get_time(cclock, &mts) |
CAFE | OSGetTime() |
CTR | nn::fnd::DateTime::GetNow() |
nlib_error_string | ( | errno_t | e | ) |
Returns a string literal corresponding to the error value of nlib
.
[in] | e | An error value. |
nlib_exist_path | ( | int * | result, |
const char * | native_path | ||
) |
Checks whether the path exists.
[out] | result | If the path exists, some non-zero value gets set. |
[in] | native_path | The path name (UTF-8). |
0 | Success. |
Other | A platform-dependent error. |
Platform | Implementation |
---|---|
Win32 | PathFileExistsW() |
Linux | stat() |
FreeBSD | stat() |
OS X | stat() |
CAFE | FSGetStat() |
CTR | nlib_fd_open() |
nlib_fd_close | ( | nlib_fd | fd | ) |
Closes a file. The file descriptor will be released even if an error is returned.
[in] | fd | The file descriptor. |
0 | Success. |
EBADF | fd is valid but not an open descriptor. |
EIO | An I/O error occurred. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | CloseHandle() |
Linux | close() |
FreeBSD | close() |
OS X | close() |
CAFE | FSCloseFile() |
CTR | FileStream::Finalize() |
nlib_fd_fileid | ( | nlib_fileid * | result, |
nlib_fd | fd | ||
) |
[out] | result | A unique byte string for the file. |
[in] | fd | The file descriptor. |
memcmp()
for the comparison. Deleting and creating files repeatedly may cause the same IDs to be reused. Therefore, the file descriptors for the both files that you want to compare need to be kept opened. Platform | implementation |
---|---|
Win32 | GetFileInformationByHandleEx() |
Linux | fstat() |
FreeBSD | fstat() |
OS X | fstat() |
CAFE | Returns ENOTSUP. |
CTR | Returns ENOTSUP. |
nlib_fd_flush | ( | nlib_fd | fd | ) |
Flushes the write to the file descriptor.
[in] | fd | The file descriptor. |
0 | Success. |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | FlushFileBuffers() |
Linux | Do nothing. |
FreeBSD | Do nothing. |
OS X | Do nothing. |
CAFE | FSFlushFile() |
CTR | FileStream::TryFlush() |
nlib_fd_getsize | ( | nlib_offset * | size, |
nlib_fd | fd | ||
) |
Gets the file size.
[out] | size | Pointer to where the file size is stored. |
[in] | fd | The file descriptor. |
0 | Success. |
EINVAL | Indicates that size is NULL . |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | GetFileSizeEx() |
Linux | fstat() |
FreeBSD | fstat() |
OS X | fstat() |
CAFE | FSGetStatFile() |
CTR | FileStream::TryGetSize() |
nlib_fd_native_handle | ( | void ** | native_handle, |
nlib_fd | fd | ||
) |
Gets (the equivalent of) the native file handle.
[in] | native_handle | Pointer to where the native file handle is stored. |
[in] | fd | The file descriptor. |
0 | Success. |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | HANDLE is stored. |
Linux | The same value as fd is stored. |
FreeBSD | The same value as fd is stored. |
OS X | The same value as fd is stored. |
CAFE | FSFileHandle is stored. |
CTR | The pointer to nn::fs::FileStream is stored. |
nlib_fd_open | ( | nlib_fd * | fd, |
const char * | native_path, | ||
unsigned int | flags, | ||
int | mode | ||
) |
Opens a file.
[out] | fd | Stores the file descriptor if the file is successfully opened. |
[in] | native_path | The file path as a UTF-8 string. |
[in] | flags | A value that is a bitwise OR combination of flags for opening files. |
[in] | mode | If creating a file with NLIB_FD_O_CREAT , access permission must be specified. Otherwise, this argument needs not to be specified. |
0 | Success. |
EINVAL | Indicates that fd and native_path were NULL . |
ENOTSUP | Indicates that the value in flags is not supported. |
ENOMEM | Memory allocation failed. |
ELOOP | The specified path represented a symbolic link. |
Other | An error was returned by the native API. |
NLIB_FD_O_RDONLY
, NLIB_FD_O_WRONLY
, and NLIB_FD_O_RDWR
. NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC
. Platform | Implementation |
---|---|
Win32 | CreateFileW(). The mode value is ignored. |
Linux | open() |
FreeBSD | open() |
OS X | open() |
CAFE | FSOpenFile(), The mode value is ignored. |
CTR | FileStream::TryInitialize(), The mode value is ignored. |
EACCES
if the path string specifies a reserved device name or device namespace. FILE_FLAG_OVERLAPPED
, FILE_FLAG_OPEN_REPARSE_POINT
, and FILE_FLAG_POSIX_SEMANTICS
and opens the file. ELOOP
if FILE_ATTRIBUTE_REPARSE_POINT
representing a symbolic link or junction is set. lstat()
, and returns EACCES
if it is not for a regular file or directory. O_CLOEXEC
, O_NOFOLLOW
, and O_NONBLOCK
to the flag given by the user and opens the file. open()
returns EINTR
. For any other error, returns the error value, except EMLINK
and EFTYPE
which it returns as ELOOP
. EACCES
if the status obtained with <t>fstat() does not match the one obtained with lstat()
. O_NONBLOCK
if the user has not set it. nlib_fd_pread | ( | size_t * | result, |
nlib_fd | fd, | ||
void * | buf, | ||
size_t | count, | ||
nlib_offset | offset | ||
) |
Reads the file descriptor from the specified offset. The offset for the file descriptor will not be changed.
[out] | result | Pointer to where the number of loaded bytes is stored. |
[in] | fd | The file descriptor. |
[in] | buf | The read buffer. |
[in] | count | The maximum number of bytes to read. |
[in] | offset | The offset. |
nlib_fd_seek
and nlib_fd_read
functions.Platform | Implementation |
---|---|
Win32 | ReadFile |
Linux | pread |
FreeBSD | pread |
OS X | pread |
CAFE | FSReadFileWithPos() |
CTR | nlib_fd_seek() + nlib_fd_read() |
NLIB_FD_O_APPEND
flag is undefined.nlib_fd_pwrite | ( | size_t * | result, |
nlib_fd | fd, | ||
const void * | buf, | ||
size_t | count, | ||
nlib_offset | offset | ||
) |
Writes to the file descriptor at the specified offset. The offset for the file descriptor will not be changed.
[out] | result | Pointer to where the number of loaded bytes is written. |
[in] | fd | The file descriptor. |
[in] | buf | The write buffer. |
[in] | count | The maximum number of bytes to write. |
[in] | offset | The offset. |
nlib_fd_seek
and nlib_fd_write
functions.Platform | Implementation |
---|---|
Win32 | WriteFile |
Linux | pwrite |
FreeBSD | pwrite |
OS X | pwrite |
CAFE | FSWriteFileWithPos() |
CTR | nlib_fd_seek() + nlib_fd_write() |
nlib_fd_read | ( | size_t * | result, |
nlib_fd | fd, | ||
void * | buf, | ||
size_t | count | ||
) |
Reads (up to) count bytes from the file descriptor into buf.
[out] | result | Pointer to where the number of loaded bytes is stored. |
[in] | fd | The file descriptor. |
[in] | buf | The read buffer. |
[in] | count | The maximum number of bytes to read. |
0 | Success. |
EINVAL | Indicates that result or buf is NULL . |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
0
is stored in *result
without generating an error, that indicates the end of the file. Platform | Implementation |
---|---|
Win32 | ReadFile() |
Linux | read() - If errno is EINTR , the function is executed again internally. |
FreeBSD | read() - If errno is EINTR , the function is executed again internally. |
OS X | read() - If errno is EINTR , the function is executed again internally. |
CAFE | FSReadFile() |
CTR | FileStream::TryRead() |
nlib_fd_readv | ( | size_t * | result, |
nlib_fd | fd, | ||
const nlib_fd_iovec * | iov, | ||
int | iovcnt | ||
) |
Loads multiple non-continuous buffers from the file associated with fd.
[out] | result | If function call is successful, stores the number of loaded bytes. |
[in] | fd | The file descriptor. |
[in] | iov | Pointers to iovcnt number of buffers and the corresponding sizes. |
[in] | iovcnt | The number of iov. |
0 | Success. |
EINVAL | result was NULL . |
EINVAL | iovcnt was less than 0 or more than 1024. |
EINVAL | Total combined buffer size exceeds RSIZE_MAX . |
EBADF | fd is not a valid open descriptor. |
ENOMEM | Dynamic memory allocation failed. |
Other | An error was returned by the native API. |
readv
or nlib_fd_read
function loads the data. Platform | Implementation |
---|---|
Win32 | nlib_malloc(), nlib_fd_read(), nlib_free() |
Linux | readv() - If errno is EINTR , the function is executed again internally. |
FreeBSD | readv() - If errno is EINTR , the function is executed again internally. |
OS X | readv() - If errno is EINTR , the function is executed again internally. |
CAFE | nlib_malloc(), nlib_fd_read(), nlib_free() |
CTR | nlib_malloc(), nlib_fd_read(), nlib_free() |
nlib_fd_seek | ( | nlib_offset * | result, |
nlib_fd | fd, | ||
nlib_offset | offset, | ||
int | whence | ||
) |
Changes the file offset.
[out] | result | Pointer to where the changed offset is stored. |
[in] | fd | The file descriptor. |
[in] | offset | The offset. |
[in] | whence | NLIB_SEEK_SET or NLIB_SEEK_CUR . |
0 | Success. |
EINVAL | Indicates that result is NULL , or whence is an invalid value. |
EINVAL | The offset after being changed is a negative value. |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | Implemented by nlib . |
Linux | lseek() |
FreeBSD | lseek() |
OS X | lseek() |
CAFE | FSSetPosFile(), No offset is allowed to be set to a position after the end of the file. |
CTR | FileStream::TrySeek(), No offset is allowed to be set to a position after the end of the file. |
nlib_fd_sync | ( | nlib_fd | fd | ) |
Synchronizes the content of a file in memory with what is on the device.
[in] | fd | The file descriptor. |
0 | Success. |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | nlib_fd_flush() |
Linux | fsync() |
FreeBSD | fsync() |
OS X | fsync() |
CAFE | nlib_fd_flush() |
CTR | nlib_fd_flush() |
nlib_fd_truncate | ( | nlib_fd | fd, |
nlib_offset | length | ||
) |
Extends or truncates the file to be the specified size.
[in] | fd | The file descriptor. |
[in] | length | The length of the file. |
0 | Success. |
EBADF | fd is not a valid open descriptor. |
Others | depending on an error returned by the native API. |
Platform | Implementation |
---|---|
Win32 | SetFilePointerEx() + SetEndOfFile() |
Linux | ftruncate() |
FreeBSD | ftruncate() |
OS X | ftruncate() |
CAFE | FSGetStatFile() + FSGetPosFile() + FSSetPosFile() + FSWriteFile() or FSTruncateFile() |
CTR | FileStream::TryGetSize() + FileStream::TrySetSize() + FileStream::TryWrite() |
nlib_fd_write | ( | size_t * | result, |
nlib_fd | fd, | ||
const void * | buf, | ||
size_t | count | ||
) |
Writes (up to) count bytes from buf to the file descriptor.
[out] | result | Pointer to where the number of loaded bytes is written. |
[in] | fd | The file descriptor. |
[in] | buf | The write buffer. |
[in] | count | The maximum number of bytes to write. |
0 | Success. |
EINVAL | Indicates that result or buf is NULL . |
EBADF | fd is valid but not an open descriptor. |
Other | An error was returned by the native API. |
Platform | Implementation |
---|---|
Win32 | WriteFile() |
Linux | write() - If errno is EINTR , the function is executed again internally. |
FreeBSD | write() - If errno is EINTR , the function is executed again internally. |
OS X | write() - If errno is EINTR , the function is executed again internally. |
CAFE | FSWriteFile() |
CTR | FileStream::TryWrite() |
nlib_fd_writev | ( | size_t * | result, |
nlib_fd | fd, | ||
const nlib_fd_iovec * | iov, | ||
int | iovcnt | ||
) |
Writes from multiple non-continuous buffers to the file associated with fd.
[out] | result | If function call is successful, stores the number of bytes written. |
[in] | fd | The file descriptor. |
[in] | iov | Pointers to iovcnt number of buffers and the corresponding sizes. |
[in] | iovcnt | The number of iov. |
0 | Success. |
EINVAL | result was NULL . |
EINVAL | iovcnt was less than 0 or more than 1024. |
EINVAL | Total combined buffer size exceeds RSIZE_MAX . |
EBADF | fd is not a valid open descriptor. |
ENOMEM | Dynamic memory allocation failed. |
Other | An error was returned by the native API. |
writev
or nlib_fd_write
function writes the data. Platform | Implementation |
---|---|
Win32 | nlib_malloc(), nlib_fd_write(), nlib_free() |
Linux | writev() - If errno is EINTR , the function is executed again internally. |
FreeBSD | writev() - If errno is EINTR , the function is executed again internally. |
OS X | writev() - If errno is EINTR , the function is executed again internally. |
CAFE | nlib_malloc(), nlib_fd_write(), nlib_free() |
CTR | nlib_malloc(), nlib_fd_write(), nlib_free() |
nlib_free | ( | void * | ptr | ) |
A weak function that calls the C standard function free
. nlib calls free
via this function.
[in] | ptr | The pointer to free. |
nlib_free_size | ( | void * | ptr, |
size_t | size | ||
) |
Frees memory of a specified size. The default action is to call the nlib_free
function.
[in] | ptr | The pointer to free. |
[in] | size | The size allocated to ptr. |
sized deallocation
of C++14. nlib_gen_random | ( | void * | buf, |
size_t | size | ||
) |
Generates a random value of size bytes and stores it in buf.
[out] | buf | Pointer to the region where the random value is stored. |
[in] | size | The size of the region where the random value is stored. |
0
on success.Platform | Implementation |
---|---|
Win32 | CryptGenRandom() |
Linux | Loads /dev/urandom . |
FreeBSD | Loads /dev/urandom . |
OS X | Loads /dev/urandom . |
CAFE | Returns ENOTSUP . |
CTR | Returns ENOTSUP . |
nlib_getenv | ( | size_t * | result, |
char * | buf, | ||
size_t | bufsize, | ||
const char * | varname | ||
) |
Gets the value for the environment variable as a string.
[out] | result | Stores the required size for the buffer. 0 is stored if the corresponding environment variable does not exist. |
[out] | buf | The buffer that stores the environment variable. |
[in] | bufsize | The size of buf. |
[in] | varname | The name of the environment variable. |
0 | Success. |
EINVAL | Indicates that result or varname is NULL . |
EINVAL | Indicates that buf is NULL and bufsize is not 0 . |
ERANGE | The prepared buffer was too small. The required buffer size gets written to result. |
NULL
and bufsize set to 0
. Platform | Implementation |
---|---|
Win32 | getenv_s() |
Linux | getenv() |
FreeBSD | getenv() |
OS X | getenv() |
CAFE | ENVGetEnvironmentVariable() |
CTR | nn::hio::CTR::GetEnvironmentVariable(), hio must have been initialized. |
nlib_is_dir | ( | int * | result, |
const char * | native_path | ||
) |
Checks whether the path is for a directory. Sets 0 in *result and returns 0 if no path exists.
[out] | result | If the path is for a directory, some non-zero value gets set. |
[in] | native_path | The path name (UTF-8). |
0 | Success. |
Other | A platform-dependent error. |
Platform | Implementation |
---|---|
Win32 | PathIsDirectoryW() |
Linux | stat() |
FreeBSD | stat() |
OS X | stat() |
CAFE | FSGetStat() |
CTR | nlib_dir_open() |
|
inlinenoexcept |
Returns true
when the process result or object status is in an erroneous condition.
T | The value of bool or errno_t , or a class implementing operator bool() |
[in] | obj | A return value from a function, or an object |
True
if an error has occurredbool
is generally evaluated as Success when it returns true
and Failed when it returns false
. A function that returns errno_t
is evaluated as Success when it returns 0 and Failed when it returns a non-zero value. nlib_is_error()
allows the both types of functions to be properly evaluated for errors with the identical representation for their return values. In addition, they are implemented so that using a pointer as any of their arguments causes a compiling error. nlib_log_attr_setint | ( | int | prio, |
int | key, | ||
int | value | ||
) |
Specifies where to output the log for each level of priority.
[in] | prio | Specifies the nlib_log_priority value. (See kNlibLogVerbose .) |
[in] | key | Specifies where to output from nlib_log_key . |
[in] | value | The value to set (Any non-zero value is ON.) |
0
on success.key Value | Description |
---|---|
kNlibLogAttrStdout | Specifies output to standard output. |
kNlibLogAttrStderr | Specifies output to standard error output. |
kNlibLogAttrMsvcTrace | Specifies output using the OutputDebugString function in the Windows environment. |
kNlibLogAttrSyslog | Specifies output to the event log (Windows) or to syslog (Linux/FreeBSD). |
kNlibLogAttrNlibFd | Specifies output to a file. nlib_fd is specified for value. |
nlib_log_print | ( | int | prio, |
const char * | tag, | ||
const char * | fmt, | ||
... | |||
) |
Outputs log messages.
[in] | prio | Values of nlib_log_priority from kNlibLogVerbose to kNlibLogFatal . |
[in] | tag | Tagged text. |
[in] | fmt | Formatted text. |
DEBUG
and the log output is set to standard output. nlib_log_vprint | ( | int | prio, |
const char * | tag, | ||
const char * | fmt, | ||
va_list | ap | ||
) |
Outputs log messages.
[in] | prio | Values of nlib_log_priority from kNlibLogVerbose to kNlibLogFatal . |
[in] | tag | Tagged text. |
[in] | fmt | Formatted text. |
[in] | ap | Variable length argument for the formatted text. |
nlib_malloc | ( | size_t | size | ) |
A weak function that calls the C standard function malloc
. nlib calls malloc
via this function.
[in] | size | The number of bytes to allocate. |
nlib
memory allocation. nlib_malloc_size | ( | const void * | ptr | ) |
Returns the allocated memory size.
[in] | ptr | Pointer to memory allocated by nlib_malloc . |
Platform | implementation |
---|---|
Win32 | _msize() |
Linux | malloc_usable_size() |
FreeBSD | malloc_usable_size() |
OS X | malloc_size() |
CAFE | No implementation found. |
CTR | No implementation found. |
nlib_memalign | ( | size_t | alignment, |
size_t | size | ||
) |
A weak function that calls the C standard function memalign
. nlib calls memalign
via this function.
[in] | alignment | The alignment. |
[in] | size | The size. |
nlib
memory allocation. nn::nlib::DynamicAlignedStorage
be used for portability. nlib_memccpy | ( | void * | dest, |
size_t | dest_size, | ||
const void * | src, | ||
size_t | src_size, | ||
int | c | ||
) |
Continues copying until c is found. Stops copying when it is found.
[in,out] | dest | The destination buffer that accepts the copied data. |
[in] | dest_size | The size of the destination buffer. |
[in] | src | The source buffer that stores the original data to be copied to another buffer. |
[in] | src_size | The size of the source buffer. |
[in] | c | Copying bytes of this value causes this function to return upon completion of that copy. |
NULL
.memccpy(dest, src, c, dest_size > src_size ? src_size : dest_size)
. If used as shown below, this function can be used to process strings, such as reading a single line of strings at once. nlib_memchr | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches the n bytes from the start of the memory region (s, s + n) and returns a pointer to byte c.
[in] | s | The memory region to examine. |
[in] | c | The character to search for. |
[in] | n | The number of bytes to search through. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_memchr_gt | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to data having a character larger than byte c.
[in] | s | The memory region to examine. |
[in] | c | The character to search for. |
[in] | n | The number of bytes to search through. |
NULL
.nlib_memchr_lt | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to data having a character less than byte c.
[in] | s | The memory region to examine. |
[in] | c | The character to search for. |
[in] | n | The number of bytes to search through. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_memchr_mb | ( | const void * | s, |
size_t | n | ||
) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to the location where 0x80 or more bytes is stored.
[in] | s | The memory region to examine. |
[in] | n | The number of bytes to search through. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of bytes. |
CTR | Scan in units of bytes. |
nlib_memchr_not | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches the n bytes from the start of memory region(s, s + n) and returns a pointer that does not point to byte c.
[in] | s | The memory region to examine. |
[in] | c | The character to skip over. |
[in] | n | The number of bytes to search through. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_memchr_range_not | ( | const void * | s, |
const char * | range, | ||
size_t | n | ||
) |
Searches the n bytes from the start of memory region (s, s + n) and returns a pointer to a character not contained in range.
[in] | s | The memory region to examine. |
[in] | range | An ASCII string representing the range. |
[in] | n | The number of bytes to search through. |
NULL
.[a-z]*
you would code something like the following. Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_memcmp | ( | const void * | buf1, |
const void * | buf2, | ||
size_t | n | ||
) |
Compares the n bytes from the starts of buf1 and buf2 as unsigned char
data.
[in] | buf1 | Comparison source - memory block 1. |
[in] | buf2 | Comparison source - memory block 2. |
[in] | n | The number of bytes to compare. |
Positive | buf1 > buf2. |
0 | buf1 == buf2. |
Negative | buf1 < buf2. |
Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | memcmp() |
nlib_memcplen | ( | size_t * | codepoint_count, |
size_t * | supplementary_codepoint_count, | ||
size_t * | from_read, | ||
const nlib_utf8_t * | from, | ||
size_t | from_size | ||
) |
Gets the number of code points contained in the string and the number of supplementary characters contained in the string..
[out] | codepoint_count | Pointer that contains the number of code points. |
[out] | supplementary_codepoint_count | Pointer that contains the number of code points for supplementary characters (U+10000 - U+10FFFF ). |
[out] | from_read | Pointer that contains the number of bytes that the number of code points was counted for. |
[in] | from | The region that contains a non-null terminated UTF-8 string. |
[in] | from_size | The size of from. |
0 | Success. |
EINVAL | from_read or from is NULL . |
EILSEQ | Indicates that invalid data that cannot be converted into a code point was detected. |
EILSEQ
, it also halts immediately before the terminating character. In that case, data from from + *from_read
has not been converted. *codepoint_count
. Note that you can use the formula *codepoint_count + *supplementary_codepoint_count
to calculate the number of characters when the string is converted to UTF-16.
|
inlinestatic |
An implementation corresponding to N1078 memcpy_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of bytes to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | memcpy() |
Linux | memcpy() |
FreeBSD | memcpy() |
OS X | memcpy() |
CAFE | OSBlockMove() |
CTR | memcpy() |
Definition at line 2357 of file Platform.h.
nlib_memcspn | ( | const void * | buf, |
size_t | len, | ||
const char * | set, | ||
size_t | n | ||
) |
Returns the length of the set of sub-bytes from the beginning of buf. The set of sub-bytes consists of bytes other than those contained in set.
[in] | buf | A pointer to the region to be scanned. |
[in] | len | The number of bytes contained in buf. |
[in] | set | A set of bytes (It need not be null-terminated). |
[in] | n | The number of bytes contained in set. |
strcspn()
, buf need not be null-terminated.
|
inlinestatic |
An implementation corresponding to N1078 memmove_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of bytes to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. Platform | Implementation |
---|---|
Win32 | memmove() |
Linux | memmove() |
FreeBSD | memmove() |
OS X | memmove() |
CAFE | OSBlockMove() |
CTR | memmove() |
Definition at line 2375 of file Platform.h.
nlib_mempagesize | ( | size_t * | size | ) |
Gets the page size.
[out] | size | Stores the page size. |
0
on success.Platform | Implementation |
---|---|
Win32 | The GetSystemInfo function. (Call once at startup.) |
Linux | The getpagesize function. (Call once when running the first time.) |
FreeBSD | The getpagesize function. (Call once when running the first time.) |
OS X | The getpagesize function. (Call once when running the first time.) |
CAFE | Set the OSGetPageSize function and return 0 . |
CTR | Set NN_OS_MEMORY_PAGE_SIZE and return 0 . |
nlib_memrchr | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches the n bytes from the end of memory region (s, s + n) and returns a pointer to byte c.
[in] | s | The memory region to examine. |
[in] | c | The character to search for. |
[in] | n | The number of bytes to search through. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
|
inlinestatic |
Makes a function call corresponding to memset(buf, ch, n)
.
[in,out] | buf | The memory block to set the data to. |
[in] | ch | The byte data (character) to set. |
[in] | n | The number of bytes. |
0
on success.Definition at line 2389 of file Platform.h.
nlib_memspn | ( | const void * | buf, |
size_t | len, | ||
const char * | set, | ||
size_t | n | ||
) |
Returns the length of the set of sub-bytes from the beginning of buf. The set of sub-bytes consists of only bytes contained in set.
[in] | buf | A pointer to the region to be scanned. |
[in] | len | The number of bytes contained in buf. |
[in] | set | A set of bytes (It need not be null-terminated). |
[in] | n | The number of bytes contained in set. |
strspn()
, buf need not be null-terminated. nlib_memutf16_to_utf8 | ( | size_t * | to_count, |
size_t * | from_count, | ||
nlib_utf8_t * | to, | ||
size_t | to_size, | ||
const nlib_utf16_t * | from, | ||
size_t | from_size | ||
) |
Converts a UTF-16 string that is not null terminated to a UTF-8 string.
[out] | to_count | Stores the number of converted characters. |
[out] | from_count | Stores the number of characters successfully converted. |
[out] | to | Pointer to the region that is to contain a converted UTF-8 string (not null terminated). |
[in] | to_size | The size, in the number of characters, of the to buffer. |
[in] | from | Pointer to the region that contains a UTF-16 string (not null terminated). |
[in] | from_size | The size, in the number of characters, of the from buffer. |
0 | All the conversions have successfully completed. |
EINVAL | Indicates that to_count, from_count, or from is NULL . |
EINVAL | Indicates that to is NULL and to_size is not 0 . |
EILSEQ | Indicates that invalid data that cannot be converted was detected. |
EILSEQ
, it also halts immediately before the terminating code point. In that case, data from from + *from_count
has not been converted. nlib_memutf32_to_utf8 | ( | size_t * | to_count, |
size_t * | from_count, | ||
nlib_utf8_t * | to, | ||
size_t | to_size, | ||
const nlib_utf32_t * | from, | ||
size_t | from_size | ||
) |
Converts a UTF-32 string that is not null terminated to a UTF-8 string.
[out] | to_count | Stores the number of converted characters. |
[out] | from_count | Stores the number of characters successfully converted. |
[out] | to | Pointer to the region that is to contain a converted UTF-8 string (not null terminated). |
[in] | to_size | The size, in the number of characters, of the to buffer. |
[in] | from | Pointer to the region that contains a UTF-32 string (not null terminated). |
[in] | from_size | The size, in the number of characters, of the from buffer. |
0 | All the conversions have successfully completed. |
EINVAL | Indicates that to_count, from_count, or from is NULL . |
EINVAL | Indicates that to is NULL and to_size is not 0 . |
EILSEQ | Indicates that invalid data that cannot be converted was detected. |
nlib_memutf8_to_utf16 | ( | size_t * | to_count, |
size_t * | from_count, | ||
nlib_utf16_t * | to, | ||
size_t | to_size, | ||
const nlib_utf8_t * | from, | ||
size_t | from_size | ||
) |
Converts a UTF-8 string that is not null terminated to a UTF-16 string.
[out] | to_count | Stores the number of converted characters. |
[out] | from_count | Stores the number of characters successfully converted. |
[out] | to | Pointer to the region that is to contain a converted UTF-16 string (not null terminated). |
[in] | to_size | The size, in the number of characters, of the to buffer. |
[in] | from | Pointer to the region that contains a UTF-8 string (not null terminated). |
[in] | from_size | The size, in the number of characters, of the from buffer. |
0 | All the conversions have successfully completed. |
EINVAL | Indicates that to_count, from_count, or from is NULL . |
EINVAL | Indicates that to is NULL and to_size is not 0 . |
EILSEQ | Indicates that invalid data that cannot be converted was detected. |
EILSEQ
, it also halts immediately before the terminating code point. In that case, data from from + *from_count
has not been converted. nlib_memutf8_to_utf32 | ( | size_t * | to_count, |
size_t * | from_count, | ||
nlib_utf32_t * | to, | ||
size_t | to_size, | ||
const nlib_utf8_t * | from, | ||
size_t | from_size | ||
) |
Converts a UTF-8 string that is not null terminated to a UTF-32 string.
[out] | to_count | Stores the number of converted characters. |
[out] | from_count | Stores the number of characters successfully converted. |
[out] | to | Pointer to the region that is to contain a converted UTF-32 string (not null terminated). |
[in] | to_size | The size, in the number of characters, of the to buffer. |
[in] | from | Pointer to the region that contains a UTF-8 string (not null terminated). |
[in] | from_size | The size, in the number of characters, of the from buffer. |
0 | All the conversions have successfully completed. |
EINVAL | Indicates that to_count, from_count, or from is NULL . |
EINVAL | Indicates that to is NULL and to_size is not 0 . |
EILSEQ | Indicates that invalid data that cannot be converted was detected. |
EILSEQ
, it also halts immediately before the terminating code point. In that case, data from from + *from_count
has not been converted. nlib_mkdir | ( | const char * | native_path, |
unsigned int | flags | ||
) |
Creates a directory.
[in] | native_path | The path name (UTF-8). |
[in] | flags | This parameter is currently not being used. |
0 | Success. |
EINVAL | native_path was set to NULL . |
EEXIST | native_path already exists. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | CreateDirectoryW() |
Linux | mkdir() |
FreeBSD | mkdir() |
OS X | mkdir() |
CAFE | FSMakeDir() |
CTR | nn::fs::TryCreateDirectory() |
nlib_mkostemps | ( | nlib_fd * | fd, |
char * | templ, | ||
int | suffixlen, | ||
int | flags | ||
) |
Creates a temporary file with a unique name that is hard to be guessed.
[out] | fd | The file descriptor of a temporary file. |
[in,out] | templ | A file name template and created file name. |
[in] | suffixlen | The length of the suffix within the template. |
[in] | flags | The flag to be specified when opening a temporary file (NLIB_FD_O_APPEND can be specified). |
0 | Success. |
EINVAL | Indicates that fd or templ was NULL . The set of six letters immediately before the suffix of templ was not XXXXXX. |
EEXIST | Indicates that retrying multiple times by specifying a different file name each time encountered the same file names that already exist. templ is undefined. |
NLIB_FD_O_RDWR
, NLIB_FD_O_CREAT
, or NLIB_FD_O_EXCL
is always specified as the file creation flag. O_CLOEXEC
is also specified in an environment where it can be specified. O_TMPFILE
, specifying a directory in templ opens the file with O_TMPFILE
specified. Note that templ should be terminated with '/'. In this case, the file is opened without O_EXCL
specified. Platform | implementation |
---|---|
Win32 | nlib_fd_open() |
Linux | mkostemps(), open() |
FreeBSD | mkostemps() |
OS X | mkstemps() |
CAFE | nlib_fd_open() |
CTR | nlib_fd_open() |
nlib_mlock | ( | void * | addr, |
size_t | len | ||
) |
The specified memory region is not swapped out.
[in] | addr | Start of the region to lock. |
[in] | len | The size. |
0
on success.Platform | Implementation |
---|---|
Win32 | VirtualLock() |
Linux | mlock() |
FreeBSD | mlock() |
OS X | mlock() |
CAFE | Return 0 . |
CTR | Return 0 . |
nlib_mq_close | ( | nlib_mq | mq | ) |
Closes the message queue indicated with a handle.
[in] | mq | Handle to a message queue. |
0 | Success. |
EBADF | Indicates the handle specified with mq is invalid. |
nlib_mq_drop | ( | nlib_mq | mq, |
nlib_mq_msg * | msg, | ||
int * | prio | ||
) |
Receives a message with the lowest priority from a queue. It is the user's responsibility to delete the received messages using a destructor function.
[in] | mq | Handle to a message queue. |
[out] | msg | Stores received messages. |
[out] | prio | If a value other than NULL is specified, stores the priority of a received message. |
0 | Success. |
EINVAL | Indicates msg is set to NULL . |
EBADF | Indicates the handle specified with mq is invalid. |
ENOENT | Indicates the queue is empty. |
nlib_mq_getattr | ( | nlib_mq | mq, |
nlib_mq_attr * | attr | ||
) |
Obtains the attribute set to the message queue indicated with a handle.
[in] | mq | Handle to a message queue. |
[in] | attr | Message queue attribute. |
0 | Success. |
EBADF | Indicates the handle specified with mq is invalid. |
EINVAL | Indicates attr is NULL . |
nlib_mq_open | ( | nlib_mq * | mq, |
const nlib_mq_attr * | attr | ||
) |
Creates a message queue to be used to exchange messages across threads.
[out] | mq | Stores the handle to a message queue. |
[in] | attr | Message queue attribute. |
0 | Success. |
ENOMEM | Memory allocation failed. |
ENFILE | Indicates the number of created message queues has reached its upper limit. |
EINVAL | Indicates mq or attr is NULL . |
nlib_mq_readonly | ( | nlib_mq | mq | ) |
Sets the message queue indicated with a handle as receive-only.
[in] | mq | Handle to a message queue. |
0 | Success. |
EBADF | Indicates the handle specified with mq is invalid. |
EPERM
error to be returned. This function is useful when you no longer want to accept new messages and need to process messages remaining in the queue. nlib_mq_receive | ( | nlib_mq | mq, |
nlib_mq_msg * | msg, | ||
int * | prio | ||
) |
Receives a message from a queue. It is the user's responsibility to delete the received messages using a destructor function.
[in] | mq | Handle to a message queue. |
[out] | msg | Stores received messages. |
[out] | prio | If a value other than NULL is specified, stores the priority of a received message. |
0 | Success. |
EINVAL | Indicates msg is set to NULL . |
EBADF | Indicates the handle specified with mq is invalid. |
EAGAIN | Indicates the message queue that is not a blocking queue is empty. |
nlib_mq_receive_until | ( | nlib_mq | mq, |
nlib_mq_msg * | msg, | ||
int * | prio, | ||
nlib_time | abstime | ||
) |
Receives a message with a time-out set from a queue. It is the user's responsibility to delete the received messages using a destructor function.
[in] | mq | Handle to a message queue. |
[out] | msg | Stores received messages. |
[out] | prio | If a value other than NULL is specified, stores the priority of a received message. |
[in] | abstime | The time when the timeout occurs. |
0 | Success. |
EINVAL | Indicates msg is set to NULL . |
EBADF | Indicates the handle specified with mq is invalid. |
EINVAL | Indicates msg is set to NULL . |
EINVAL | Indicates the message queue is not a blocking queue. |
ETIMEDOUT | Indicates an attempt to receive a message in a blocking queue has timed-out. |
nlib_mq_send | ( | nlib_mq | mq, |
nlib_mq_msg | msg, | ||
int | prio | ||
) |
Sends a message to a queue.
[in] | mq | Handle to a message queue. |
[in] | msg | A message to send. |
[in] | prio | An integer between 0 to 31 indicating the message priority (with 31 being the highest priority). |
0 | Success. |
EBADF | Indicates the handle specified with mq is invalid. |
EINVAL | Indicates the priority specified with prio is below 0 or exceeds 32. |
EAGAIN | Indicates the message queue that is not a blocking queue is full. |
EPERM | Indicates the queue is set as receive-only. |
nlib_mq_send_until | ( | nlib_mq | mq, |
nlib_mq_msg | msg, | ||
int | prio, | ||
nlib_time | abstime | ||
) |
Sends a messages with a time-out set to the queue.
[in] | mq | Handle to a message queue. |
[in] | msg | A message to send. |
[in] | prio | An integer between 0 to 31 indicating the message priority (with 31 being the highest priority). |
[in] | abstime | The time when the timeout occurs. |
0 | Success. |
EBADF | Indicates the handle specified with mq is invalid. |
EINVAL | Indicates the priority specified with prio is below 0 or exceeds 32. |
EINVAL | Indicates the message queue is not a blocking queue. |
ETIMEDOUT | Indicates an attempt to send a message to a blocking queue has timed-out. |
EPERM | Indicates the queue is set as receive-only. |
nlib_munlock | ( | void * | addr, |
size_t | len | ||
) |
The specified memory region can be swapped out.
[in] | addr | Start of the region to unlock. |
[in] | len | The size. |
0
on success.Platform | Implementation |
---|---|
Win32 | VirtualUnlock() |
Linux | munlock() |
FreeBSD | munlock() |
OS X | munlock() |
CAFE | Return 0 . |
CTR | Return 0 . |
nlib_mutex_destroy | ( | nlib_mutex * | mutex | ) |
Destroys the specified mutex object and frees any associated resources.
[in] | mutex | The mutex to destroy. |
0 | Success. |
EINVAL | Indicates that mutex is NULL . |
Other | Indicates something else, like that mutex is locked. |
Platform | Implementation |
---|---|
Win32 | CloseHandle() or DeleteCriticalSection() |
Linux | pthread_mutex_destroy() |
FreeBSD | pthread_mutex_destroy() |
OS X | pthread_mutex_destroy() |
CAFE | No SDK API called. |
CTR | CriticalSection::~CriticalSection() |
nlib_mutex_init | ( | nlib_mutex * | mutex | ) |
Initializes a mutex.
[in] | mutex | Indicates the mutex object to initialize. |
0
.Platform | Implementation |
---|---|
Win32 | InitializeCriticalSectionEx() |
Linux | pthread_mutex_init() |
FreeBSD | pthread_mutex_init() |
OS X | pthread_mutex_init() |
CAFE | OSFastMutex_Init() |
CTR | CriticalSection::CriticalSection() |
nlib_mutex_lock | ( | nlib_mutex * | mutex | ) |
Locks the specified mutex.
[in] | mutex | The mutex to lock. |
0 | Success. |
EINVAL | Indicates that mutex is NULL or is not initialized. |
EDEADLK | Indicates that a deadlock is detected successfully. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() or EnterCriticalSection() |
Linux | pthread_mutex_lock() |
FreeBSD | pthread_mutex_lock() |
OS X | pthread_mutex_lock() |
CAFE | OSFastMutex_Lock() |
CTR | CriticalSection::Enter() |
nlib_mutex_recursive_init | ( | nlib_mutex * | mutex | ) |
Initializes a recursive mutex.
[in] | mutex | Indicates the mutex object to initialize. |
0
.Platform | Implementation |
---|---|
Win32 | InitializeCriticalSectionEx() |
Linux | pthread_mutex_init() |
FreeBSD | pthread_mutex_init() |
OS X | pthread_mutex_init() |
CAFE | OSFastMutex_Init() |
CTR | CriticalSection::CriticalSection() |
nlib_mutex_recursive_timed_init | ( | nlib_mutex * | mutex | ) |
Initializes a mutex that is recursive and can time out.
[in] | mutex | Indicates the mutex object to initialize. |
0
.Platform | Implementation |
---|---|
Win32 | CreateMutex() |
Linux | Assign NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER . |
FreeBSD | pthread_mutex_init() |
OS X | pthread_mutex_init() |
CAFE | OSFastMutex_Init() |
CTR | CriticalSection::CriticalSection() |
nlib_mutex_trylock | ( | nlib_mutex * | mutex | ) |
Locks mutex, but only if it is not locked.
[in] | mutex | The mutex to lock. |
0 | Success. |
EINVAL | Indicates that mutex is NULL or is not initialized. |
EBUSY | The mutex is already locked by some other thread. |
Other | Could not lock for some reason. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() or TryEnterCriticalSection() |
Linux | pthread_mutex_trylock() |
FreeBSD | pthread_mutex_trylock() |
OS X | pthread_mutex_trylock() |
CAFE | OSFastMutex_TryLock() |
CTR | CriticalSection::TryEnter() |
nlib_mutex_trylock_for | ( | nlib_mutex * | mutex, |
nlib_duration | delta | ||
) |
Locks the specified mutex. Times out.
[in] | mutex | The mutex to lock. |
[in] | delta | The timeout time. |
0 | Success. |
EINVAL | Indicates that mutex is NULL or is not initialized. |
ETIMEDOUT | Indicates a timeout. |
Other | Could not lock for some reason. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() |
Linux | pthread_mutex_timedlock() |
FreeBSD | pthread_mutex_timedlock() |
OS X | nlib_mutex_trylock(), nlib_sleep() |
CAFE | OSFastMutex_TryLock(), nlib_sleep() |
CTR | CriticalSection::TryEnter() |
nlib_mutex_unlock | ( | nlib_mutex * | mutex | ) |
Unlocks the specified mutex.
[in] | mutex | The mutex to unlock. |
0 | Success. |
EINVAL | Indicates that mutex is NULL or is not initialized. |
Indicates | that unlocking has failed due to other programming errors. |
Platform | Implementation |
---|---|
Win32 | ReleaseMutex() or LeaveCriticalSection() |
Linux | pthread_mutex_unlock() |
FreeBSD | pthread_mutex_unlock() |
OS X | pthread_mutex_unlock() |
CAFE | OSFastMutex_Unlock() |
CTR | CriticalSection::Leave() |
nlib_once | ( | nlib_onceflag * | flag, |
nlib_oncefunc | func | ||
) |
Ensures that func is executed only one time at most.
[in] | flag | Initializes with NLIB_ONCE_INIT and changes the value after the function executes. |
[in] | func | The function to execute only one time at most. |
0 | Indicates that execution of the function has completed. |
EINVAL | flag was set to NULL . |
NLIB_ONCE_INIT
ahead of time. If the nlib_once
function has been called multiple times, this function does nothing if it has already been called.
|
inlinestatic |
Waits for a very short time.
nlib_yield()
does, and can indicate to the hardware that a waiting state is now placed. Platform | implementation |
---|---|
x86/x86_64 | _mm_pause() |
arm | __yield() if __ARM_ACLE defined |
others | nlib_yield() |
Definition at line 1188 of file Platform.h.
nlib_physical_alloc | ( | void * | ptr, |
size_t | size, | ||
int | prot | ||
) |
Allocates physical memory.
[in] | ptr | A pointer to virtual memory. |
[in] | size | The size (in bytes) of the physical memory to allocate. |
[in] | prot | The access specification. |
0
on success.nlib_virtual_alloc
function and allocates physical memory. Value | Description |
---|---|
NLIB_PHYSICAL_ALLOC_PROT_NONE | Cannot access memory. |
NLIB_PHYSICAL_ALLOC_PROT_READ | Can read memory. |
NLIB_PHYSICAL_ALLOC_PROT_WRITE | Can change memory. |
NLIB_PHYSICAL_ALLOC_PROT_EXEC | Can execute memory. |
Platform | Implementation |
---|---|
Win32 | VirtualAlloc(ptr, size, MEM_COMMIT, ...) |
Linux | mprotect() |
FreeBSD | mprotect() |
OS X | mprotect() |
CAFE | Return 0 . |
CTR | Return 0 . |
nlib_physical_free | ( | void * | ptr, |
size_t | size | ||
) |
Frees the allocated physical memory.
[in] | ptr | A pointer to virtual memory. |
[in] | size | The size (in bytes) of the region of allocated physical memory to free. |
0
on success.nlib_virtual_alloc
function and frees the allocated physical memory. Platform | Implementation |
---|---|
Win32 | VirtualFree(..., MEM_DECOMMIT) |
Linux | mprotect(..., PROT_NONE) |
FreeBSD | mprotect(..., PROT_NONE) |
OS X | mprotect(..., PROT_NONE) |
CAFE | Return 0 . |
CTR | Return 0 . |
|
inlinestatic |
Returns the number of bits that are 1
.
[in] | x | A 16-bit integer. |
Definition at line 2399 of file Platform.h.
|
inlinestatic |
Returns the number of bits that are 1
.
[in] | x | A 32-bit integer. |
Platform | Implementation |
---|---|
SSE | _mm_popcnt_u32() |
NEON | vcnt_u8() |
CAFE | Table lookup. |
CTR | Table lookup. |
Definition at line 2402 of file Platform.h.
|
inlinestatic |
Returns the number of bits that are 1
.
[in] | x | A 64-bit integer. |
Platform | Implementation |
---|---|
SSE | _mm_popcnt_u32() , _mm_popcnt_u64() |
NEON | vcnt_u8() |
CAFE | Table lookup. |
CTR | Table lookup. |
Definition at line 2405 of file Platform.h.
nlib_readlink | ( | size_t * | len, |
const char * | native_path, | ||
char * | buf, | ||
size_t | bufsize | ||
) |
Resolve a symbolic link.
[out] | len | The length of the string stored in buf (not including null characters). |
[in] | native_path | The path to the symbolic link. |
[out] | buf | The buffer to store the content of the symbolic link. |
[in] | bufsize | The size of the buffer. |
0 | Success. |
EINVAL | naitive_path is not a symbolic link, or other conditions. |
ERANGE | The buffer length was insufficient (the string length for the content of the symbolic link is stored in *len). |
Other | platform dependent error value. |
ERANGE
and stores the string length in *len. In that case, you can run the function again by preparing a buffer with a length of *len plus one or more bytes. Platform | implementation |
---|---|
Win32 | GetFinalPathNameByHandle() |
Linux | readlink(), lstat() |
FreeBSD | readlink(), lstat() |
OS X | readlink(), lstat() |
CAFE | Returns ENOTSUP. |
CTR | Returns ENOTSUP. |
nlib_realloc | ( | void * | ptr, |
size_t | size | ||
) |
A weak function that calls the C standard function realloc
. nlib calls realloc
via this function.
[in] | ptr | Pointer to the memory block allocated ahead of time. |
[in] | size | The new size, in bytes. |
nlib
memory allocation. nlib_rename | ( | const char * | old_path, |
const char * | new_path | ||
) |
Renames a file.
[in] | old_path | A path name (UTF-8). |
[in] | new_path | A path name (UTF-8). |
0 | Success. |
EINVAL | Indicates that old_path and new_path were NULL . |
ENOENT | No old_path exists. |
EEXIST | new_path already exists. |
ENOTEMPTY | The same as EEXIST. |
EISDIR | new_path is a directory, but new_path is not a directory. EEXIST may be returned. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | MoveFileW() |
Linux | rename() |
FreeBSD | rename() |
OS X | rename() |
CAFE | FSRename() |
CTR | nn::fs::TryRenameFile() / nn::fs::TryRenameDirectory() |
ENOENT
when it should return EEXIST
or EISDIR
in other cases. EEXIST
. nlib_rmdir | ( | const char * | native_path | ) |
Deletes a directory.
[in] | native_path | The path name (UTF-8). |
0 | Success. |
EINVAL | native_path was set to NULL . |
ENOENT | No native_path exists. |
EEXIST | The directory is not empty. |
ENOTEMPTY | The same as EEXIST. |
ENOTDIR | native_path was not a directory. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | RemoveDirectoryW() |
Linux | rmdir() |
FreeBSD | rmdir() |
OS X | rmdir() |
CAFE | nlib_unlink() |
CTR | nn::fs::TryDeleteDirectory() |
nlib_rwlock_destroy | ( | nlib_rwlock * | rwlock | ) |
Destroys a read-write lock object.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Platform | Implementation |
---|---|
Win32 | Does nothing. |
Linux | pthread_rwlock_destroy() |
FreeBSD | pthread_rwlock_destroy() |
OS X | pthread_rwlock_destroy() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_init | ( | nlib_rwlock * | rwlock | ) |
Initializes a read-write lock object.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Platform | Implementation |
---|---|
Win32 | InitializeSRWLock() |
Linux | pthread_rwlock_init() |
FreeBSD | pthread_rwlock_init() |
OS X | pthread_rwlock_init() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_rdlock | ( | nlib_rwlock * | rwlock | ) |
Gets the read lock, and enters the critical section. Blocks until it can get a lock.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | AcquireSRWLockShared() |
Linux | pthread_rwlock_rdlock() |
FreeBSD | pthread_rwlock_rdlock() |
OS X | pthread_rwlock_rdlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_rdunlock | ( | nlib_rwlock * | rwlock | ) |
Releases the read lock.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | ReleaseSRWLockShared() |
Linux | pthread_rwlock_unlock() |
FreeBSD | pthread_rwlock_unlock() |
OS X | pthread_rwlock_unlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_tryrdlock | ( | nlib_rwlock * | rwlock | ) |
Gets the read lock, and attempts to enter the critical section.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
EBUSY | Could not get the lock. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockShared() |
Linux | pthread_rwlock_tryrdlock() |
FreeBSD | pthread_rwlock_tryrdlock() |
OS X | pthread_rwlock_tryrdlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_tryrdlock_for | ( | nlib_rwlock * | rwlock, |
nlib_duration | duration | ||
) |
Gets the read lock, and attempts to enter the critical section. Times out.
[in] | rwlock | A read-write lock object. |
[in] | duration | The length of time for the timeout. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
ETIMEDOUT | Indicates a timeout. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockShared(), nlib_sleep() |
Linux | pthread_rwlock_timedrdlock() |
FreeBSD | pthread_rwlock_timedrdlock() |
OS X | nlib_rwlock_tryrdlock(), nlib_sleep() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_tryrdlock_until | ( | nlib_rwlock * | rwlock, |
nlib_time | abstime | ||
) |
Gets the read lock, and attempts to enter the critical section. Times out.
[in] | rwlock | A read-write lock object. |
[in] | abstime | The time when the timeout occurs. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
ETIMEDOUT | Indicates a timeout. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockShared() and sleep. |
Linux | pthread_rwlock_timedrdlock() |
FreeBSD | pthread_rwlock_timedrdlock() |
OS X | nlib_rwlock_tryrdlock(), nlib_sleep() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_trywrlock | ( | nlib_rwlock * | rwlock | ) |
Gets a write lock, and attempts to enter the critical section.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
EBUSY | Could not get the lock. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockExclusive() |
Linux | pthread_rwlock_trywrlock() |
FreeBSD | pthread_rwlock_trywrlock() |
OS X | pthread_rwlock_trywrlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_trywrlock_for | ( | nlib_rwlock * | rwlock, |
nlib_duration | duration | ||
) |
Gets a write lock, and attempts to enter the critical section. Times out.
[in] | rwlock | A read-write lock object. |
[in] | duration | The length of time for the timeout. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
ETIMEDOUT | Indicates a timeout. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockExclusive() and sleep. |
Linux | pthread_rwlock_timedwrlock() |
FreeBSD | pthread_rwlock_timedwrlock() |
OS X | nlib_rwlock_trywrlock(), nlib_sleep() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_trywrlock_until | ( | nlib_rwlock * | rwlock, |
nlib_time | abstime | ||
) |
Gets a write lock, and attempts to enter the critical section. Times out.
[in] | rwlock | A read-write lock object. |
[in] | abstime | The time when the timeout occurs. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
ETIMEDOUT | Indicates a timeout. |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | TryAcquireSRWLockExclusive() and sleep. |
Linux | pthread_rwlock_timedwrlock() |
FreeBSD | pthread_rwlock_timedwrlock() |
OS X | nlib_rwlock_trywrlock(), nlib_sleep() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_wrlock | ( | nlib_rwlock * | rwlock | ) |
Gets a write lock, and enters the critical section. Blocks until it can get a lock.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | AcquireSRWLockExclusive() |
Linux | pthread_rwlock_wrlock() |
FreeBSD | pthread_rwlock_wrlock() |
OS X | pthread_rwlock_wrlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_rwlock_wrunlock | ( | nlib_rwlock * | rwlock | ) |
Releases a write lock.
[in] | rwlock | A read-write lock object. |
0 | Success. |
EINVAL | rwlock is set to NULL . |
Other | An implementation-dependent error. |
Platform | Implementation |
---|---|
Win32 | ReleaseSRWLockExclusive() |
Linux | pthread_rwlock_unlock() |
FreeBSD | pthread_rwlock_unlock() |
OS X | pthread_rwlock_unlock() |
CAFE | Implemented by nlib . |
CTR | Implemented by nlib . |
nlib_semaphore_destroy | ( | nlib_semaphore * | sem | ) |
Destroys the semaphore count.
[in] | sem | Pointer to the semaphore object. |
0 | Success. |
EINVAL | Indicates that sem is NULL . |
Other | Some invalid state, such as a blocking thread, has been detected. |
Platform | Implementation |
---|---|
Win32 | CloseHandle() |
Linux | sem_destroy() |
FreeBSD | sem_destroy() |
OS X | sem_close(), sem_unlink() |
CAFE | No SDK API called. |
CTR | Semaphore::~Semaphore() |
nlib_semaphore_init | ( | nlib_semaphore * | sem, |
int | initial_count | ||
) |
Initializes the semaphore object specified by sem.
[out] | sem | Pointer to the semaphore object. |
[in] | initial_count | Initial value for the semaphore count. |
0 | Success. |
EINVAL | Indicates that sem is NULL or the value set for initial_count exceeds 65535. |
Platform | Implementation |
---|---|
Win32 | CreateSemaphore() |
Linux | sem_init() |
FreeBSD | sem_init() |
OS X | sem_open() |
CAFE | OSInitSemaphore() |
CTR | Semaphore::TryInitialize() |
nlib_semaphore_post | ( | nlib_semaphore * | sem, |
int * | previous_count | ||
) |
Increments the semaphore count by 1.
[in] | sem | Pointer to the semaphore object. |
[out] | previous_count | Semaphore count prior to release. |
0 | Success. |
EINVAL | Indicates that sem is NULL . |
Other | The semaphore count has reached the upper limit. |
Platform | Implementation |
---|---|
Win32 | ReleaseSemaphore() |
Linux | sem_post() |
FreeBSD | sem_post() |
OS X | sem_post() |
CAFE | OSSignalSemaphore() |
CTR | Semaphore::Release() |
nlib_semaphore_post_ex | ( | nlib_semaphore * | sem, |
int | release_count, | ||
int * | previous_count | ||
) |
Increments the semaphore count by the amount specified by releaseCount.
[in] | sem | Pointer to the semaphore object. |
[in] | release_count | Number by which to increase the semaphore count. |
[out] | previous_count | Semaphore count prior to release. |
0 | Success. |
EINVAL | Indicates that sem is NULL . |
Other | The semaphore count has reached the upper limit. |
Platform | Implementation |
---|---|
Win32 | ReleaseSemaphore() |
Linux | sem_post() |
FreeBSD | sem_post() |
OS X | sem_post() |
CAFE | OSSignalSemaphore() |
CTR | Semaphore::Release() |
nlib_semaphore_trywait | ( | nlib_semaphore * | sem | ) |
Decrements the semaphore count by 1 if the count is not 0
.
[in] | sem | Pointer to the semaphore object. |
0 | Success. |
EAGAIN | The semaphore count is 0 . |
EINVAL | Indicates that sem is NULL . |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() |
Linux | sem_trywait() - If errno is EINTR , the function is executed again internally. |
FreeBSD | sem_trywait() - If errno is EINTR , the function is executed again internally. |
OS X | sem_trywait() - If errno is EINTR , the function is executed again internally. |
CAFE | OSTryWaitSemaphore() |
CTR | Semaphore::TryAcquire() |
nlib_semaphore_trywait_for | ( | nlib_semaphore * | sem, |
nlib_duration | duration | ||
) |
Decrements the semaphore count by 1 if the count is not 0
. If 0
, waits for the period specified by duration.
[in] | sem | Pointer to the semaphore object. |
[in] | duration | The length of time for the timeout. |
0 | Success. |
ETIMEDOUT | Indicates a timeout. |
EINVAL | Indicates that sem is NULL . |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() |
Linux | sem_timedwait() - If errno is EINTR , the function is executed again internally. |
FreeBSD | sem_timedwait() - If errno is EINTR , the function is executed again internally. |
OS X | nlib_semaphore_trywait(), nlib_sleep() - If errno is EINTR , the function is executed again internally. |
CAFE | OSTryWaitSemaphore() |
CTR | Semaphore::TryAcquire() |
nlib_semaphore_wait | ( | nlib_semaphore * | sem | ) |
Waits until the semaphore count is no longer 0
and decrements the semaphore count by 1.
[in] | sem | Pointer to the semaphore object. |
0 | Success. |
EINVAL | Indicates that sem is NULL . |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() |
Linux | sem_wait() - If errno is EINTR , the function is executed again internally. |
FreeBSD | sem_wait() - If errno is EINTR , the function is executed again internally. |
OS X | sem_wait() - If errno is EINTR , the function is executed again internally. |
CAFE | OSWaitSemaphore() |
CTR | Semaphore::Acquire() |
nlib_skipws | ( | size_t * | cnt_lf, |
const char ** | last_lf, | ||
const char * | s, | ||
size_t | n | ||
) |
Searches a string made up of n characters and returns the pointer to the first character found that is not a white-space character.
[in] | cnt_lf | Stores the number of LF characters (0x0A) that were found. |
[in] | last_lf | Stores the pointer to the last LF characters (0x0A) . |
[in] | s | Pointer to the string. |
[in] | n | The length of the target string. |
Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Implemented using the nlib_memchr_not function. |
CTR | Implemented using the nlib_memchr_not function. |
nlib_sleep | ( | nlib_duration | t | ) |
Sleeps for the duration of t.
[in] | t | The time to sleep. |
0
on success.Platform | Implementation |
---|---|
Win32 | Sleep() |
Linux | nanosleep() - If errno is EINTR , the function is executed again internally. |
FreeBSD | nanosleep() - If errno is EINTR , the function is executed again internally. |
OS X | nanosleep() - If errno is EINTR , the function is executed again internally. |
CAFE | OSSleepNanoseconds() |
CTR | nn::os::Thread::Sleep() |
|
inlinestatic |
Initializes the spinlock.
[in] | lock | Spinlock to be initialized. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | nlib independent implementation |
FreeBSD | nlib independent implementation |
OS X | Assigns 0 |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
Definition at line 1675 of file Platform.h.
|
inlinestatic |
Locks the spinlock. Behavior is undefined if a recursive lock is performed.
[in] | lock | Spinlock to be locked. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | nlib independent implementation |
FreeBSD | nlib independent implementation |
OS X | OSSpinLockLock() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
Definition at line 1678 of file Platform.h.
|
inlinestatic |
Locks the spinlock. Returns 0 if successful or EBUSY if fails.
[in] | lock | Spinlock to be locked. |
0 | Lock was successful. |
EBUSY | Lock was unsuccessful. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | nlib independent implementation |
FreeBSD | nlib independent implementation |
OS X | OSSpinLockTry() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
Definition at line 1708 of file Platform.h.
|
inlinestatic |
Unlocks the spinlock.
[in] | lock | Spinlock being locked. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | nlib independent implementation |
FreeBSD | nlib independent implementation |
OS X | OSSpinLockUnlock() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
Definition at line 1739 of file Platform.h.
nlib_strchr | ( | const char * | s, |
int | c | ||
) |
Searches for a character from the start of a string.
[in] | s | The string to search through. |
[in] | c | The character to search for. |
NULL
.Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Check in units of 32 bits. |
CTR | Check in units of 32 bits. |
nlib_strcplen | ( | size_t * | codepoint_count, |
size_t * | supplementary_codepoint_count, | ||
size_t * | len, | ||
const nlib_utf8_t * | str | ||
) |
Gets the number of code points contained in the string, the number of supplementary characters contained in the string, and the string length. If the function returns EILSEQ
, a value, including the number of code points to the point that cannot be converted, is stored.
[out] | codepoint_count | Pointer that contains the number of code points. |
[out] | supplementary_codepoint_count | Pointer that contains the number of code points for supplementary characters (U+10000 - U+10FFFF). |
[out] | len | Pointer that contains the string length. |
[in] | str | String |
0 | Success. |
EINVAL | Indicates that str is NULL . |
EILSEQ | Indicates that data that cannot be converted into a code point was detected. |
*codepoint_count
. Note that you can use the formula *codepoint_count + *supplementary_codepoint_count
to calculate the number of characters when the string is converted to UTF-16. nlib_strcpy | ( | char * | s1, |
size_t | s1max, | ||
const char * | s2 | ||
) |
An implementation corresponding to N1078 strcpy_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_strnlen() + nlib_memcpy() |
Linux | nlib_strnlen() + nlib_memcpy() |
FreeBSD | nlib_strnlen() + nlib_memcpy() |
OS X | nlib_strnlen() + nlib_memcpy() |
CAFE | nlib_strnlen() + nlib_memcpy() |
CTR | nlib_strnlen() + nlib_memcpy() |
nlib_strlen | ( | const char * | s | ) |
Internally calls strlen()
. In some cases, it may operate as an independent implementation.
[in] | s | Pointer to the string. |
0
if s is NULL
. Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_strncpy | ( | char * | s1, |
size_t | s1max, | ||
const char * | s2, | ||
size_t | n | ||
) |
An implementation corresponding to N1078 strncpy_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of characters to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_strnlen() + nlib_memcpy() |
Linux | nlib_strnlen() + nlib_memcpy() |
FreeBSD | nlib_strnlen() + nlib_memcpy() |
OS X | nlib_strnlen() + nlib_memcpy() |
CAFE | nlib_strnlen() + nlib_memcpy() |
CTR | nlib_strnlen() + nlib_memcpy() |
nlib_strnlen | ( | const char * | s, |
size_t | maxsize | ||
) |
An implementation corresponding to N1078 strnlen_s
.
[in] | s | Pointer to the string. |
[in] | maxsize | The size of the string. (The maximum number for the return value.) |
0
if s is NULL
. Returns maxsize if the string is longer than maxsize. Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Scan in units of words. |
CTR | Scan in units of words. |
nlib_strrchr | ( | const char * | s, |
int | c | ||
) |
Searches for a character from the end of a string.
[in] | s | The string to search through. |
[in] | c | The character to search for. |
NULL
.Platform | Implementation |
---|---|
Win32 | strrchr() |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | nlib_strlen , plus check backwards in units of 32 bits. |
CTR | nlib_strlen , plus check backwards in units of 32 bits. |
nlib_strto_int32 | ( | int32_t * | result, |
const char * | nptr, | ||
char ** | endptr, | ||
int | base | ||
) |
Converts a string to the int32_t
type.
[out] | result | The number of written characters (not including null characters). |
[in] | nptr | The string to be converted. |
[out] | endptr | The pointer to the first character that cannot be converted is stored. |
[in] | base | A cardinal number (0, 8, 10, and 16 are supported at the minimum.) |
0 | Success. |
ERANGE | The result value is out of the range of int32_t . *result is already set. |
EILSEQ | The value was not read. |
EINVAL | Conversion with the given base is not supported. |
strtol()
except the following: errno
does not need to be set to 0 in advance. int32_t
type. EILSEQ
. EILSEQ
. EILSEQ
. nlib_swapendian_16 | ( | uint16_t * | p, |
size_t | count | ||
) |
Swaps the endianness.
[in,out] | p | The region that the endian is swapped for. |
[in] | count | The amount of data. |
0 | Success. |
EINVAL | Indicates that p is NULL . |
Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Normal implementation. |
CTR | Normal implementation. |
nlib_swapendian_32 | ( | uint32_t * | p, |
size_t | count | ||
) |
Swaps the endianness.
[in,out] | p | The region that the endian is swapped for. |
[in] | count | The amount of data. |
0 | Success. |
EINVAL | Indicates that p is NULL . |
Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Normal implementation. |
CTR | Normal implementation. |
nlib_swapendian_64 | ( | uint64_t * | p, |
size_t | count | ||
) |
Swaps the endianness.
[in,out] | p | The region that the endian is swapped for. |
[in] | count | The amount of data. |
0 | Success. |
EINVAL | Indicates that p is NULL . |
Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Normal implementation. |
CTR | Normal implementation. |
nlib_thread_attr_destroy | ( | nlib_thread_attr * | attr | ) |
Destroys a thread-initialization object.
[out] | attr | The object to destroy. |
0 | Success. |
EINVAL | attr was set to NULL . |
nlib_thread_attr_getint | ( | const nlib_thread_attr * | attr, |
int | key, | ||
int * | value | ||
) |
Gets the integer corresponding to the key of the thread attribute object.
[in] | attr | Thread attribute. |
[in] | key | A key. |
[out] | value | Holds the value corresponding to the key. |
0 | Success. |
EINVAL | Invalid argument value. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | pthread_attr_getdetachstate(), pthread_attr_getstacksize(), pthread_attr_getschedparam(), pthread_attr_getaffinity_np() |
FreeBSD | pthread_attr_getdetachstate(), pthread_attr_getstacksize(), pthread_attr_getschedparam(), pthread_attr_getaffinity_np() |
OS X | pthread_attr_getdetachstate(), pthread_attr_getstacksize(), pthread_attr_getschedparam() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
nlib_thread_attr_getptr | ( | const nlib_thread_attr * | attr, |
int | key, | ||
void ** | value | ||
) |
Gets the pointer corresponding to the key of the thread attribute object. As of now, returns EINVAL
only.
[in] | attr | Thread attribute. |
[in] | key | A key. |
[out] | value | Holds the value corresponding to the key. |
0 | Success. |
EINVAL | Invalid argument value. |
nlib_thread_attr_getstack | ( | const nlib_thread_attr * | attr, |
void ** | stack_addr, | ||
size_t * | stack_size | ||
) |
Obtains a stack setting for thread attribute objects.
[in] | attr | Thread attribute. |
[out] | stack_addr | Stack address. |
[out] | stack_size | Stack size. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | pthread_attr_getstack() |
FreeBSD | pthread_attr_getstack() |
OS X | pthread_attr_getstack() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
nlib_thread_attr_init | ( | nlib_thread_attr * | attr | ) |
Initializes a thread attribute object and sets it to the default.
[out] | attr | The attribute being initialized. |
0 | Success. |
EINVAL | attr was set to NULL . |
nlib_thread_attr_setint | ( | nlib_thread_attr * | attr, |
int | key, | ||
int | value | ||
) |
Sets an integer corresponding to the key of the thread attribute object.
[out] | attr | The thread attribute. |
[in] | key | A key. |
[in] | value | The value being set. |
0 | Success. |
EINVAL | Invalid argument value. |
Key | Description |
---|---|
NLIB_THREAD_ATTR_KEY_DETACHSTATE | If non-zero, starts the thread in the detached state. |
NLIB_THREAD_ATTR_KEY_STACKSIZE | The size of the thread stack. |
NLIB_THREAD_ATTR_KEY_PRIORITY | Thread priority. |
NLIB_THREAD_ATTR_KEY_PRIORITY | Thread affinity mask. |
NLIB_THREAD_ATTR_KEY_EXPLICIT_SCHED | If non-zero, enables the NLIB_THREAD_ATTR_KEY_PRIORITY setting. |
Platform | Implementation |
---|---|
Win32 | Detaches immediately after the thread is started, _beginthreadex(), sets immediately after the thread is started, sets immediately after the thread is started. |
Linux | pthread_attr_setdetachstate(), pthread_attr_setstacksize(), pthread_attr_setschedparam(), pthread_attr_setaffinity_np() |
FreeBSD | pthread_attr_setdetachstate(), pthread_attr_setstacksize(), pthread_attr_setschedparam(), pthread_attr_setaffinity_np() |
OS X | pthread_attr_setdetachstate(), pthread_attr_setstacksize(), pthread_attr_setschedparam(), sets immediately after the thread is started. |
CAFE | OSCreateThread(), OSCreateThread(), OSCreateThread(), OSCreateThread() |
CTR | Detaches immediately after the thread is started, nn::os::Thread::TryStartUsingAutoStack(), nn::os::Thread::TryStartUsingAutoStack(), none |
nlib_thread_attr_setptr | ( | nlib_thread_attr * | attr, |
int | key, | ||
void * | value | ||
) |
Sets a pointer corresponding to the key of the thread attribute object. As of now, returns EINVAL
only.
[out] | attr | The thread attribute. |
[in] | key | A key. |
[in] | value | The value being set. |
0 | Success. |
EINVAL | Invalid argument value. |
nlib_thread_attr_setstack | ( | nlib_thread_attr * | attr, |
void * | stack_addr, | ||
size_t | stack_size | ||
) |
Sets a stack setting for thread attribute objects.
[out] | attr | The thread attribute. |
[in] | stack_addr | Stack address. |
[in] | stack_size | Stack size. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation (The set value is ignored) |
Linux | pthread_attr_getstack() |
FreeBSD | pthread_attr_getstack() |
OS X | pthread_attr_getstack() |
CAFE | nlib independent implementation |
CTR | nlib independent implementation |
nlib_thread_cleanup_pop | ( | int | exec | ) |
Deletes the handler at the top of the stack storing the cleanup handler.
[in] | exec | Runs a cleanup handler if not 0. Does not run the handler if 0. |
Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | pthread_cleanup_pop() |
FreeBSD | pthread_cleanup_pop() |
OS X | pthread_cleanup_pop() |
CAFE | nlib independent implementation |
CTR | No implementation found (compiler error). |
nlib_thread_cleanup_push | ( | void(*)(void *) | fn, |
void * | arg | ||
) |
Pushes fn to a dedicated stack.
[in] | fn | |
[in] | arg |
nlib_thread_exit()
is executed to a dedicated stack. If nlib_thread_exit()
(not nlib_thread_exit_cpp()
) is called before nlib_thread_cleanup_pop()
is executed, handlers are run one by one and the finalization of the thread is performed. Note that when leaving a thread through execution of a return statement, no cleanup handler will be run. In addition, whether a handler is run or not when using a C++ exception is undefined (dependent of the platform), and the behavior when calling nlib_thread_exit()
or nlib_thred_exit_cpp()
inside the cleanup handler is undefined. Platform | Implementation |
---|---|
Win32 | nlib independent implementation |
Linux | pthread_cleanup_push() |
FreeBSD | pthread_cleanup_push() |
OS X | pthread_cleanup_push() |
CAFE | nlib independent implementation |
CTR | No implementation found (compiler error). |
nlib_thread_create | ( | nlib_thread * | thread, |
const nlib_thread_attr * | attr, | ||
nlib_thread_func | func, | ||
void * | arg | ||
) |
Creates and executes a new thread.
[out] | thread | If a thread has been created successfully, this parameter stores the data indicating that thread. |
[in] | attr | If NULL is specified, the default attribute is set. |
[in] | func | The function to run on the new thread. |
[in] | arg | The argument to pass to function func. |
0 | Success. |
EINVAL | Indicates that thread or func was NULL , or some other parameter was deemed invalid. |
ENOMEM | Dynamic allocation of memory has failed. |
EAGAIN | Thread could not be started due to insufficient resources (too many threads, insufficient memory, etc.). |
EACCES | Thread could not be started due to insufficient resources (too many threads, insufficient memory, etc.). |
nlib_thread_detach | ( | nlib_thread | thread | ) |
Detaches an executing thread.
[in] | thread | The thread identifier. |
0 | Success. |
EINVAL | The thread could not be found but will be detached. |
ESRCH | The thread could not be found but will be detached. |
Platform | Implementation |
---|---|
Win32 | CloseHandle() |
Linux | pthread_detach() |
FreeBSD | pthread_detach() |
OS X | pthread_detach() |
CAFE | OSDetachThread() |
CTR | Thread::Detach() |
nlib_thread_equal | ( | nlib_thread | th1, |
nlib_thread | th2 | ||
) |
Checks whether two threads point to the same thread.
[in] | th1 | A nlib_thread -type value to compare. |
[in] | th2 | A nlib_thread -type value to compare. |
0
. nlib_thread_getconcurrency | ( | unsigned int * | num_cpu | ) |
Gets the number of hardware threads.
[out] | num_cpu | Sets the number of hardware threads. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | GetSystemInfo(&sysinfo); sysinfo.dwNumberOfProcessors |
Linux | sysconf(_SC_NPROCESSORS_ONLN) |
FreeBSD | sysconf(_SC_NPROCESSORS_ONLN) |
OS X | sysconf(_SC_NPROCESSORS_ONLN) |
CAFE | OSGetCoreCount() |
CTR | 1 |
nlib_thread_getcpu | ( | int * | cpuid | ) |
Gets the CPU on which the called thread is executing.
[out] | cpuid | The CPU number. |
0
if there is no error. Returns EINVAL
if cpuid is NULL
.*cpuid
to 0
and returns an error. Platform | Implementation |
---|---|
Win32(VISTA) | GetCurrentProcessorNumber() |
Win32(Windows 7 and later) | GetCurrentProcessorNumberEx() |
Linux | sched_getcpu(), (GetCurrentProcessorNumber() if cygwin) |
FreeBSD | Set 0 and return ENOTSUP . |
OS X | Set 0 and return ENOTSUP . |
CAFE | OSGetCoreId() |
CTR | nn::os::Thread::GetCurrentProcessorNumber() |
nlib_thread_getid | ( | nlib_thread_id * | id | ) |
Stores a unique integer value corresponding to the executing thread.
[out] | id | Stores the integer value corresponding to the thread. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | GetCurrentThreadId() |
Linux | syscall(SYS_gettid), (GetCurrentThreadId() if cygwin) |
FreeBSD | thr_self() |
OS X | pthread_threadid_np() |
CAFE | OSGetCurrentThread() |
CTR | nn::os::Thread::GetCurrentId() |
nlib_thread_getname | ( | nlib_thread | thread, |
char * | name, | ||
size_t | len | ||
) |
Gets the thread name.
[in] | thread | The thread identifier. |
[out] | name | The buffer that stores the thread name. |
[in] | len | The length of the name buffer. |
Platform | implementation |
---|---|
Win32 | Returns ENOTSUP . |
Linux | pthread_getname_np(). If cygwin , returns ENOTSUP . |
FreeBSD | Returns ENOTSUP . |
OS X | pthread_getname_np() |
CAFE | OSGetThreadName() |
CTR | Returns ENOTSUP . |
nlib_thread_getpriority | ( | nlib_thread | thread, |
int * | priority | ||
) |
Gets the current execution priority of the thread. The meaning of the numerical value is implementation-dependent.
[in] | thread | The thread identifier. |
[out] | priority | Stores the execution priority. |
0 | Success. |
EINVAL | priority was set to NULL . |
ESRCH | Indicates that thread is invalid. (In some cases, EINVAL is returned.) |
Platform | Implementation |
---|---|
Win32 | GetThreadPriority() |
Linux | pthread_getschedparam() |
FreeBSD | pthread_getschedparam() |
OS X | pthread_getschedparam() |
CAFE | OSGetThreadPriority() |
CTR | Thread::GetCurrentPriority() |
nlib_thread_join | ( | nlib_thread | thread | ) |
Waits for the thread to terminate.
[in] | thread | The identifier for the thread to wait to terminate. |
0 | Success. |
EINVAL | The thread could not be found but will be detached. |
ESRCH | The thread could not be found but will be detached. |
Platform | Implementation |
---|---|
Win32 | WaitForSingleObject() + CloseHandle() |
Linux | pthread_join() |
FreeBSD | pthread_join() |
OS X | pthread_join() |
CAFE | OSJoinThread() |
CTR | Thread::Join() |
nlib_thread_priority_default | ( | int * | priority | ) |
Gets the default numerical value that can be specified for the execution priority.
[out] | priority | The execution priority. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | THREAD_PRIORITY_NORMAL |
Linux | 0 |
FreeBSD | 0 |
OS X | 0 |
CAFE | OS_PRIORITY_APP_DEFAULT |
CTR | 16 |
nlib_thread_priority_max | ( | int * | priority | ) |
Gets the largest numerical value that can be specified for the execution priority.
[out] | priority | The execution priority. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | THREAD_BASE_PRIORITY_LOWRT |
Linux | sched_get_priority_max(SCHED_OTHER) |
FreeBSD | sched_get_priority_max(SCHED_OTHER) |
OS X | sched_get_priority_max(SCHED_OTHER) |
CAFE | 31 |
CTR | 31 |
nlib_thread_priority_min | ( | int * | priority | ) |
Gets the smallest numerical value that can be specified for the execution priority.
[out] | priority | The execution priority. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | THREAD_BASE_PRIORITY_IDLE |
Linux | sched_get_priority_min(SCHED_OTHER) |
FreeBSD | sched_get_priority_min(SCHED_OTHER) |
OS X | sched_get_priority_min(SCHED_OTHER) |
CAFE | 0 |
CTR | 0 |
nlib_thread_self | ( | nlib_thread * | thread | ) |
Stores the nlib_thread
value corresponding to the executing thread.
[out] | thread | The thread identifier. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | GetCurrentThread() |
Linux | pthread_self() |
FreeBSD | pthread_self() |
OS X | pthread_self() |
CAFE | OSGetCurrentThread() |
CTR | Returns ENOTSUP . |
nlib_thread_setaffinity | ( | nlib_thread | thread, |
uint32_t | affinity | ||
) |
Sets a processor affinity mask for the specified thread.
[in] | thread | The thread identifier. |
[in] | affinity | Thread affinity mask. |
0
on success.tid
other than the thread's own tid
(that is, the tid
for any thread that is not pthread_t
). The function returns EINVAL
if another thread has been specified. Platform | Implementation |
---|---|
Win32 | SetThreadAffinityMask() |
Linux | pthread_setaffinity_np(), (SetThreadAffinityMask() if cygwin) |
FreeBSD | pthread_setaffinity_np() |
OS X | thread_policy_set() |
CAFE | OSSuspendThread(), OSSetThreadAffinity(), and OSResumeThread(). 1, 2 and 4 correspond respectively to core 0, core 1 and core 2. Setting for a thread of its own is not allowed. |
CTR | Returns ENOTSUP . |
nlib_thread_setname | ( | nlib_thread | thread, |
const char * | name | ||
) |
Attaches a name to the thread.
[in] | thread | The thread identifier. |
[in] | name | Thread name. |
0
on success.ENOTSUP
. Platform | Implementation |
---|---|
Win32 | RaiseException(MS_VC_EXCEPTION, ....) |
Linux | pthread_setname_np(). If cygwin , returns ENOTSUP . |
FreeBSD | pthread_set_name_np() |
OS X | pthread_setname_np() |
CAFE | OSSetThreadName() |
CTR | Returns ENOTSUP . |
nlib_thread_setpriority | ( | nlib_thread | thread, |
int | priority | ||
) |
Sets the execution priority of the thread. The meaning of the numerical value is implementation-dependent.
[in] | thread | The thread identifier. |
[in] | priority | The execution priority to set. |
0 | Success. |
EINVAL | Indicates that priority was NULL or an invalid value. |
ESRCH | Indicates that thread is invalid. (In some cases, EINVAL is returned.) |
Other | Indicates that the parameter could not be set for some reason, such as a lack of permission. |
Platform | Implementation |
---|---|
Win32 | SetThreadPriority() |
Linux | pthread_setschedparam() |
FreeBSD | pthread_setschedparam() |
OS X | pthread_setschedparam() |
CAFE | OSSetThreadPriority() |
CTR | Thread::ChangePriority() |
nlib_ticktime | ( | nlib_duration * | t | ) |
Gets the elapsed time since the system was last started.
[out] | t | Pointer to where the elapsed time since the system started is stored. |
0 | Success. |
EINVAL | Indicates that t is NULL . |
Platform | Implementation |
---|---|
Win32 | GetTickCount64() |
Linux | clock_gettime(CLOCK_MONOTONIC, ...) |
FreeBSD | clock_gettime(CLOCK_MONOTONIC, ...) |
OS X | host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock), clock_get_time(cclock, &mts) |
CAFE | OSGetSystemTime() |
CTR | nn::os::Tick::GetSystemCurrent() |
nlib_timer_create | ( | nlib_timer * | timer, |
nlib_timer_callback | callback, | ||
void * | param, | ||
uint32_t | flags | ||
) |
Creates a timer.
[out] | timer | Stores the timer identifier. | ||||||
[in] | callback | The callback function to run. | ||||||
[in] | param | The argument to be passed to the callback function. | ||||||
[in] | flags | A value of 0 or the result given by ORring the following values.
|
0 | Success. |
EINVAL | Timer is NULL . |
ENOMEM | memory allocation failed. |
Others. | Varies depending on the internal implementation. |
NLIB_TIMER_SHORTTERM_TASK
for flags allows it to be executed on the timer thread itself. As doing so causes execution of other callback functions will be delayed, apply it only for a callback function that can be completed within a short duration. Specify NLIB_TIMER_LONGTERM_TASK
to suggest to the system that the callback function needs a long time to complete its execution. Platform | implementation |
---|---|
Win32 | CreateTimerQueueTimer() |
Linux | an implementation specific to nlib |
FreeBSD | an implementation specific to nlib |
OS X | an implementation specific to nlib |
CAFE | an implementation specific to nlib |
CTR | an implementation specific to nlib |
nlib_timer_delete | ( | nlib_timer | timer, |
int | wait_completion, | ||
nlib_timer_callback | completion_callback | ||
) |
Deletes a timer.
[in] | timer | The identifier of the timer. |
[in] | wait_completion | If non-zero, blocks until all the callback functions of the timer have completed their execution. |
[in] | completion_callback | If not NULL , called after all the callback functions of the timer have completed their execution. |
0 | Success. |
EBADF | The identifier of the timer is not valid. |
Platform | implementation |
---|---|
Win32 | DeleteTimerQueueTimer() |
Linux | an implementation specific to nlib |
FreeBSD | an implementation specific to nlib |
OS X | an implementation specific to nlib |
CAFE | an implementation specific to nlib |
CTR | an implementation specific to nlib |
nlib_timer_gettime | ( | nlib_timer | timer, |
nlib_timerspec * | curr_value | ||
) |
Obtains the current timer settings.
[in] | timer | The identifier of the timer. |
[out] | curr_value | The current settings are stored. |
0 | Success. |
EBADF | The identifier of the timer is not valid. |
EINVAL | The curr_value is NULL . |
nlib_timer_settime | ( | nlib_timer | timer, |
const nlib_timerspec * | new_value, | ||
nlib_timerspec * | old_value | ||
) |
Starts or suspends the timer.
[in] | timer | The identifier of the timer. |
[in] | new_value | A new setting |
[out] | old_value | If not NULL , the previous setting is stored. |
0 | Success. |
EBADF | The identifier of the timer is not valid. |
EINVAL | new_value is NULL or the new value field value is a negative value. |
nlib_timerspec
structure is defined as described below: due_time
specifies the time that elapses before the initial startup of the timer and interval
specifies the iteration interval of the startup after the initial one. Setting zero for both due_time
and interval
suspends the timer. Setting zero only for interval
starts the timer just once and the startup never iterates. This function can be called from a callback function of the timer. interval
set to zero and call this function again at the end of the callback function to set the next startup. Platform | implementation |
---|---|
Win32 | ChangeTimerQueueTimer() |
Linux | an implementation specific to nlib |
FreeBSD | an implementation specific to nlib |
OS X | an implementation specific to nlib |
CAFE | an implementation specific to nlib |
CTR | an implementation specific to nlib |
nlib_tls_alloc | ( | nlib_tls * | tls, |
nlib_tls_destructor | destr | ||
) |
Allocates a new ID for the specified TLS slot.
[out] | tls | Pointer to where the TLS slot ID is stored. |
[in] | destr | The destructor function to call when the thread ends. |
0 | Success. |
EINVAL | Indicates that tls is NULL . |
EAGAIN | Indicates that there are insufficient resources to allocate a TLS slot, or that the number of TLS slots has reached the limit for the system. |
nlib_tls_alloc()
is called. Platform | Implementation |
---|---|
Win32 | TlsAlloc()+ |
Linux | pthread_key_create() |
FreeBSD | pthread_key_create() |
OS X | pthread_key_create() |
CAFE | No SDK API called. |
CTR | nn::os::ThreadLocalStorage |
lib_tls_setvalue()
in a destructor function, two implementations are available: an implementation in which the destructor function is called multiple times and another implementation in which it is called once. Note that, in cygwin and CTR, the destructor function is called only once as of now. The condition described above may cause memory leaks.nlib_tls_free | ( | nlib_tls | tls | ) |
Frees the ID corresponding to the TLS slot.
[in] | tls | The ID to free. |
0 | Success. |
EINVAL | Indicates that tls is not a valid ID. |
Platform | Implementation |
---|---|
Win32 | TlsFree() |
Linux | pthread_key_delete() |
FreeBSD | pthread_key_delete() |
OS X | pthread_key_delete() |
CAFE | No SDK API called. |
CTR | ThreadLocalStorage::~ThreadLocalStorage() |
nlib_tls_getvalue | ( | nlib_tls | tls, |
void ** | value | ||
) |
Gets the value from a TLS slot.
[in] | tls | The ID of the TLS slot. |
[out] | value | The pointer for getting the stored value. |
0 | Success. |
EINVAL | Indicates that tls is not a valid ID. |
Platform | Implementation |
---|---|
Win32 | TlsGetValue() |
Linux | pthread_getspecific() |
FreeBSD | pthread_getspecific() |
OS X | pthread_getspecific() |
CAFE | OSGetThreadSpecific() |
CTR | ThreadLocalStorage::GetValue() |
nlib_tls_setvalue | ( | nlib_tls | tls, |
const void * | value | ||
) |
Stores a value in a TLS slot.
[in] | tls | The ID of the TLS slot. |
[in] | value | The value to set. |
0 | Success. |
EINVAL | Indicates that tls is not a valid ID. |
Platform | Implementation |
---|---|
Win32 | TlsSetValue() |
Linux | pthread_setspecific() |
FreeBSD | pthread_setspecific() |
OS X | pthread_setspecific() |
CAFE | OSSetThreadSpecific() + OSSetThreadCleanupCallback() |
CTR | ThreadLocalStorage::SetValue() |
nlib_unlink | ( | const char * | native_path | ) |
Deletes a file.
[in] | native_path | The path name (UTF-8). |
0 | Success. |
EINVAL | native_path was set to NULL . |
ENOENT | No native_path exists. |
EISDIR | native_path was a directory. |
Other | Failed for some reason. |
Platform | Implementation |
---|---|
Win32 | DeleteFileW() |
Linux | unlink() |
FreeBSD | unlink() |
OS X | unlink() |
CAFE | FSRemove() |
CTR | nn::fs::TryDeleteFile() |
nlib_utf16_to_utf32char | ( | nlib_utf32_t * | utf32, |
nlib_utf16_t | upper, | ||
nlib_utf16_t | lower | ||
) |
Converts a single code point from UTF-16 into UTF-32.
[out] | utf32 | Stores a UTF-32 character. |
[in] | upper | The first 16 bits of UTF-16. |
[in] | lower | The 16 bits subsequent to upper. |
0 | Conversion was not possible. |
1 | Only upper was converted to UTF-32. |
2 | Indicates that upper and lower were combined and converted to UTF-32. |
nlib_utf16_to_utf8 | ( | size_t * | utf8count, |
nlib_utf8_t * | utf8, | ||
size_t | buflen, | ||
const nlib_utf16_t * | utf16 | ||
) |
Converts a UTF-16 string into a UTF-8 string.
[out] | utf8count | Stores the number of converted characters (the number of char , not including the null character). |
[out] | utf8 | The buffer for storing the converted string. |
[in] | buflen | The size of the utf8 buffer (the number of characters including the null character). |
[in] | utf16 | A UTF-16 string. |
0 | No error occurred. |
EINVAL | Indicates that either utf8 is NULL and buflen > 0 , or utf16 is NULL . |
ERANGE | The converted string was too big to fit, so it has been stored in truncated form. |
EILSEQ | Data that cannot be converted was detected. |
char
) is set in *utf8count (providing that utf8count is not NULL
). NULL
and buflen is set to 0
, the number of converted UTF-8 (which is not necessarily the number of code points) is set in utf8count. 0
, utf8 is set to an empty string, and the function returns EILSEQ
.
|
inlinestatic |
Gets the number of code points in the string.
[out] | count | Pointer to where the number of code points is stored. |
[in] | str | String. |
0 | Success. |
EINVAL | Indicates that count or str is NULL . |
EILSEQ | Some data cannot be converted into a code point. |
Definition at line 2248 of file Platform.h.
|
inlinestatic |
Gets the number of code points in the string.
[out] | count | Pointer to where the number of code points is stored. |
[out] | len | Pointer to where the length of str is stored. |
[in] | str | String. |
0 | Success. |
EINVAL | Indicates that count or str is NULL . |
EILSEQ | Some data cannot be converted into a code point. |
Definition at line 2252 of file Platform.h.
|
inlinestatic |
The UTF-16 version of the nlib_strcpy
function.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_utf16nlen() + nlib_memcpy() |
Linux | nlib_utf16nlen() + nlib_memcpy() |
FreeBSD | nlib_utf16nlen() + nlib_memcpy() |
OS X | nlib_utf16nlen() + nlib_memcpy() |
CAFE | nlib_utf16nlen() + nlib_memcpy() |
CTR | nlib_utf16nlen() + nlib_memcpy() |
Definition at line 2211 of file Platform.h.
|
inlinestatic |
Counts the number of nlib_utf16_t
-type characters, not including the null character.
[in] | str | UTF-16 string. |
nlib_utf16_t
-type characters, not including the null character at the end).Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Expanded loop. |
CTR | Expanded loop. |
Definition at line 2203 of file Platform.h.
|
inlinestatic |
The UTF-16 version of the nlib_strcpy
function.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of characters to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_utf16nlen() + nlib_memcpy() |
Linux | nlib_utf16nlen() + nlib_memcpy() |
FreeBSD | nlib_utf16nlen() + nlib_memcpy() |
OS X | nlib_utf16nlen() + nlib_memcpy() |
CAFE | nlib_utf16nlen() + nlib_memcpy() |
CTR | nlib_utf16nlen() + nlib_memcpy() |
Definition at line 2215 of file Platform.h.
|
inlinestatic |
The UTF-16 version of the nlib_strnlen
function.
[in] | s | Pointer to the string. |
[in] | maxsize | The size of the string. (The maximum number for the return value.) |
0
if s is NULL
. If the string length is equal to or longer than maxsize, the function returns maxsize. Platform | Implementation |
---|---|
Win32 | Implemented using SIMD. |
Linux | Implemented using SIMD. |
FreeBSD | Implemented using SIMD. |
OS X | Implemented using SIMD. |
CAFE | Expanded loop. |
CTR | Expanded loop. |
Definition at line 2207 of file Platform.h.
nlib_utf32_to_utf8 | ( | size_t * | utf8count, |
nlib_utf8_t * | utf8, | ||
size_t | buflen, | ||
const nlib_utf32_t * | utf32 | ||
) |
Converts a UTF-32 string into a UTF-8 string.
[out] | utf8count | Stores the number of converted characters (the number of char , not including the null character). |
[out] | utf8 | The buffer for storing the converted string. |
[in] | buflen | The size of the utf8 buffer (the number of characters including the null character). |
[in] | utf32 | A UTF-32 string. |
0 | No error occurred. |
EINVAL | Either utf8 is NULL and buflen > 0 , or utf32 is NULL . |
ERANGE | The converted string was too big to fit, so it has been stored in truncated form. |
EILSEQ | Data that cannot be converted was detected. |
char
) is set in *utf8count (providing that utf8count is not NULL
). NULL
and buflen is set to 0
, the number of converted UTF-8 is set in utf8count. 0
, utf8 is set to an empty string, and the function returns EILSEQ
. nlib_utf32char_to_utf16 | ( | nlib_utf16_t * | upper, |
nlib_utf16_t * | lower, | ||
nlib_utf32_t | utf32 | ||
) |
Converts a single UTF-32 character into UTF-16.
[in] | upper | Stores the first 16 bits of UTF-16. |
[in] | lower | Stores the 16 bits subsequent to upper (if they are present). |
[in] | utf32 | UTF-32 for one character. |
0 | Conversion was not possible. |
1 | A result was stored for only upper. |
2 | Results were stored for both upper and lower. |
nlib_utf32char_to_utf8 | ( | nlib_utf8_t(&) | utf8[4], |
nlib_utf32_t | utf32 | ||
) |
Converts the UTF-32 for one character into UTF-8.
[out] | utf8 | Stores the converted UTF-8 string. This string must not be null-terminated. |
[in] | utf32 | UTF-32 for one character. |
0 | Conversion was not possible. |
1 | Only utf8[0] was set. |
2 | Indicates that utf8[0] and utf8[1] were set. |
3 | Indicates that utf8[0] , utf8[1] , and utf8[2] were set. |
4 | Indicates that utf8[0] , utf8[1] , utf8[2] , and utf8[3] were set. |
nlib_utf32cplen | ( | size_t * | count, |
const nlib_utf32_t * | str | ||
) |
Gets the number of code points in the string.
[out] | count | Pointer to where the number of code points is stored. |
[in] | str | String. |
0 | Success. |
EINVAL | Indicates that count or str is NULL . |
EILSEQ | Some data cannot be converted into a code point. |
|
inlinestatic |
The UTF-32 version of the nlib_strcpy
function.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_utf32nlen() + nlib_memcpy() |
Linux | nlib_utf32nlen() + nlib_memcpy() |
FreeBSD | nlib_utf32nlen() + nlib_memcpy() |
OS X | nlib_utf32nlen() + nlib_memcpy() |
CAFE | nlib_utf32nlen() + nlib_memcpy() |
CTR | nlib_utf32nlen() + nlib_memcpy() |
Definition at line 2236 of file Platform.h.
|
inlinestatic |
Counts the number of nlib_utf32_t
-type characters, not including the null character.
[in] | str | UTF-32 string. |
nlib_utf32_t
-type characters, not including the null character at the end). Definition at line 2228 of file Platform.h.
|
inlinestatic |
The UTF-32 version of the nlib_strcpy
function.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of characters to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_utf32nlen() + nlib_memcpy() |
Linux | nlib_utf32nlen() + nlib_memcpy() |
FreeBSD | nlib_utf32nlen() + nlib_memcpy() |
OS X | nlib_utf32nlen() + nlib_memcpy() |
CAFE | nlib_utf32nlen() + nlib_memcpy() |
CTR | nlib_utf32nlen() + nlib_memcpy() |
Definition at line 2240 of file Platform.h.
|
inlinestatic |
The UTF-32 version of the nlib_strnlen
function.
[in] | s | Pointer to the string. |
[in] | maxsize | The size of the string. (The maximum number for the return value.) |
0
if s is NULL
. Returns maxsize if the string is longer than maxsize. Definition at line 2232 of file Platform.h.
nlib_utf8_to_utf16 | ( | size_t * | utf16count, |
nlib_utf16_t * | utf16, | ||
size_t | buflen, | ||
const nlib_utf8_t * | utf8 | ||
) |
Converts a UTF-8 string into a UTF-16 string. The UTF-16 string is null-terminated.
[out] | utf16count | Stores the number of converted characters (the number of nlib_utf16_t -type characters, not including the null character). |
[out] | utf16 | The buffer for storing the converted string. |
[in] | buflen | The size of the utf16 buffer (the number of characters including the null character). |
[in] | utf8 | A UTF-8 string. |
0 | Success. |
EINVAL | Either utf16 is NULL and buflen > 0 , or utf8 is NULL . |
ERANGE | The converted string was too big to fit, so it has been stored in truncated form. |
EILSEQ | Data that cannot be converted was detected. |
nlib_utf16_t
-type characters) is set in *utf16count (providing that utf16count is not NULL
). NULL
and buflen is set to 0
, the number of converted UTF-16 (which is not necessarily the number of code points) is set in utf16count. 0
, utf16 is set to an empty string, and the function returns EILSEQ
. nlib_utf8_to_utf32 | ( | size_t * | utf32count, |
nlib_utf32_t * | utf32, | ||
size_t | buflen, | ||
const nlib_utf8_t * | utf8 | ||
) |
Converts a UTF-8 string into a UTF-32 string.
[out] | utf32count | Stores the number of converted characters (the number of nlib_utf32_t -type characters, not including the null character). |
[out] | utf32 | The buffer for storing the converted string. |
[out] | buflen | The size of the utf32 buffer (the number of characters including the null character). |
[in] | utf8 | A UTF-8 string. |
0 | No error occurred. |
EINVAL | Either utf32 is NULL and buflen > 0 , or utf8 is NULL . |
ERANGE | The converted string was too big to fit, so it has been stored in truncated form. |
EILSEQ | Data that cannot be converted was detected. |
nlib_utf32_t
-type characters) is set in *utf32count (providing that utf32count is not NULL
). NULL
and buflen is set to 0
, the number of converted UTF-32 is set in utf32count. 0
, utf32 is set to an empty string, and the function returns EILSEQ
. nlib_utf8_to_utf32char | ( | nlib_utf32_t * | utf32, |
const nlib_utf8_t * | utf8 | ||
) |
Converts UTF-8 into one character's worth of UTF-32.
[out] | utf32 | Stores the converted character. |
[in] | utf8 | A UTF-8 string. |
0 | Conversion was not possible. |
1 | Only utf8[0] was converted. |
2 | Indicates that utf8[0] and utf8[1] were converted. |
3 | Indicates that utf8[0] , utf8[1] , and utf8[2] were converted. |
4 | Indicates that utf8[0] , utf8[1] , utf8[2] , and utf8[3] were converted. |
nlib_utf8_to_wide | ( | size_t * | wccount, |
wchar_t * | wcstr, | ||
size_t | buflen, | ||
const nlib_utf8_t * | utf8 | ||
) |
Converts a UTF-8 string into a UTF-16/UTF-32 string.
[out] | wccount | Stores the number of converted characters (the number of wchar_t , not including the null character). |
[out] | wcstr | The buffer for storing the converted string. |
[in] | buflen | The size of the wcstr buffer (the number of characters including the null character). |
[in] | utf8 | A UTF-8 string. |
0
on success.nlib_utf8_to_utf16
or nlib_utf8_to_utf32
, depending on whether wchar_t
is 16 bits or 32 bits. nlib_virtual_alloc | ( | void ** | ptr, |
size_t | size | ||
) |
Allocates virtual memory address space.
[out] | ptr | The pointer to where the starting address of the allocated virtual memory address space gets written. |
[in] | size | The size (in bytes) of the virtual memory address space to allocate. |
0
on success.Platform | Implementation |
---|---|
Win32 | VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_READWRITE); |
Linux | mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); |
FreeBSD | mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); |
OS X | mmap(NULL, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); |
CAFE | MEMAllocFromDefaultHeapEx(size, OSGetPageSize()) |
CTR | Construction of MemoryBlock (can allocate up to eight regions). |
nlib_virtual_free | ( | void * | ptr, |
size_t | size | ||
) |
Frees the allocated virtual memory address space.
[in] | ptr | The value given to the nlib_virtual_alloc function. |
[in] | size | The value given to the nlib_virtual_alloc function. |
0
on success.nlib_virtual_alloc
function. Platform | Implementation |
---|---|
Win32 | VirtualFree(ptr, 0, MEM_RELEASE); |
Linux | munmap(ptr, size) |
FreeBSD | munmap(ptr, size) |
OS X | munmap(ptr, size) |
CAFE | MEMFreeToDefaultHeap(ptr) |
CTR | Destruction of MemoryBlock . |
nlib_vsnprintf | ( | size_t * | count, |
char * | buf, | ||
size_t | size, | ||
const char * | fmt, | ||
va_list | args | ||
) |
A safer form of vsnprintf
, with some differences from standard vsnprintf
behavior.
[out] | count | The number of written characters (not including the null character). |
[in] | buf | The buffer where the output is written. |
[in] | size | The size of the buffer (the number of characters including the null character). |
[in] | fmt | The format settings. |
[in] | args | An argument list. |
0 | Success. |
ERANGE | The output cannot fit in the buffer. |
EINVAL | Indicates that count is NULL . |
errno
settings of the vsnprintf
function that vary depending on the implementation. ERANGE
, the number of characters that would have been written is set in count, and a null-terminated string that fills the buffer is stored in buf. nlib_snprintf
, nlib_vdprintf
, nlib_dprintf
, and nlib_printf
. Platform | Implementation |
---|---|
Win32 | _vsnprintf_s_l + _vscprintf_l |
Linux | vsnprintf |
FreeBSD | vsnprintf |
OS X | vsnprintf |
CAFE | vsnprintf |
CTR | vsnprintf |
nlib_vsnwprintf | ( | size_t * | count, |
wchar_t * | buf, | ||
size_t | size, | ||
const wchar_t * | fmt, | ||
va_list | args | ||
) |
A safer form of vswprintf
, with some differences from standard vswprintf
behavior.
[out] | count | The number of written characters (not including the null character). |
[in] | buf | The buffer where the output is written. |
[in] | size | The size of the buffer (the number of characters including the null character). |
[in] | fmt | The format settings. |
[in] | args | An argument list. |
0 | Success. |
ERANGE | The output cannot fit in the buffer. |
EINVAL | Indicates that count is NULL . |
errno
settings of the vswprintf
function that vary depending on the implementation. ERANGE
, the number of characters that would have been written is set in count, and a null-terminated string that fills the buffer is stored in buf. nlib_snwprintf
, nlib_vdwprintf
, nlib_dwprintf
, and nlib_wprintf
. Platform | Implementation |
---|---|
Win32 | _vsnwprintf_s_l + _vscwprintf_l |
Linux | vswprintf + nlib_vsnwprintf_fallback() |
FreeBSD | nlib_vsnwprintf_fallback() |
OS X | nlib_vsnwprintf_fallback() |
CAFE | vswprintf + nlib_vsnwprintf_fallback() |
CTR | vswprintf + nlib_vsnwprintf_fallback() |
nlib_wcscplen | ( | size_t * | count, |
const wchar_t * | str | ||
) |
Gets the number of code points in the string.
[out] | count | Pointer to where the number of code points is stored. |
[in] | str | String. |
0 | Success. |
EINVAL | Indicates that count or str is NULL . |
EILSEQ | Some data cannot be converted into a code point. |
nlib_wcscpy | ( | wchar_t * | s1, |
size_t | s1max, | ||
const wchar_t * | s2 | ||
) |
An implementation corresponding to N1078 wcscpy_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_wcsnlen() + nlib_memcpy() |
Linux | nlib_wcsnlen() + nlib_memcpy() |
FreeBSD | nlib_wcsnlen() + nlib_memcpy() |
OS X | nlib_wcsnlen() + nlib_memcpy() |
CAFE | nlib_wcsnlen() + nlib_memcpy() |
CTR | nlib_wcsnlen() + nlib_memcpy() |
nlib_wcslen | ( | const wchar_t * | s | ) |
Makes a call to thewcslen
function. In some cases, it may operate as an independent implementation.
[in] | s | Pointer to the string. |
0
if s is NULL
. nlib_wcsncpy | ( | wchar_t * | s1, |
size_t | s1max, | ||
const wchar_t * | s2, | ||
size_t | n | ||
) |
An implementation corresponding to N1078 wcsncpy_s
.
[in,out] | s1 | The buffer to copy to. |
[in] | s1max | The size (number of characters) of the buffer to copy to. |
[in] | s2 | The buffer to copy from. |
[in] | n | The number of characters to copy. |
0 | Success. |
EINVAL | Indicates that s1 or s2 is NULL . |
ERANGE | The buffer is not large enough. |
s1[0]=0
is set if the function fails and s1 is not NULL
. The behavior is undefined if the buffers overlap. Platform | Implementation |
---|---|
Win32 | nlib_wcsnlen() + nlib_memcpy() |
Linux | nlib_wcsnlen() + nlib_memcpy() |
FreeBSD | nlib_wcsnlen() + nlib_memcpy() |
OS X | nlib_wcsnlen() + nlib_memcpy() |
CAFE | nlib_wcsnlen() + nlib_memcpy() |
CTR | nlib_wcsnlen() + nlib_memcpy() |
nlib_wcsnlen | ( | const wchar_t * | s, |
size_t | maxsize | ||
) |
An implementation corresponding to N1078 wcsnlen_s
.
[in] | s | Pointer to the string. |
[in] | maxsize | The size of the string. (The maximum number for the return value.) |
0
if s is NULL
. Returns maxsize if the string is longer than maxsize. Platform | Implementation |
---|---|
Win32 | nlib_utf16nlen() |
Linux | nlib_utf32nlen() |
FreeBSD | nlib_utf32nlen() |
OS X | nlib_utf32nlen() |
CAFE | nlib_utf16nlen() |
CTR | nlib_utf16nlen() |
nlib_wide_to_utf8 | ( | size_t * | utf8count, |
nlib_utf8_t * | utf8, | ||
size_t | buflen, | ||
const wchar_t * | wcstr | ||
) |
Converts a UTF-16/UTF-32 string into a UTF-8 string.
[out] | utf8count | Stores the number of converted characters (the number of char , not including the null character). |
[out] | utf8 | The buffer for storing the converted string. |
[in] | buflen | The size of the utf8 buffer (the number of characters including the null character). |
[in] | wcstr | A UTF-16/UTF-32 string. |
0
on success.nlib_utf16_to_utf8
or nlib_utf32_to_utf8
, depending on whether wchar_t
is 16 bits or 32 bits. nlib_write_stderr | ( | size_t * | result, |
const void * | buf, | ||
size_t | count | ||
) |
Writes a string to standard error output.
[out] | result | The number of characters written. |
[in] | buf | Pointer to a UTF-8 string (without a NULL terminator). |
[in] | count | The number of characters. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | MultiByteToWideChar() + GetStdHandle(STD_ERROR_HANDLE) + WriteConsoleW() |
Linux | write() |
FreeBSD | write() |
OS X | write() |
CAFE | OSConsoleWrite() |
CTR | nn::dbg::detail::PutString() |
nlib_write_stdout | ( | size_t * | result, |
const void * | buf, | ||
size_t | count | ||
) |
Writes a string to standard output.
[out] | result | The number of characters written. |
[in] | buf | Pointer to a UTF-8 string (without a NULL terminator). |
[in] | count | The number of characters. |
0 | Success. |
Platform | Implementation |
---|---|
Win32 | MultiByteToWideChar() + GetStdHandle(STD_OUTPUT_HANDLE) + WriteConsoleW() |
Linux | write() - If errno is EINTR , the function is executed again internally. |
FreeBSD | write() - If errno is EINTR , the function is executed again internally. |
OS X | write() - If errno is EINTR , the function is executed again internally. |
CAFE | OSConsoleWrite() |
CTR | nn::dbg::detail::PutString() |
nlib_mq_attr::flag |
Settings to be used when creating a message queue.
Value | Description |
---|---|
NLIB_MQ_BLOCK | When reading an empty queue or writing into a full queue, blocks and waits. |
NLIB_MQ_NONBLOCK | Returns an error (EAGAIN ) when it would normally blocks. |
NLIB_MQ_LOCKFREE | Creates a lock-free queue. Returns an error (EAGAIN ) when it would normally blocks. |
Definition at line 1153 of file Platform.h.
© 2012-2017 Nintendo Co., Ltd. All rights reserved.