filelength
io.h:インデックス への移動
ヘッダーファイル
io.h
カテゴリ
入出力ルーチン
プロトタイプ
long filelength(int handle);
説明
ファイルのサイズ(バイト単位)を取得します。
filelength は,handle に関連付けられたファイルの長さ(バイト単位)を返します。
戻り値
成功した場合,filelength は,ファイルの長さ(バイト単位)を表す long 値を返します。エラーが発生した場合は -1 を返し,グローバル変数 errno が次の値に設定されます。
EBADF |
不正なファイル番号 |
例
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* 10 バイトを含むファイルを作成します */
handle = open("DUMMY.FIL", O_CREAT);
write(handle, buf, strlen(buf));
/* ファイルのサイズを表示します */
printf("file length in bytes: %ld\n", filelength(handle));
/* ファイルを閉じます */
close(handle);
return 0;
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |