- 论坛徽章:
- 0
|
本帖最后由 ljpdxj 于 2012-03-03 16:17 编辑
source code如附件
源码如下:- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <getopt.h>
- #include <time.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <stdint.h>
- #include <errno.h>
- #define VERSION "1.0.0"
- #define PACKMOD_DEBUG
- #ifndef PACKMOD_DEBUG
- #define DBG(s...)
- #else
- #define DBG(fmt, arg...) printf("[Debug: createRomBin %4d] "fmt, __LINE__, ##arg)
- #endif
- #define ERR(fmt, arg...) \
- do { \
- printf("[Error!!! createRomBin %d] "fmt, __LINE__, ##arg); \
- } while (0)
- #define WORKING_BUF_SIZE 4096
- char u8WorkBuf[WORKING_BUF_SIZE];
- size_t uReadBytes = 0;
- static void createRomBin(void)
- {
- FILE *pFirstBootFile = NULL;
- FILE *pOutPutFile = NULL;
- struct stat statbuf;
- /* open first boot file */
- pFirstBootFile = fopen("./256k", "rb+");
- //printf("pGlobalInfo->pFbName:%s\n", pGlobalInfo->pFbName);
- if (pFirstBootFile == NULL)
- {
- ERR("Can not open \"%s\" for read\n", "./256k");
- return ;
- }
- fstat(fileno(pFirstBootFile), &statbuf);
- printf("=========>file leng:%d\n", statbuf.st_size);
- /* open output file */
- pOutPutFile = fopen("./test", "wb+");
- printf("pGlobalInfo->pOFName:%s\n", "./test");
- if (pOutPutFile == NULL)
- {
- ERR("Can not open \"%s\" for write\n", "./test");
- return;
- }
- /* copy data to output file */
- while (uReadBytes = fread(u8WorkBuf, 1, WORKING_BUF_SIZE, pFirstBootFile) != 0)
- {
- printf("read bytes:%d\n", uReadBytes);
- fwrite(u8WorkBuf, 1, WORKING_BUF_SIZE, pOutPutFile);
- }
- fclose(pFirstBootFile);
- fclose(pOutPutFile);
- }
- int main(int argc, char *argv[])
- {
- createRomBin();
- return 0;
- }
复制代码 c档是砍掉了不相关的函数之后的,另外一个二进制档会被此c档使用到。
why??????fread一直返回1,到文件结束????? |
|