fwide() — ストリームの方向を決定する
形式
#include <stdio.h>
#include <wchar.h>
int fwide(FILE *stream, int mode);言語レベル
ANSI
スレッド・セーフ
はい
ロケール依存
この関数は、コンパイル・コマンドに対して LOCALETYPE(*CLD) が指定されている場合には使用できません。
統合ファイル・システム・インターフェース
この関数は、コンパイル・コマンドに対して SYSIFCOPT(*NOIFSIO) が指定されている場合には使用できません。
説明
fwide() 関数は、 streamが指すストリームの方向を決定します。 mode が 0 より大きい場合、 fwide() 関数はまずストリームをワイド指向にしようとします。 mode が 0 より小さい場合、 fwide() 関数はまずストリーム・バイト指向にしようとします。 それ以外の場合、 mode は 0 であり、 fwide() 関数はストリームの方向を変更しません。
注: ストリームの方向が既に決定されている場合、
fwide() 関数はそれを変更しません。戻り値
呼び出しの後、ストリームの方向が広い場合、 fwide() 関数は 0 より大きい値を戻します。 ストリームにバイト方向がある場合は、0 より小さい値を戻します。 ストリームに方向がない場合は、0を戻します。
例
#include <stdio.h>
#include <math.h>
#include <wchar.h>
void check_orientation(FILE *stream)
{
int rc;
rc = fwide(stream,0); /* check the orientation */
if (rc<0) {
printf("Stream has byte orientation.\n");
} else if (rc>0) {
printf("Stream has wide orientation.\n");
} else {
printf("Stream has no orientation.\n");
}
return;
}
int main(void)
{
FILE *stream;
/* Demonstrate that fwide can be used to set the orientation,
but cannot change it once it has been set. */
stream = fopen("test.dat","w");
printf("After opening the file: ");
check_orientation(stream);
fwide(stream, -1); /* Make the stream byte oriented */
printf("After fwide(stream, -1): ");
check_orientation(stream);
fwide(stream, 1); /* Try to make the stream wide oriented */
printf("After fwide(stream, 1): ");
check_orientation(stream);
fclose(stream);
printf("Close the stream\n");
/* Check that a wide character output operation sets the orientation
as expected. */
stream = fopen("test.dat","w");
printf("After opening the file: ");
check_orientation(stream);
fwprintf(stream, L"pi = %.5f\n", 4* atan(1.0));
printf("After fwprintf( ): ");
check_orientation(stream);
fclose(stream);
return 0;
/*******************************************************************
The output should be similar to :
After opening the file: Stream has no orientation.
After fwide(stream, -1): Stream has byte orientation.
After fwide(stream, 1): Stream has byte orientation.
Close the stream
After opening the file: Stream has no orientation.
After fwprintf( ): Stream has wide orientation.
*******************************************************************/
}