- 论坛徽章:
- 0
|
代码大致是这样的,接口已经做好了,现在只需要把CONFFILES_NAME的内容交给*buf就可以了
但是由于是多个文件,所以采用了tar打包的方法(tar打包调用脚本已经省略),但是这样就会出错,
如果CONFFILES_NAME是一个文本文件,就没有问题
在此再次谢过各位!
49 int dev_getconfigfile(char *buf, int length, int *pflen)
50 {
51 int readCnt = 0;
52 FILE *fp;
53 int fd;
54 struct stat theStat;
55 char filename[128];
56 strcpy(filename, CONFFILES_NAME);
57 fp = fopen(filename, "r");
58 if (fp == NULL) {
59 printf("file open fail!\n");
60 return -1;
61 }
62 fd = fileno(fp);
63 fstat(fd, &theStat);
64
65 if (theStat.st_size > length) {
66 printf("file is too big!\n");
67 fclose(fp);
68 return -1;
69 }
70
71 readCnt = fread(buf, 1, theStat.st_size, fp);
72 if (readCnt < theStat.st_size ){
73 printf("lose some.%d %d\n", readCnt,(int)theStat.st_size);
74 fclose(fp);
75 return -1;
76 }
77 fclose(fp);
78 *pflen = theStat.st_size;
79 return 0;
80 } |
[ 本帖最后由 WHITLACK 于 2008-12-24 04:36 编辑 ] |
|