nlib
Platform.h ファイル

基本的なAPIがCリンケージで宣言されています。 [詳解]

#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "nn/nlib/Platform_unix.h"
#include <smmintrin.h>
#include <nmmintrin.h>
#include <stdint.h>
#include <inttypes.h>
#include "nn/nlib/Platform_socket.h"
#include <errno.h>

[ソースコード]

クラス

struct  nlib_timerspec
 タイマーの初回起動までの時間と以降の起動間隔を指定します。両方0を指定した場合タイマーは停止します。 [詳解]
 
struct  nlib_mq_attr
 メッセージキューの設定や現在の状態を格納する構造体です。 [詳解]
 

マクロ定義

#define RSIZE_MAX   0x7FFFFFFFFFFFFFFFLL
 size_tの最大値よりいくらか小さい値が定義されています。 [詳解]
 
バージョン

nlibのバージョンを取得するためのマクロと関数です。

#define NLIB_VERSION_YEAR   2017
 バージョン番号の年に相当する部分が整数として定義されています。
 
#define NLIB_VERSION_YEAR_SHORT   17
 バージョン番号の年部分の下二桁に相当する部分が整数として定義されています。
 
#define NLIB_VERSION_DATE   0926
 バージョン番号の月日に相当する部分が整数として定義されています。
 
#define NLIB_VERSION   20170926
 バージョン番号が定義されています。リリースの年月日に相当する数値が定義されています。
 
アトリビュート

コンパイラ毎のアトリビュートの違いを吸収するためのマクロです。

#define NLIB_WARN(exp)   ("WARNING: " exp)
 ワーニングを出力します。 [詳解]
 
#define NLIB_ASSUME(cond)   switch (0) case 0: default: if (cond) ; else __builtin_unreachable() /* NOLINT */
 cond が真であることを示してコンパイラに最適化のヒントを与えます。 [詳解]
 

型定義

typedef unsigned char nlib_byte_t
 C++17以降でstd::byteにtypedefされる型です。
 
typedef int32_t nlib_long_compatible_t
 longと互換性のある整数型がtypedefされています。
 
typedef uint32_t nlib_ulong_compatible_t
 unsigned longと互換性のある整数型がtypedefされています。
 

関数

エラー

エラー値に関するユーティリティです。

const char * nlib_error_string (errno_t e)
 nlibのエラー値に対応する文字列リテラルを返します。 [詳解]
 
CRC-32, CRC-32C

SSE又はNEONが利用できる場合は、専用命令を利用して高速に計算を行います。

uint32_t nlib_crc32 (uint32_t crc32, const void *p, size_t n)
 データのCRC-32チェックサムを計算する関数です。 [詳解]
 
uint32_t nlib_crc32c (uint32_t crc32c, const void *p, size_t n)
 データのCRC-32Cチェックサムを計算する関数です。 [詳解]
 
ランダム値の生成
errno_t nlib_gen_random (void *buf, size_t size)
 ランダムな値をsize バイト生成してbuf に格納します。 [詳解]
 
OSからのメモリ割り当て

OSからの仮想メモリ空間の割当及び解放と、物理メモリの割当及び解放を行います。

errno_t nlib_mempagesize (size_t *size)
 ページサイズを取得します。 [詳解]
 
errno_t nlib_virtual_alloc (void **ptr, size_t size)
 仮想メモリアドレス空間を割り当てます。 [詳解]
 
errno_t nlib_virtual_free (void *ptr, size_t size)
 仮想メモリアドレス空間の割り当てを解除します [詳解]
 
errno_t nlib_physical_alloc (void *ptr, size_t size, int prot)
 物理メモリを割り当てます。 [詳解]
 
errno_t nlib_physical_free (void *ptr, size_t size)
 物理メモリの割り当てを解除します。 [詳解]
 
errno_t nlib_mlock (void *addr, size_t len)
 指定したメモリ領域がスワップアウトされないようにします。 [詳解]
 
errno_t nlib_munlock (void *addr, size_t len)
 指定したメモリ領域がスワップアウトできるようにします。 [詳解]
 
ミューテックス

pthreadのミューテックスに準じたI/Fを提供しています。

errno_t nlib_mutex_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex)
 ミューテックスを初期化します。 [詳解]
 
errno_t nlib_mutex_recursive_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex)
 再帰ミューテックスを初期化します。 [詳解]
 
errno_t nlib_mutex_recursive_timed_init (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex)
 再帰かつタイムアウト可能なミューテックスを初期化します。 [詳解]
 
errno_t nlib_mutex_lock (nlib_mutex *mutex) NLIB_ACQUIRE(*mutex)
 与えられたmutexをロックします。 [詳解]
 
errno_t nlib_mutex_trylock (nlib_mutex *mutex) NLIB_TRY_ACQUIRE(0
 mutexがロックされていない場合のみロックします。 [詳解]
 
errno_t nlib_mutex_trylock_for (nlib_mutex *mutex, nlib_duration delta) NLIB_TRY_ACQUIRE(0
 与えられたmutexをロックします。タイムアウトします。 [詳解]
 
errno_t nlib_mutex_unlock (nlib_mutex *mutex) NLIB_RELEASE(*mutex)
 与えられたmutex をアンロックします。 [詳解]
 
errno_t nlib_mutex_destroy (nlib_mutex *mutex) NLIB_EXCLUDES(*mutex)
 mutexオブジェクトを破壊し、関連付けられているリソース(あれば)を解放します。 [詳解]
 
static errno_t nlib_mutex_trylock_for_timespec (nlib_mutex *mutex, const struct timespec *tm) NLIB_TRY_ACQUIRE(0
 nlib_mutex_trylock_for()の引数にtimespec構造体を取るバージョンです。
 
セマフォ
errno_t nlib_semaphore_init (nlib_semaphore *sem, int initial_count)
 sem で指定されるセマフォオブジェクトを初期化する。 [詳解]
 
errno_t nlib_semaphore_wait (nlib_semaphore *sem)
 セマフォカウントが0でなくなるまで待って、セマフォカウントを1減少させる。 [詳解]
 
errno_t nlib_semaphore_trywait (nlib_semaphore *sem)
 セマフォカウントが0でなければ、セマフォカウントを1減少させる。 [詳解]
 
errno_t nlib_semaphore_trywait_for (nlib_semaphore *sem, nlib_duration duration)
 セマフォカウントが0でなければ、セマフォカウントを1減少させる。0の場合はduration の期間だけ待つ。 [詳解]
 
errno_t nlib_semaphore_post (nlib_semaphore *sem, int *previous_count)
 セマフォカウントを1つ増加させる。 [詳解]
 
errno_t nlib_semaphore_post_ex (nlib_semaphore *sem, int release_count, int *previous_count)
 セマフォカウントをreleaseCount 増加させる。 [詳解]
 
errno_t nlib_semaphore_destroy (nlib_semaphore *sem)
 セマフォオブジェクトを破壊する。 [詳解]
 
static errno_t nlib_semaphore_trywait_for_timespec (nlib_semaphore *sem, const struct timespec *tm)
 nlib_semaphore_trywait_for()の引数にtimespec構造体を取るバージョンです。
 
条件変数

pthreadの条件変数に準じたI/Fを提供しています。

errno_t nlib_cond_init (nlib_cond *cond)
 条件変数を初期化します。 [詳解]
 
errno_t nlib_cond_signal (nlib_cond *cond)
 条件変数cond を待っているスレッドの1つの実行を再開させます。 [詳解]
 
errno_t nlib_cond_broadcast (nlib_cond *cond)
 条件変数cond を待っているスレッド全ての実行を再開させます。 [詳解]
 
errno_t nlib_cond_wait (nlib_cond *cond, nlib_mutex *mutex) NLIB_REQUIRES(*mutex)
 mutexをアンロックし、条件変数を待機します。実行が再開したらmutexを再ロックします。 [詳解]
 
errno_t nlib_cond_wait_for (nlib_cond *cond, nlib_mutex *mutex, nlib_duration duration) NLIB_REQUIRES(*mutex)
 mutexをアンロックし、条件変数をduration の間だけ待機します。実行が再開したらmutexを再ロックします。 [詳解]
 
errno_t nlib_cond_wait_until (nlib_cond *cond, nlib_mutex *mutex, nlib_time abstime) NLIB_REQUIRES(*mutex)
 mutexをアンロックし、条件変数をabstimeまで待機します。実行が再開したらmutexを再ロックします。 [詳解]
 
errno_t nlib_cond_destroy (nlib_cond *cond)
 条件変数オブジェクトを破壊します。 [詳解]
 
static errno_t nlib_cond_wait_for_timespec (nlib_cond *cond, nlib_mutex *mutex, const struct timespec *tm) NLIB_REQUIRES(*mutex)
 nlib_cond_wait_for()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_cond_wait_until_timespec (nlib_cond *cond, nlib_mutex *mutex, const struct timespec *tm) NLIB_REQUIRES(*mutex)
 nlib_cond_wait_until()の引数にtimespec構造体を取るバージョンです。
 
デバック, デバック出力
errno_t nlib_write_stdout (size_t *result, const void *buf, size_t count)
 標準出力に文字列を書き出します。 [詳解]
 
errno_t nlib_write_stderr (size_t *result, const void *buf, size_t count)
 標準エラー出力に文字列を書き出します。 [詳解]
 
errno_t nlib_debug_backtrace (size_t *result, void **buffer, size_t count)
 バックトレースをbuffer が指す配列に格納します。 [詳解]
 
errno_t nlib_debug_backtrace_gettext (char *str, size_t strbufsize, void *const *buf, size_t count)
 nlib_debug_backtrace()で得られた情報から文字列情報を作成します。 [詳解]
 
errno_t nlib_getenv (size_t *result, char *buf, size_t bufsize, const char *varname)
 環境変数の値を文字列で取得します。 [詳解]
 
メモリ領域のコピー、比較、探索
static errno_t nlib_memcpy (void *s1, size_t s1max, const void *s2, size_t n)
 N1078のmemcpy_sに相当する実装です。 [詳解]
 
static errno_t nlib_memmove (void *s1, size_t s1max, const void *s2, size_t n)
 N1078のmemmove_sに相当する実装です。 [詳解]
 
static errno_t nlib_memset (void *buf, int ch, size_t n)
 内部でmemset(buf, ch, n)相当の関数を呼び出します。 [詳解]
 
void * nlib_memccpy (void *dest, size_t dest_size, const void *src, size_t src_size, int c)
 cが見つかるまでコピーを行います。見つかった場合そこでコピーを中止します。 [詳解]
 
int nlib_memcmp (const void *buf1, const void *buf2, size_t n)
 buf1buf2 を先頭からn バイト分unsigned charとして比較します。 [詳解]
 
const void * nlib_memchr (const void *s, int c, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc があるポインタを返します。 [詳解]
 
const void * nlib_memrchr (const void *s, int c, size_t n)
 メモリ領域[s, s + n)の後方からn バイトを検索して、バイトc があるポインタを返します。 [詳解]
 
const void * nlib_memchr_not (const void *s, int c, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc でないポインタを返します。 [詳解]
 
const void * nlib_memchr_range_not (const void *s, const char *range, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、最初のrange に含まない文字へのポインタを返します。 [詳解]
 
const void * nlib_memchr_lt (const void *s, int c, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc 未満の文字があるデータへのポインタを返します。 [詳解]
 
const void * nlib_memchr_gt (const void *s, int c, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc より大きいの文字があるデータへのポインタを返します。 [詳解]
 
const void * nlib_memchr_mb (const void *s, size_t n)
 メモリ領域[s, s + n)の先頭からn バイトを検索して、0x80以上のバイトが格納されている場所へのポインタを返します。 [詳解]
 
size_t nlib_memspn (const void *buf, size_t len, const char *set, size_t n)
 bufの先頭から続く部分バイト列の長さを返します。 部分バイト列は、setに含まれるバイトのみで構成されます。 [詳解]
 
size_t nlib_memcspn (const void *buf, size_t len, const char *set, size_t n)
 bufの先頭から続く部分バイト列の長さを返します。 部分バイト列は、setに含まれるバイト以外のみで構成されます。 [詳解]
 
ヌル終端文字列のための関数
const char * nlib_skipws (size_t *cnt_lf, const char **last_lf, const char *s, size_t n)
 n 個の文字から成る文字列を探索して最初の空白でない文字へのポインタを返します。 [詳解]
 
size_t nlib_strlen (const char *s)
 内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。 [詳解]
 
size_t nlib_strnlen (const char *s, size_t maxsize)
 N1078のstrnlen_sに相当する実装です。 [詳解]
 
errno_t nlib_strcpy (char *s1, size_t s1max, const char *s2)
 N1078のstrcpy_sに相当する実装です。 [詳解]
 
errno_t nlib_strncpy (char *s1, size_t s1max, const char *s2, size_t n)
 N1078のstrncpy_sに相当する実装です。 [詳解]
 
const char * nlib_strchr (const char *s, int c)
 文字列の先頭から文字を検索します。 [詳解]
 
const char * nlib_strrchr (const char *s, int c)
 文字列の末尾から文字を検索します。 [詳解]
 
size_t nlib_wcslen (const wchar_t *s)
 内部でwcslen()を呼び出します。独自の実装が動作する場合もあります。 [詳解]
 
size_t nlib_wcsnlen (const wchar_t *s, size_t maxsize)
 N1078のwcsnlen_sに相当する実装です。 [詳解]
 
errno_t nlib_wcscpy (wchar_t *s1, size_t s1max, const wchar_t *s2)
 N1078のwcscpy_sに相当する実装です。 [詳解]
 
errno_t nlib_wcsncpy (wchar_t *s1, size_t s1max, const wchar_t *s2, size_t n)
 N1078のwcsncpy_sに相当する実装です。 [詳解]
 
strtol()代替

strtol()を代替します。詳しくはnlib_strto_int32()の項目を御覧ください。

errno_t nlib_strto_int32 (int32_t *result, const char *nptr, char **endptr, int base)
 文字列をint32_t型に変換します。 [詳解]
 
errno_t nlib_strto_int64 (int64_t *result, const char *nptr, char **endptr, int base)
 文字列をint64_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_uint32 (uint32_t *result, const char *nptr, char **endptr, int base)
 文字列をuint32_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_uint64 (uint64_t *result, const char *nptr, char **endptr, int base)
 文字列をuint64_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_double (double *result, const char *nptr, char **endptr)
 文字列をdouble型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_float (float *result, const char *nptr, char **endptr)
 文字列をfloat型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_int32_fallback (int32_t *result, const char *nptr, char **endptr, int base)
 C標準関数を使わずに文字列をint32_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_int64_fallback (int64_t *result, const char *nptr, char **endptr, int base)
 C標準関数を使わずに文字列をint64_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_uint32_fallback (uint32_t *result, const char *nptr, char **endptr, int base)
 C標準関数を使わずに文字列をuint32_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_uint64_fallback (uint64_t *result, const char *nptr, char **endptr, int base)
 C標準関数を使わずに文字列をuint64_t型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_double_fallback (double *result, const char *nptr, char **endptr)
 C標準関数を使わずに文字列をdouble型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
errno_t nlib_strto_float_fallback (float *result, const char *nptr, char **endptr)
 C標準関数を使わずに文字列をfloat型に変換します。詳しくはnlib_strto_int32()を参照してください。
 
strtol()代替その2

C++17で導入されているfrom_chars()を用いた実装です。標準C++ライブラリに存在しない場合は代替実装が用いられます。詳しくはnlib_int32_from_chars()の項目を御覧ください。

errno_t nlib_int8_from_chars (int8_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をint8_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_int16_from_chars (int16_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をint16_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_int32_from_chars (int32_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をint32_t型に変換します。 [詳解]
 
errno_t nlib_int64_from_chars (int64_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をint64_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_uint8_from_chars (uint8_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をuint8_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_uint16_from_chars (uint16_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をuint16_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_uint32_from_chars (uint32_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をuint32_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_uint64_from_chars (uint64_t *result, const char **endptr, const char *first, const char *last, int base)
 文字列をuint64_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。
 
errno_t nlib_double_from_chars (double *result, const char **endptr, const char *first, const char *last)
 文字列をdouble型に変換します。 [詳解]
 
errno_t nlib_float_from_chars (float *result, const char **endptr, const char *first, const char *last)
 文字列をfloat型に変換します。詳しくはnlib_double_from_chars()の項目を御覧ください。
 
malloc
void * nlib_malloc (size_t size)
 C標準関数のmalloc()を呼び出すweak関数です。nlibはこの関数を経由してmalloc()を呼び出します。 [詳解]
 
void nlib_free (void *ptr)
 C標準関数のfree()を呼び出すweak関数です。nlibはこの関数を経由してfree()を呼び出します。 [詳解]
 
void * nlib_calloc (size_t nmemb, size_t size)
 C標準関数のcalloc()を呼び出すweak関数です。nlibはこの関数を経由してcalloc()を呼び出します。 [詳解]
 
void * nlib_realloc (void *ptr, size_t size)
 C標準関数のrealloc()を呼び出すweak関数です。nlibはこの関数を経由してrealloc()を呼び出します。 [詳解]
 
size_t nlib_malloc_size (const void *ptr)
 アロケートされたメモリのサイズを返します。 [詳解]
 
void nlib_free_size (void *ptr, size_t size)
 サイズを指定してメモリを解放します。デフォルトではnlib_free()を呼び出します。 [詳解]
 
void * nlib_memalign (size_t alignment, size_t size)
 memalign()を呼び出すweak関数です。nlibはこの関数を経由してmemalign()を呼び出します。 [詳解]
 
ctype.h代替

C標準ヘッダctype.hで宣言されている関数の代替です。ロケールの影響を受けません。

static int nlib_isalnum (int ch)
 chがASCII文字の'0'-'9', 'A'-'Z', または'a'-'z'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isalpha (int ch)
 chがASCII文字の'A'-'Z', または'a'-'z'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isblank (int ch)
 chがASCII文字の' 'または'\t'である場合に非0、そうでない場合に0を返します。
 
static int nlib_iscntrl (int ch)
 chがASCIIコードの0から31、または127である場合に非0、そうでない場合に0を返します。
 
static int nlib_isdigit (int ch)
 chがASCII文字の'0'-'9'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isgraph (int ch)
 chがASCII文字の33から126である場合に非0、そうでない場合に0を返します。
 
static int nlib_islower (int ch)
 chがASCII文字の'a'-'z'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isprint (int ch)
 chがASCII文字の32から126である場合に非0、そうでない場合に0を返します。
 
static int nlib_ispunct (int ch)
 chがASCII文字の0から32、または127である場合に非0、そうでない場合に0を返します。
 
static int nlib_isspace (int ch)
 chがASCII文字の' ', '\t', または'\n'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isupper (int ch)
 chがASCII文字の'A'-'Z'である場合に非0、そうでない場合に0を返します。
 
static int nlib_isxdigit (int ch)
 chがASCII文字の'0'-'9', 'A'-'F', または'a'-'f'である場合に非0、そうでない場合に0を返します。
 
static int nlib_tolower (int ch)
 chがASCII文字の'A'-'Z'である場合に小文字にしたものを、そうでない場合にchを返します。
 
static int nlib_toupper (int ch)
 chがASCII文字の'a'-'z'である場合に大文字にしたものを、そうでない場合にchを返します。
 
count leading zeros, count trailing zeros, popcnt, bitreverse
static int nlib_popcnt16 (uint16_t x)
 1となっているビットの数を返します。 [詳解]
 
static int nlib_popcnt32 (uint32_t x)
 1となっているビットの数を返します。 [詳解]
 
static int nlib_popcnt64 (uint64_t x)
 1となっているビットの数を返します。 [詳解]
 
static int nlib_clz32 (uint32_t x)
 MSB(most significant bit)から見て連続する0ビットの数を返します。 [詳解]
 
static int nlib_ctz32 (uint32_t x)
 LSB(least significant bit)から見て連続する0ビットの数を返します。 [詳解]
 
static int nlib_clz64 (uint64_t x)
 MSB(most significant bit)から見て連続する0ビットの数を返します。 [詳解]
 
static int nlib_ctz64 (uint64_t x)
 LSB(least significant bit)から見て連続する0ビットの数を返します。 [詳解]
 
static uint32_t nlib_bitreverse32 (uint32_t x)
 32ビット整数のビットの並び順を反転させます。 [詳解]
 
static uint64_t nlib_bitreverse64 (uint64_t x)
 64ビット整数のビットの並び順を反転させます。 [詳解]
 

時刻と時間

時刻や経過時間を取得したりスリープを行う関数です。

typedef int64_t nlib_time
 1970/01/01を起点(0)としてから100ns刻みで時刻を表現する型です。64bit符号付き整数です。
 
typedef int64_t nlib_duration
 100ns刻みで時間を表現する型です。64bit符号付き整数です。
 
errno_t nlib_epochtime (nlib_time *t)
 現在時刻を取得します。 [詳解]
 
errno_t nlib_ticktime (nlib_duration *t)
 ブートからの経過時間を取得します。 [詳解]
 
errno_t nlib_sleep (nlib_duration t)
 t の間スリープする。 [詳解]
 
static errno_t nlib_epochtime_timespec (struct timespec *tm)
 nlib_epochtime()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_ticktime_timespec (struct timespec *tm)
 nlib_ticktime()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_sleep_timespec (const struct timespec *tm)
 nlib_sleep()の引数にtimespec構造体を取るバージョンです。
 

タイマー

定期的にタスクを実行します。

typedef uint32_t nlib_timer
 nlib_timer_create()nlib_timer_delete()で利用するタイマーのIDです。
 
typedef void(* nlib_timer_callback) (nlib_timer timer, void *param)
 nlib_timer_create()で設定するコールバック関数の型です。
 
errno_t nlib_timer_create (nlib_timer *timer, nlib_timer_callback callback, void *param, uint32_t flags)
 タイマーを作成します。 [詳解]
 
errno_t nlib_timer_settime (nlib_timer timer, const nlib_timerspec *new_value, nlib_timerspec *old_value)
 タイマーを開始したり一時停止したりします。 [詳解]
 
errno_t nlib_timer_gettime (nlib_timer timer, nlib_timerspec *curr_value)
 タイマーの現在の設定を取得します。 [詳解]
 
errno_t nlib_timer_delete (nlib_timer timer, int wait_completion, nlib_timer_callback completion_callback)
 タイマーを削除します。 [詳解]
 

TLS

Thread local storage(TLS)はスレッド毎に異なるメモリにアクセスするための仕組みです。

#define NLIB_TLS_INVALID   (nlib_tls)(-1)
 無効なTLSスロットのIDを指し示す値
 
typedef void(* nlib_tls_destructor) (void *tls_value)
 スレッド終了時に呼び出されるTLSのデストラクタ関数の型です。 [詳解]
 
errno_t nlib_tls_alloc (nlib_tls *tls, nlib_tls_destructor destr)
 TLSスロットに対する新しいIDを確保します。 [詳解]
 
errno_t nlib_tls_free (nlib_tls tls)
 TLSスロットに対応するIDを解放します。 [詳解]
 
errno_t nlib_tls_setvalue (nlib_tls tls, const void *value)
 TLSスロットに値を格納します。 [詳解]
 
errno_t nlib_tls_getvalue (nlib_tls tls, void **value)
 TLSスロットから値を取り出します。 [詳解]
 

スピンロック

スピンロックを行います。スピンロックの初期化を静的に行うことができます。

#define NLIB_SPINLOCK_INITIALIZER   (0)
 nlib_spinlockを静的に初期化するためのマクロです。
 
typedef int32_t nlib_spinlock
 スピンロック変数の型です。NLIB_SPINLOCK_INITIALIZERにより静的に初期化して利用します。 [詳解]
 
static void nlib_spinlock_init (nlib_spinlock *lock)
 スピンロックを初期化します。 [詳解]
 
static void nlib_spinlock_lock (nlib_spinlock *lock)
 スピンロックをロックします。再帰ロックを行った場合の動作は不定です。 [詳解]
 
static errno_t nlib_spinlock_trylock (nlib_spinlock *lock)
 スピンロックをロックします。成功した場合は0を返し、失敗した場合はEBUSYを返します。 [詳解]
 
static void nlib_spinlock_unlock (nlib_spinlock *lock)
 スピンロックをアンロックします。 [詳解]
 

リードライトロック

リードライトロックは複数のリーダーによる同時アクセスを許可しつつ、更新時にはライターによる排他アクセスのみを許可する仕組みです。

#define NLIB_RWLOCK_INITIALIZER
 nlib_rwlockを静的に初期化するための定数です。
 
typedef struct nlib_rwlock_ nlib_rwlock
 リードライトロックオブジェクトの型です。 [詳解]
 
errno_t nlib_rwlock_init (nlib_rwlock *rwlock) NLIB_EXCLUDES(*rwlock)
 リードライトロックを初期化します。 [詳解]
 
errno_t nlib_rwlock_destroy (nlib_rwlock *rwlock) NLIB_EXCLUDES(*rwlock)
 リードライトロックオブジェクトを破壊します。 [詳解]
 
errno_t nlib_rwlock_rdlock (nlib_rwlock *rwlock) NLIB_ACQUIRE_SHARED(*rwlock)
 読み込みロックを取得しクリティカルセクションに入ります。取得できるまでブロックします。 [詳解]
 
errno_t nlib_rwlock_tryrdlock (nlib_rwlock *rwlock) NLIB_TRY_ACQUIRE_SHARED(0
 読み込みロックを取得しクリティカルセクションに入ることを試みます。 [詳解]
 
errno_t nlib_rwlock_tryrdlock_for (nlib_rwlock *rwlock, nlib_duration duration) NLIB_TRY_ACQUIRE_SHARED(0
 読み込みロックを取得しクリティカルセクションに入ることを試みます。タイムアウトします。 [詳解]
 
errno_t nlib_rwlock_tryrdlock_until (nlib_rwlock *rwlock, nlib_time abstime) NLIB_TRY_ACQUIRE_SHARED(0
 読み込みロックを取得しクリティカルセクションに入ることを試みます。タイムアウトします。 [詳解]
 
errno_t nlib_rwlock_rdunlock (nlib_rwlock *rwlock) NLIB_RELEASE_SHARED(*rwlock)
 読み込みロックを解放します。 [詳解]
 
errno_t nlib_rwlock_wrlock (nlib_rwlock *rwlock) NLIB_ACQUIRE(*rwlock)
 書き込みロックを取得しクリティカルセクションに入ります。取得できるまでブロックします。 [詳解]
 
errno_t nlib_rwlock_trywrlock (nlib_rwlock *rwlock) NLIB_TRY_ACQUIRE(0
 書き込みロックを取得しクリティカルセクションに入ることを試みます。 [詳解]
 
errno_t nlib_rwlock_trywrlock_for (nlib_rwlock *rwlock, nlib_duration duration) NLIB_TRY_ACQUIRE(0
 書き込みロックを取得しクリティカルセクションに入ることを試みます。タイムアウトします。 [詳解]
 
errno_t nlib_rwlock_trywrlock_until (nlib_rwlock *rwlock, nlib_time abstime) NLIB_TRY_ACQUIRE(0
 書き込みロックを取得しクリティカルセクションに入ることを試みます。タイムアウトします。 [詳解]
 
errno_t nlib_rwlock_wrunlock (nlib_rwlock *rwlock) NLIB_RELEASE(*rwlock)
 書き込みロックを解放します。 [詳解]
 
static errno_t nlib_rwlock_tryrdlock_for_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE_SHARED(0
 nlib_rwlock_tryrdlock_for()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_rwlock_tryrdlock_until_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE_SHARED(0
 nlib_rwlock_tryrdlock_until()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_rwlock_trywrlock_for_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE(0
 nlib_rwlock_trywrlock_for()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_rwlock_trywrlock_until_timespec (nlib_rwlock *rwlock, const struct timespec *tm) NLIB_TRY_ACQUIRE(0
 nlib_rwlock_trywrlock_until()の引数にtimespec構造体を取るバージョンです。
 

リードライトロック用条件変数

nlib_rwlockに対して利用することのできる条件変数です。

#define NLIB_CONDRWLOCK_INITIALIZER   { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER }
 nlib_condrwlockを静的に初期化するための定数です。
 
typedef struct nlib_condrwlock_ nlib_condrwlock
 リードライトロック用の条件変数の型です。 [詳解]
 
errno_t nlib_condrwlock_init (nlib_condrwlock *cond)
 リードライトロック用条件変数を初期化します。 [詳解]
 
errno_t nlib_condrwlock_destroy (nlib_condrwlock *cond)
 リードライトロック用条件変数を破壊します。 [詳解]
 
errno_t nlib_condrwlock_signal (nlib_condrwlock *cond)
 リードライトロック用条件変数cond を待っているスレッドの1つの実行を再開させます。 [詳解]
 
errno_t nlib_condrwlock_broadcast (nlib_condrwlock *cond)
 リードライトロック用条件変数cond を待っているスレッド全ての実行を再開させます。 [詳解]
 
errno_t nlib_condrwlock_wait (nlib_condrwlock *cond, nlib_rwlock *rwlock, int rdlock)
 rwlockをアンロックし、条件変数を待機します。実行が再開したらrwlockを再ロックします。 [詳解]
 
errno_t nlib_condrwlock_wait_for (nlib_condrwlock *cond, nlib_rwlock *rwlock, nlib_duration duration, int rdlock)
 rwlockをアンロックし、条件変数を待機します。実行が再開したらrwlockを再ロックします。 [詳解]
 
errno_t nlib_condrwlock_wait_until (nlib_condrwlock *cond, nlib_rwlock *rwlock, nlib_time abstime, int rdlock)
 rwlockをアンロックし、条件変数を待機します。実行が再開したらrwlockを再ロックします。 [詳解]
 
static errno_t nlib_condrwlock_wait_for_timespec (nlib_condrwlock *cond, nlib_rwlock *rwlock, const struct timespec *tm, int rdlock)
 nlib_condrwlock_wait_for_timespec()の引数にtimespec構造体を取るバージョンです。
 
static errno_t nlib_condrwlock_wait_until_timespec (nlib_condrwlock *cond, nlib_rwlock *rwlock, const struct timespec *tm, int rdlock)
 nlib_condrwlock_wait_until_timespec()の引数にtimespec構造体を取るバージョンです。
 

バリア

複数のスレッドを特定のタスクの完了に同期させます。繰り返し利用可能です。

typedef struct nlib_barrier_ nlib_barrier
 バリアオブジェクトの型です。 [詳解]
 
errno_t nlib_barrier_init (nlib_barrier *barrier, unsigned int count)
 バリアオブジェクトを初期化します。 [詳解]
 
errno_t nlib_barrier_destroy (nlib_barrier *barrier)
 バリアオブジェクトを破壊します。 [詳解]
 
errno_t nlib_barrier_wait (nlib_barrier *barrier)
 スレッドの待ち合わせを行います。 [詳解]
 

1回のみの実行

特定の処理が1回だけ実行されることを保証するための仕組みです。

#define NLIB_ONCE_INIT   { 0 }
 nlib_onceflagを静的に初期化するための値
 
typedef struct nlib_onceflag_ nlib_onceflag
 nlib_onceで利用される構造体
 
typedef void(* nlib_oncefunc) (void)
 nlib_onceで実行される関数の型
 
errno_t nlib_once (nlib_onceflag *flag, nlib_oncefunc func)
 func を高々1回しか実行されないようします。 [詳解]
 

メッセージキュー

nlibのメッセージキューの特徴についてはnlib_mq_open()をご覧ください。

typedef int32_t nlib_mq
 メッセージキューに関連付けられるハンドルです。ハンドルがゼロクリア(memset()を利用してください)された場合、必ず無効ハンドルとなります。
 
typedef void * nlib_mq_msg
 メッセージキューに格納されるメッセージの型です。
 
typedef void(* nlib_mq_msg_destructor) (nlib_mq_msg)
 メッセージキューから取り出したメッセージのデストラクタ関数です。
 
errno_t nlib_mq_open (nlib_mq *mq, const nlib_mq_attr *attr)
 スレッド間でメッセージをやりとりするためのメッセージキューを作成します。 [詳解]
 
errno_t nlib_mq_getattr (nlib_mq mq, nlib_mq_attr *attr)
 ハンドルで示されるメッセージキューに設定されている属性を取得します。 [詳解]
 
errno_t nlib_mq_close (nlib_mq mq)
 ハンドルで示されるメッセージキューをクローズします。 [詳解]
 
errno_t nlib_mq_readonly (nlib_mq mq)
 ハンドルで示されるメッセージキューを受信専用にします。 [詳解]
 
errno_t nlib_mq_send (nlib_mq mq, nlib_mq_msg msg, int prio)
 メッセージをキューに送信します。 [詳解]
 
errno_t nlib_mq_send_until (nlib_mq mq, nlib_mq_msg msg, int prio, nlib_time abstime)
 メッセージをキューにタイムアウトつきで送信します。 [詳解]
 
errno_t nlib_mq_receive (nlib_mq mq, nlib_mq_msg *msg, int *prio)
 メッセージをキューから受信します。受信したメッセージはユーザーがデストラクタ関数で削除する必要があります。 [詳解]
 
errno_t nlib_mq_receive_until (nlib_mq mq, nlib_mq_msg *msg, int *prio, nlib_time abstime)
 メッセージをキューからタイムアウトつきで受信します。受信したメッセージはユーザーがデストラクタ関数で削除する必要があります。 [詳解]
 
errno_t nlib_mq_drop (nlib_mq mq, nlib_mq_msg *msg, int *prio)
 キューに存在する最低の優先度のメッセージをキューから受信します。受信したメッセージはユーザーがデストラクタ関数で削除する必要があります。 [詳解]
 

スレッド

#define NLIB_THREAD_INVALID   (nlib_thread)(0)
 無効なスレッドを指し示す値
 
typedef struct nlib_thread_attr_ nlib_thread_attr
 新しく作られるスレッドに適用されるスレッド属性
 
typedef void(* nlib_thread_func) (void *arg)
 別スレッドで実行される関数 [詳解]
 
typedef int nlib_thread_id
 スレッド毎にユニークな整数値
 
static void nlib_pause (void)
 ごく短期間の間ウェイトします。 [詳解]
 
errno_t nlib_thread_create (nlib_thread *thread, const nlib_thread_attr *attr, nlib_thread_func func, void *arg)
 新しいスレッド作成して実行します。 [詳解]
 
errno_t nlib_thread_join (nlib_thread thread)
 スレッドの終了を待ちます。 [詳解]
 
errno_t nlib_thread_detach (nlib_thread thread)
 実行中のスレッドをデタッチ状態にします。 [詳解]
 
errno_t nlib_thread_self (nlib_thread *thread)
 実行中のスレッドに対応するnlib_threadの値を格納する。 [詳解]
 
errno_t nlib_thread_getconcurrency (unsigned int *num_cpu)
 ハードウェアスレッドの数を取得します。 [詳解]
 
errno_t nlib_thread_getid (nlib_thread_id *id)
 実行中のスレッドに対応する一意の整数値を格納する。 [詳解]
 
int nlib_thread_equal (nlib_thread th1, nlib_thread th2)
 2つのスレッドが同一スレッドを指すかどうかチェックします。 [詳解]
 
errno_t nlib_thread_getcpu (int *result)
 呼び出したスレッドが実行されているCPUを取得します。 [詳解]
 
errno_t nlib_thread_setaffinity (nlib_thread thread, uint32_t affinity)
 指定されたスレッドのプロセッサアフィニティマスクを設定します。 [詳解]
 
errno_t nlib_thread_setname (nlib_thread thread, const char *name)
 スレッドに名前をつけます。 [詳解]
 
errno_t nlib_thread_getname (nlib_thread thread, char *name, size_t len)
 スレッド名を取得します。 [詳解]
 
errno_t nlib_thread_attr_init (nlib_thread_attr *attr)
 スレッド属性オブジェクトを初期化して、デフォルトに設定する。 [詳解]
 
errno_t nlib_thread_attr_setint (nlib_thread_attr *attr, int key, int value)
 スレッドの属性オブジェクトのキーに対応する整数を設定する。 [詳解]
 
errno_t nlib_thread_attr_getint (const nlib_thread_attr *attr, int key, int *value)
 スレッドの属性オブジェクトのキーに対応する整数を取得する。 [詳解]
 
errno_t nlib_thread_attr_setptr (nlib_thread_attr *attr, int key, void *value)
 スレッドの属性オブジェクトのキーに対応するポインタを設定する。現在のところEINVALのみを返します。 [詳解]
 
errno_t nlib_thread_attr_getptr (const nlib_thread_attr *attr, int key, void **value)
 スレッドの属性オブジェクトのキーに対応するポインタを取得する。現在のところEINVALのみを返します。 [詳解]
 
errno_t nlib_thread_attr_setstack (nlib_thread_attr *attr, void *stack_addr, size_t stack_size)
 スレッドの属性オブジェクトのスタック設定を設定します。 [詳解]
 
errno_t nlib_thread_attr_getstack (const nlib_thread_attr *attr, void **stack_addr, size_t *stack_size)
 スレッドの属性オブジェクトのスタック設定を取得する。 [詳解]
 
errno_t nlib_thread_attr_destroy (nlib_thread_attr *attr)
 スレッド初期化オブジェクトを破壊します。 [詳解]
 
errno_t nlib_thread_getpriority (nlib_thread thread, int *priority)
 スレッドの現在の実行優先度を取得します。数値の意味は実装依存です。 [詳解]
 
errno_t nlib_thread_setpriority (nlib_thread thread, int priority)
 スレッドの実行優先度を設定します。数値の意味は実装依存です。 [詳解]
 
errno_t nlib_thread_priority_min (int *priority)
 実行優先度に指定できる数値の最小値を取得します。 [詳解]
 
errno_t nlib_thread_priority_max (int *priority)
 実行優先度に指定できる数値の最大値を取得します。 [詳解]
 
errno_t nlib_thread_priority_default (int *priority)
 実行優先度に指定できる数値のデフォルト値を取得します。 [詳解]
 
void nlib_thread_cleanup_push (void(*fn)(void *), void *arg)
 fnを専用のスタックにプッシュします。 [詳解]
 
void nlib_thread_cleanup_pop (int exec)
 クリーンアップハンドラが格納されているスタックの一番上のハンドラを削除します。 [詳解]
 

ロギング

ログを標準出力やsyslog, 及びファイルに出力します。

enum  nlib_log_priority { ,
  kNlibLogVerbose,
  kNlibLogDebug,
  kNlibLogInfo,
  kNlibLogWarn,
  kNlibLogError,
  kNlibLogFatal ,
  kNlibLogLevelEqualOrAbove = 0x10,
  kNlibLogLevelEqualOrBelow = 0x20,
  kNlibLogLevelAll = 0x30
}
 出力の優先度(種類)を定義しています。 [詳解]
 
int nlib_log_print (int prio, const char *tag, const char *fmt,...)
 ログメッセージを出力します。 [詳解]
 
int nlib_log_vprint (int prio, const char *tag, const char *fmt, va_list ap)
 ログメッセージを出力します。 [詳解]
 
errno_t nlib_log_attr_setint (int prio, int key, int value)
 優先度ごとの出力先の指定を行います。 [詳解]
 

ファイル

#define NLIB_FD_O_RDONLY   O_RDONLY
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_WRONLY   O_WRONLY
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_RDWR   O_RDWR
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_APPEND   O_APPEND
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_CREAT   O_CREAT
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_TRUNC   O_TRUNC
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_FD_O_EXCL   O_EXCL
 nlib_fd_open()flags 引数で使われます。
 
#define NLIB_SEEK_SET   SEEK_SET
 nlib_fd_seek()whence 引数で使われます。
 
#define NLIB_SEEK_CUR   SEEK_CUR
 nlib_fd_seek()whence 引数で使われます。
 
#define NLIB_FD_INVALID   (-1)
 無効なファイルディスクリプタを定義したマクロです。
 
typedef int64_t nlib_offset
 ファイルへのオフセットです。64bit整数です。
 
typedef int nlib_fd
 (nlib独自の)ファイルディスクリプタで、32bit整数です。 [詳解]
 
errno_t nlib_fd_open (nlib_fd *fd, const char *native_path, unsigned int flags, int mode)
 ファイルをオープンします。 [詳解]
 
static errno_t nlib_fd_creat (nlib_fd *fd, const char *native_path, int mode)
 nlib_fd_open(fd, native_path, NLIB_FD_O_CREAT | NLIB_FD_O_WRONLY | NLIB_FD_O_EXCL, mode)と等価です。 ファイルが既に存在する場合は失敗することに注意してください。
 
errno_t nlib_fd_close (nlib_fd fd)
 ファイルをクローズします。エラーを返した場合でもファイルディスクリプタは解放されます。 [詳解]
 
errno_t nlib_fd_read (size_t *result, nlib_fd fd, void *buf, size_t count)
 ファイルディスクリプタから、(最大)count バイトをbuf に読むこみます。 [詳解]
 
errno_t nlib_fd_write (size_t *result, nlib_fd fd, const void *buf, size_t count)
 ファイルディスクリプタへ、(最大)count バイトをbuf から書きこみます。 [詳解]
 
errno_t nlib_fd_seek (nlib_offset *result, nlib_fd fd, nlib_offset offset, int whence)
 ファイルのオフセットを変更する。 [詳解]
 
errno_t nlib_fd_pread (size_t *result, nlib_fd fd, void *buf, size_t count, nlib_offset offset)
 指定したオフセットでファイルディスクリプタから読みこみます。ファイルディスクリプタのオフセットは変更されません。 [詳解]
 
errno_t nlib_fd_pwrite (size_t *result, nlib_fd fd, const void *buf, size_t count, nlib_offset offset)
 指定したオフセットでファイルディスクリプタに書きこみます。ファイルディスクリプタのオフセットは変更されません。 [詳解]
 
errno_t nlib_fd_truncate (nlib_fd fd, nlib_offset length)
 指定した長さにファイルを延長、もしくは切り詰める。 [詳解]
 
errno_t nlib_fd_getsize (nlib_offset *size, nlib_fd fd)
 ファイルサイズを取得します。 [詳解]
 
errno_t nlib_fd_flush (nlib_fd fd)
 ファイルディスクリプタへの書き込みをフラッシュします。 [詳解]
 
errno_t nlib_fd_sync (nlib_fd fd)
 メモリにあるファイルの内容をデバイス上のものと同期させます。 [詳解]
 
errno_t nlib_fd_native_handle (void **native_handle, nlib_fd fd)
 ネイティブのファイルハンドル(に相当するもの)を取得する。 [詳解]
 
errno_t nlib_fd_readv (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt)
 fdに関連付けられたファイルから複数の非連続なバッファへの読み込みを行います。 [詳解]
 
errno_t nlib_fd_writev (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt)
 複数の非連続なバッファからfdに関連付けられたファイルへの書き込みを行います。 [詳解]
 
errno_t nlib_fd_preadv (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt, nlib_offset offset)
 内部でpread()又はnlib_fd_pread()を使うこと以外は、nlib_fd_readv()と同様です。
 
errno_t nlib_fd_pwritev (size_t *result, nlib_fd fd, const nlib_fd_iovec *iov, int iovcnt, nlib_offset offset)
 内部でpwrite()又はnlib_fd_pwrite()を使うこと以外は、nlib_fd_writev()と同様です。
 
errno_t nlib_unlink (const char *native_path)
 ファイルを削除する [詳解]
 
errno_t nlib_mkdir (const char *native_path, unsigned int flags)
 ディレクトリを作成する [詳解]
 
errno_t nlib_rmdir (const char *native_path)
 ディレクトリを削除する [詳解]
 
errno_t nlib_remove (const char *native_path)
 ファイルまたはディレクトリを削除します。ファイルに対してはnlib_unlink()を、ディレクトリに対してはnlib_rmdir()を呼び出します。
 
errno_t nlib_rename (const char *old_path, const char *new_path)
 ファイル名の変更する [詳解]
 
errno_t nlib_dir_open (nlib_dir *dir, const char *native_path)
 ディレクトリをオープンする [詳解]
 
errno_t nlib_dir_close (nlib_dir dir)
 ディレクトリをクローズする [詳解]
 
errno_t nlib_dir_read (nlib_dirent *ent, nlib_dir dir)
 ディレクトリエントリがあればそれをを1つ読み込む。 [詳解]
 
errno_t nlib_is_dir (int *result, const char *native_path)
 パスがディレクトリかどうかを検査します。パスが存在しない場合は*resultに0を設定し、0を返します。 [詳解]
 
errno_t nlib_exist_path (int *result, const char *native_path)
 パスが存在するかどうかを検査します。 [詳解]
 
errno_t nlib_disk_freespace (const char *native_path, uint64_t *free_bytes_available, uint64_t *total_bytes, uint64_t *total_free_bytes)
 指定されたパスが属するストレージの容量に関する情報を取得します。 [詳解]
 
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)
 ユニークで推測されにくい名前を持つ一時ファイルを作成します。 [詳解]
 
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)
 シンボリックリンクを解決します。 [詳解]
 

printf

各種標準ライブラリのprintfの違いを吸収するための関数です。

説明
printfのフォーマット文字列の記述には移植性のために気をつける必要がある場合があります。以下の記述を参考にしてください。
参照
https://google.github.io/styleguide/cppguide.html#64-bit_Portability
http://www.textdrop.net/google-styleguide-ja/cppguide.xml#64%E3%83%93%E3%83%83%E3%83%88%E3%81%AE%E7%A7%BB%E6%A4%8D%E6%80%A7
#define PRIdS   __PRIS_PREFIX "d"
 size_tの型をprintfで表示する場合に利用します。%zdに相当します。
 
#define PRIxS   __PRIS_PREFIX "x"
 size_tの型をprintfで表示する場合に利用します。%zxに相当します。
 
#define PRIuS   __PRIS_PREFIX "u"
 size_tの型をprintfで表示する場合に利用します。%zuに相当します。
 
#define PRIXS   __PRIS_PREFIX "X"
 size_tの型をprintfで表示する場合に利用します。%zXに相当します。
 
#define PRIoS   __PRIS_PREFIX "o"
 size_tの型をprintfで表示する場合に利用します。%zoに相当します。
 
errno_t nlib_vsnprintf (size_t *count, char *buf, size_t size, const char *fmt, va_list args)
 より安全な形式のvsnprintfで、標準のvsnprintfの動作の違いも吸収します。 [詳解]
 
errno_t nlib_snprintf (size_t *count, char *buf, size_t size, const char *fmt,...)
 より安全な形式のsnprintfです。
 
errno_t nlib_vdprintf (nlib_fd fd, size_t *count, const char *fmt, va_list args)
 ファイルディスクリプタに出力するvsnprintf()です。
 
errno_t nlib_dprintf (nlib_fd fd, size_t *count, const char *fmt,...)
 ファイルディスクリプタに出力するsnprintf()です。
 
int nlib_printf (const char *fmt,...)
 printf()の代替です。
 
errno_t nlib_vsnwprintf (size_t *count, wchar_t *buf, size_t size, const wchar_t *fmt, va_list args)
 より安全な形式のvswprintfで、各種vswprintfの動作の違いも吸収します。 [詳解]
 
errno_t nlib_snwprintf (size_t *count, wchar_t *buf, size_t size, const wchar_t *fmt,...)
 より安全な形式のsnwprintfです。
 
errno_t nlib_vdwprintf (nlib_fd fd, size_t *count, const wchar_t *fmt, va_list args)
 ファイルディスクリプタに出力するvsnwprintfです。
 
errno_t nlib_dwprintf (nlib_fd fd, size_t *count, const wchar_t *fmt,...)
 ファイルディスクリプタに出力するsnwprintf()です。
 
int nlib_wprintf (const wchar_t *fmt,...)
 wprintf()の代替です。
 

ユニコード

nn::nlib::unicode名前空間にもユニコード関連の機能が実装されています。

typedef uint16_t nlib_utf16_t
 char16_tが利用できる場合はchar16_tに、そうでない場合はuint16_ttypedefされます。
 
typedef uint32_t nlib_utf32_t
 char32_tが利用できる場合はchar32_tに、そうでない場合はuint32_ttypedefされます。
 
typedef char nlib_utf8_t
 chartypedefです。文字列がUTF-8であることを示します。
 
errno_t nlib_wide_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const wchar_t *wcstr)
 UTF-16/UTF-32文字列からUTF-8文字列に変換します。 [詳解]
 
errno_t nlib_utf8_to_wide (size_t *wccount, wchar_t *wcstr, size_t buflen, const nlib_utf8_t *utf8)
 UTF-8文字列からUTF-16/UTF-32文字列に変換します。 [詳解]
 
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
 wchar_tのサイズによってnlib_memutf16_to_utf8()またはnlib_memutf32_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
 wchar_tのサイズによってnlib_memutf8_to_utf16またはnlib_memutf8_to_utf32が呼ばれます。
 
errno_t nlib_wcscplen (size_t *count, const wchar_t *str)
 文字列中のコードポイントの数を取得します。 [詳解]
 
errno_t nlib_strcplen (size_t *codepoint_count, size_t *supplementary_codepoint_count, size_t *len, const nlib_utf8_t *str)
 文字列中のコードポイントの数と補助文字の数と文字列長を取得します。 EILSEQを返す場合は、その場所までのコードポイント数等が格納されています。 [詳解]
 
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)
 文字列中のコードポイントの数と補助文字の数を取得します。 [詳解]
 
int nlib_utf16_to_utf32char (nlib_utf32_t *utf32, nlib_utf16_t upper, nlib_utf16_t lower)
 1つのコードポイントをUTF-16からUTF-32に変換します。 [詳解]
 
int nlib_utf32char_to_utf16 (nlib_utf16_t *upper, nlib_utf16_t *lower, nlib_utf32_t utf32)
 1つのUTF-32文字をUTF-16に変換します。 [詳解]
 
int nlib_utf8_to_utf32char (nlib_utf32_t *utf32, const nlib_utf8_t *utf8)
 UTF-8を1文字分のUTF-32に変換します。 [詳解]
 
int nlib_utf32char_to_utf8 (nlib_utf8_t(&utf8)[4], nlib_utf32_t utf32)
 1文字のUTF-32をUTF-8に変換します。 [詳解]
 
errno_t nlib_utf16_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const nlib_utf16_t *utf16)
 UTF-16文字列からUTF-8文字列に変換します。 [詳解]
 
errno_t nlib_utf8_to_utf16 (size_t *utf16count, nlib_utf16_t *utf16, size_t buflen, const nlib_utf8_t *utf8)
 UTF-8文字列からUTF-16文字列に変換します。UTF-16文字列はヌル終端されます。 [詳解]
 
errno_t nlib_utf32_to_utf8 (size_t *utf8count, nlib_utf8_t *utf8, size_t buflen, const nlib_utf32_t *utf32)
 UTF-32文字列からUTF-8文字列に変換します。 [詳解]
 
errno_t nlib_utf8_to_utf32 (size_t *utf32count, nlib_utf32_t *utf32, size_t buflen, const nlib_utf8_t *utf8)
 UTF-8文字列からUTF-32文字列に変換します。 [詳解]
 
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
 ヌル終端しないUTF-16文字列をUTF-8文字列に変換します。 [詳解]
 
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
 ヌル終端しないUTF-8文字列をUTF-16文字列に変換します。 [詳解]
 
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
 ヌル終端しないUTF-32文字列をUTF-8文字列に変換します。 [詳解]
 
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
 ヌル終端しないUTF-8文字列をUTF-32文字列に変換します。 [詳解]
 
static size_t nlib_utf16len (const nlib_utf16_t *str)
 ヌル文字を含まないnlib_utf16_tの数を数えます。 [詳解]
 
static size_t nlib_utf16nlen (const nlib_utf16_t *str, size_t maxsize)
 nlib_strnlen()のUTF-16版です。 [詳解]
 
static errno_t nlib_utf16cpy (nlib_utf16_t *s1, size_t s1max, const nlib_utf16_t *s2)
 nlib_strcpy()のUTF-16版です。 [詳解]
 
static errno_t nlib_utf16ncpy (nlib_utf16_t *s1, size_t s1max, const nlib_utf16_t *s2, size_t n)
 nlib_strcpy()のUTF-16版です。 [詳解]
 
static size_t nlib_utf32len (const nlib_utf32_t *str)
 ヌル文字を含まないnlib_utf32_tの数を数えます。 [詳解]
 
static size_t nlib_utf32nlen (const nlib_utf32_t *str, size_t maxsize)
 nlib_strnlen()のUTF-32版です。 [詳解]
 
static errno_t nlib_utf32cpy (nlib_utf32_t *s1, size_t s1max, const nlib_utf32_t *s2)
 nlib_strcpy()のUTF-32版です。 [詳解]
 
static errno_t nlib_utf32ncpy (nlib_utf32_t *s1, size_t s1max, const nlib_utf32_t *s2, size_t n)
 nlib_strcpy()のUTF-32版です。 [詳解]
 
static errno_t nlib_utf16cplen (size_t *count, const nlib_utf16_t *str)
 文字列中のコードポイントの数を取得します。 [詳解]
 
static errno_t nlib_utf16cplen_ex (size_t *count, size_t *len, const nlib_utf16_t *str)
 文字列中のコードポイントの数を取得します。 [詳解]
 
errno_t nlib_utf32cplen (size_t *count, const nlib_utf32_t *str)
 文字列中のコードポイントの数を取得します。 [詳解]
 
static uint16_t nlib_bswap16 (uint16_t x)
 __builtin_bswap16(x)や_byteswap_ushort(x)を返します。
 
static uint32_t nlib_bswap32 (uint32_t x)
 __builtin_bswap32(x)や_byteswap_ulong(x)を返します。
 
static uint64_t nlib_bswap64 (uint64_t x)
 __builtin_bswap64(x)や_byteswap_uint64(x)を返します。
 
errno_t nlib_swapendian_16 (uint16_t *p, size_t count)
 エンディアンを変換します。 [詳解]
 
errno_t nlib_swapendian_32 (uint32_t *p, size_t count)
 エンディアンを変換します。 [詳解]
 
errno_t nlib_swapendian_64 (uint64_t *p, size_t count)
 エンディアンを変換します。 [詳解]
 

詳解

基本的なAPIがCリンケージで宣言されています。

Platform.h に定義があります。