填充文件后面为0xFF到指定大小
2012-02-07 09:08
393 查看
以下程序可以填充文件后面全部为0xff到指定大小.
test.c
#include <stdio.h>
/*
* Return: 0, OK
* -1, Fail
*/
unsigned long int appendFile(char *destFilePath, unsigned long int appendLength)
{
unsigned char tmpBuf[1024];
int i = 0;
FILE *fp;
for(i = 0; i < 1024; i++)
{
tmpBuf[i] = 0xFF;
}
if ((fp = fopen(destFilePath, "ab+"))==NULL)
{
printf("Can not open file %s \n", destFilePath);
return -1;
}
while(appendLength > 0)
{
if (appendLength <= 1024)
{
fwrite(tmpBuf, sizeof(char), appendLength, fp);
appendLength -= appendLength;
}
else
{
fwrite(tmpBuf, sizeof(char), 1024, fp);
appendLength -= 1024;
}
}
fclose(fp);
return 0;
}
#define SRC_FILE "./file1.bin"
#define DEST_FILE "./file2.bin"
void main(void)
{
unsigned long int totalLength = (85504 - 13824) * 1024;
unsigned long int fileLength = 57751552;
unsigned long int appendLength = totalLength - fileLength;
appendFile(DEST_FILE, appendLength);
}
test.c
#include <stdio.h>
/*
* Return: 0, OK
* -1, Fail
*/
unsigned long int appendFile(char *destFilePath, unsigned long int appendLength)
{
unsigned char tmpBuf[1024];
int i = 0;
FILE *fp;
for(i = 0; i < 1024; i++)
{
tmpBuf[i] = 0xFF;
}
if ((fp = fopen(destFilePath, "ab+"))==NULL)
{
printf("Can not open file %s \n", destFilePath);
return -1;
}
while(appendLength > 0)
{
if (appendLength <= 1024)
{
fwrite(tmpBuf, sizeof(char), appendLength, fp);
appendLength -= appendLength;
}
else
{
fwrite(tmpBuf, sizeof(char), 1024, fp);
appendLength -= 1024;
}
}
fclose(fp);
return 0;
}
#define SRC_FILE "./file1.bin"
#define DEST_FILE "./file2.bin"
void main(void)
{
unsigned long int totalLength = (85504 - 13824) * 1024;
unsigned long int fileLength = 57751552;
unsigned long int appendLength = totalLength - fileLength;
appendFile(DEST_FILE, appendLength);
}
相关文章推荐
- 快速创建一个的指定大小的内容全为0xFF的文件
- Ubuntu创建一个指定大小的文件用全零填充这个文件
- Linux系统下生成一个指定大小的文件
- 创建指定大小的文件
- 如何获取指定文件的大小?
- Shell脚本实例(二) 向指定目录下不断产生指定大小的文件
- php查找指定目录下指定大小文件的方法
- python3.6深度学习图片集处理项目源代码(为cnn等准备图片集合,批量生成、删除、改名、旋转、调整图片大小,包括删除指定路径下所有文件)
- linux生成指定大小的文件
- 创建指定大小的文件
- python 实现统计ftp服务器指定目录下文件夹数目、文件数目及所有文件大小 本次主要为满足应用方核对上传到ftp服务器的文件是否缺漏。 主要要求:指定目录下,文件夹数目/文件数目/所有文件大小
- Linux系统下生成一个指定大小的文件和空间预留
- Android清除外部和内部缓存,数据库,SharedPreference,指定路径下的文件,获取缓存大小,格式化储存单位工具类
- Linux操作系统下生成一个指定大小的文件
- Linux下批量删除空文件或者删除指定大小的文件
- 用FastCopy ver2.11复制指定日期及大小的WINDOWS文件
- 搜索超过大指定大小的文件
- shell 创建多个指定大小的文件,循环删除指定大小文件
- c# 创建指定大小的空字符填充的文本文件 在指定位置读写相关内容
- android获取指定文件大小