setmode
io.h:インデックス への移動
ヘッダーファイル
io.h
カテゴリ
入出力ルーチン
プロトタイプ
int setmode(ifnt handle, int amode);
説明
オープンファイルのモードを設定します。
setmode は,handle に関連付けられたオープンファイルのモードをバイナリまたはテキストに設定します。引数 amode には,値 O_BINARY または O_TEXT のいずれかを指定する必要があります。両方は指定できません。これらのシンボル定数は,fcntl.h で定義されています。
戻り値
成功した場合,setmode は直前の変換モードを返します。エラーが発生した場合は -1 を返し,グローバル変数に次の値を設定します。
| EINVAL | 無効な引数 | 
| EBADF | 不正なファイルハンドル | 
例
 #include <fcntl.h>
 #include <io.h>
 #include <stdio.h>
 int main (int argc, char ** argv )
 (
   FILE *fp;
   int newmode;
   long where;
   char buf[256];
   fp = fopen( argv[1], "r+" );
   if ( !fp )
   {
     printf( "Couldn't open %s\n", argv[1] );
     return -1;
   }
   newmode = setmode( fileno( fp ), O_BINARY );
   if ( newmode == -1 )
   {
     printf( "Couldn't set mode of %s\n", argv[1] );
     return -2
   }
   fp->flags |= _F_BIN;
   where = ftell( fp );
   printf ("file position: %d\n", where );
   fread( buf, 1, 1, fp );
   where = ftell ( fp );
   printf( "read %c, file position: %ld\n", *buf, where );
   fclose ( fp );
   return 0;
 }
移植性
| POSIX | Win32 | ANSI C | ANSI C++ | 
|---|---|---|---|
| + |