LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1038|回复: 2

chsize()函数怎么理解?

[复制链接]
发表于 2003-12-7 16:45:29 | 显示全部楼层 |阅读模式
一个文件的大小不是由文件本身决定的吗?怎么能用change?
要是太小可以用null 填充,要变小,怎么处理? :confused:
 楼主| 发表于 2003-12-7 22:23:28 | 显示全部楼层
这是chsize()的帮助文件,请E文好的帮看看。

chsize()                                                                                       
Change the size of a file
Synopsis:                                                                                       
#include <unistd.h>
                                                                                       
int chsize( int filedes,
            long size );
                                                                                       
Library:                                                                                       
libc
Description:
                                                                                       
The chsize() function extends or truncates the file specified by filedes to size bytes
The file is padded with NUL ('\0') characters if it needs to be extended.
Note: chsize() ignores advisory locks that may have been set with the fcntl() function.Returns:
                                                                                       
0    Success.
-1   An error occurred.
                                                                                       Errors:
                                                                                       
EBADF
    The filedes argument isn't a valid file descriptor, or the file isn't opened for writing.
ENOSPC
    There isn't enough space left on the device to extend the file.
ENOSYS
    The chsize() function isn't implemented for the filesystem specified by filedes.
                                                                                       
Examples:                                                                                       
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>                                                                                       
int main( void )
{
    int  filedes;                                                                                       
    filedes= open( "file", O_RDWR | O_CREAT,
        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
    if( filedes!= -1 ) {
        if( chsize( filedes, 32 * 1024L ) != 0 ) {
            printf( "Error extending file\n" );
        }
        close( filedes);
        return EXIT_SUCCESS;
    }                                                                                       
    return EXIT_FAILURE;
}
                                                                                       
Classification:
                                                                                       
QNX 4
Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes
发表于 2003-12-8 00:14:00 | 显示全部楼层
变小就是截断文件
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表