大龙的博客

常用链接

统计

最新评论

chsize ------------------ 改变文件大小, 预分配

chsize
改变文件尺寸。
int chsize(int handle,long size);
例程 需要的头文件 可选的头文件 兼容性
chsize <io.h> <errno.h> Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性

LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
如果文件尺寸成功改变chsize返回值0;返回值-1指出一个错误,如果指定的文件锁定不能访问,errno设置为EACCES,如果指定的文件是只读的或者该句柄无效,则errno设置为EBADF;如果该设备上没有剩余空间,则errno设置为ENOSPC。
参数
handle指向打开文件的句柄。
Size
文件的新尺寸,以字节为单位。
说明
chsize函数以size指定的长度扩充或截除与handle关联的文件,该文件必须以允许写模式打开,如果该文件被扩充,要在末尾添加空格字符('\0')。如果文件被截除,从缩短的文件的末尾到该文件的最初长度之间的所有数据被丢失。
例子
/* CHSIZE.C: This program uses filelength to report the size
* of a file before and after modifying it with chsize.
*/
#includ <io.h>
#includ <fcntl.h>
#includ <sys/types.h>
#includ <sys/stat.h>
#includ <stdio.h>
void main( void )
{
int fh, result;
unsigned int nbytes = BUFSIZ;
/* Open a file */
if( (fh = open( "data", ORDWR | OCREAT, SIREAD
| SIWRITE ))!= -1 )
{
printf( "File length before: %ld\n", filelength( fh ) );
if( ( result = chsize( fh, 329678 ) ) == 0 )
printf( "Size successfully changed\n" );
else
printf( "Problem in changing the size\n" );
printf( "File length after: %ld\n", filelength( fh ) );
close( fh );
}
}
输出结果
File length before: 0
Size successfully changed
File length after:329678
参见
close,creat,open

posted on 2008-04-23 20:56 大龙 阅读(4075) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理