フォーマット
#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() 関数は 0 より大きな値を戻します。ストリームがバイト指向であれば、0 より小さい値を戻します。ストリームに指向がなければ、0 を戻します。
fwide() の使用例
#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. *******************************************************************/ }
関連情報