{
if(argc!=2)
{
printf("2 argment\n");
return 0;
}
struct stat buf;
stat(argv[1], &buf);
printf("st_blksize=%d,st_blocks=%d\n", (int)buf.st_blksize, (int)buf.st_blocks);
return 0;
}
语法: #include <stdio.h>
stream
Pointer to FILE structure.
buffer
User-allocated buffer.
mode
Mode of buffering.
size
Buffer size in bytes. Allowable range: 2 <= size <= INT_MAX (2147483647). Internally, the value supplied for size is rounded down to the nearest multiple of 2.
_IOLBF, 表示线缓冲
_IONBF, 表示无缓存
/* setvbuf example */
#include <stdio.h>
{
FILE *pFile;
pFile=fopen ("myfile.txt","w");
setvbuf ( pFile , sBuf, _IOFBF , 1024 );
fclose (pFile);
return 0;
}
在这个例子中,每次写1024字节,所以只有缓冲区满了(有1024字节),才往文件写入数据,可以减少IO次数