Document of c-modernization-kit (util) 1.0.0
Loading...
Searching...
No Matches
console-util.h File Reference

コンソール UTF-8 ヘルパー API。 More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CONSOLE_UTIL_EXPORT
 DLL エクスポート/インポート制御マクロ。
#define CONSOLE_UTIL_API
 呼び出し規約マクロ。

Functions

CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_init (void)
 コンソールヘルパーを初期化する。
CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_dispose (void)
 コンソールヘルパーを終了し、リソースを解放する。

Detailed Description

コンソール UTF-8 ヘルパー API。

Windows 環境で stdout / stderr を内部パイプに差し替え、 コンソール (TTY) 出力は WriteConsoleW 経由で UTF-16 として 送出し、パイプやファイルへは UTF-8 バイト列をそのまま書き戻します。
Linux 環境では console_init は何もせず 0 を返します。
呼び出し側は #ifdef _WIN32 ガード不要でクロスプラットフォームに 使用できます。

使用例
#include <console-util.h>
#include <stdio.h>
int main(void) {
console_init(); // stdout / stderr を差し替え
printf("こんにちは\n"); // コンソールでは WriteConsoleW、パイプでは UTF-8
fprintf(stderr, "警告\n");
return 0;
}
コンソール UTF-8 ヘルパー API。
CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_init(void)
コンソールヘルパーを初期化する。
CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_dispose(void)
コンソールヘルパーを終了し、リソースを解放する。

Definition in file console-util.h.

Macro Definition Documentation

◆ CONSOLE_UTIL_EXPORT

#define CONSOLE_UTIL_EXPORT

DLL エクスポート/インポート制御マクロ。

ビルド条件に応じて以下の値を取ります。

条件
Linux (非 Windows) (空)
Windows / __INTELLISENSE__ 定義時 (空)
Windows / CONSOLE_UTIL_STATIC 定義時 (静的リンク) (空)
Windows / CONSOLE_UTIL_EXPORTS 定義時 (DLL ビルド) __declspec(dllexport)
Windows / CONSOLE_UTIL_EXPORTS 未定義時 (DLL 利用側) __declspec(dllimport)

Definition at line 46 of file console-util.h.

◆ CONSOLE_UTIL_API

#define CONSOLE_UTIL_API

呼び出し規約マクロ。

Windows 環境では __stdcall 呼び出し規約を指定します。
Linux (非 Windows) 環境では空に展開されます。
既に定義済みの場合は再定義されません。

Definition at line 55 of file console-util.h.

Referenced by console_dispose(), and console_init().

Function Documentation

◆ console_init()

CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_init ( void )

コンソールヘルパーを初期化する。

Windows 環境では stdout と stderr を内部パイプに差し替え、 バックグラウンドスレッドを起動します。
スレッドはパイプから UTF-8 バイト列を受け取り、出力先がコンソール (TTY) の場合は WriteConsoleW で UTF-16 として書き出します。 パイプやファイルへは UTF-8 バイト列をそのまま転送します。
Linux 環境では何もしません。
stdin には触れません。
本関数はプログラム開始時に一度だけ呼び出すことを想定しています。
初期化に失敗した場合は stderr に警告を出力し、何もせずに返ります。

Note
本関数を呼び出した後は console_dispose を呼び出して リソースを解放してください。

Definition at line 294 of file console-util.c.

References CONSOLE_UTIL_API.

◆ console_dispose()

CONSOLE_UTIL_EXPORT void CONSOLE_UTIL_API console_dispose ( void )

コンソールヘルパーを終了し、リソースを解放する。

Windows 環境ではバックグラウンドスレッドを停止し、 stdout / stderr を元のハンドルに戻します。
Linux 環境では何もしません。
console_init を呼び出していない場合も安全に呼び出せます。

Definition at line 295 of file console-util.c.

References CONSOLE_UTIL_API.