| lenovo 回复于:2004-04-07 16:00:57
|
man stat
man fstat
|
| xiaoen_tang 回复于:2004-04-07 19:43:41
|
long
get_file_size( char * filename )
{
struct stat f_stat;
if( stat( filename, &f_stat ) == -1 ){
return -1;
}
return (long)f_stat.st_size;
}
|
| whyglinux 回复于:2004-05-03 16:13:28
|
另一种判断文件大小的方法。
[code:1:fae3aacbeb]
long
get_file_size( char* filename )
{
FILE* fp = fopen( filename, "r" );
if (fp==NULL) return -1;
fseek( fp, 0L, SEEK_END );
return ftell(fp);
}
[/code:1:fae3aacbeb]
|
| JohnBull 回复于:2004-05-03 17:25:26
|
先打开文件这种判断不严密,没有处理打开失败,有core dump可能。
还是stat直接一些。
|
| whyglinux 回复于:2004-05-03 17:43:04
|
同意。只想示例一种方法,没有考虑到程序的健壮性。
谢谢版主提醒。
|
| Amber_star 回复于:2004-09-29 20:15:19
|
按照这种说法, 一个文件的最大长度为2 的32次方 ,就是4G
|
| Amber_star 回复于:2004-09-29 20:18:44
|
我想在新见一个文件的时候就指定其大小怎么办呢.lseek 函数好像办不到的啊,必须在后面写点东西才能是文件的长度确定下来,请问有其他的法子吗?
|
| lenovo 回复于:2004-09-29 20:25:09
|
比如你想要n个字节大小的文件,
你先lseek到n-1字节处,然后随便write一个字节
就可以了。
|
| Amber_star 回复于:2004-09-29 20:30:18
|
那就是要浪费一个字节了 ^_^
|
| lenovo 回复于:2004-09-29 20:39:20
|
[quote:99ce2f458d="Amber_star"]那就是要浪费一个字节了 ^_^[/quote:99ce2f458d]
我晕,什么叫浪费呀?
|
| Amber_star 回复于:2004-09-29 20:55:59
|
ftruncate
|
| flw 回复于:2004-09-30 13:51:00
|
[quote:0074a56593="Amber_star"]那就是要浪费一个字节了 ^_^[/quote:0074a56593]
看清楚了。
脑子怎么就转不过弯呢。
|