#define LINE_BUF_SIZE 128 char read_upgrade_version(char *file_path,const char *type, char *value) { char line[LINE_BUF_SIZE] = {0}; FILE *fp = NULL; char *pType = NULL; fp = fopen(file_path, "r"); if (!fp) { printf("Can't open %s",file_path); return -1; } while (!feof(fp)) { if(fgets(line, LINE_BUF_SIZE, fp) == NULL) { break; } pType = strstr(line, "="); if(pType == NULL) { continue; } pType = strstr(line, type); if (pType) { pType ++; pType += strlen(type); if (pType) { strcpy(value, pType); break; } } } fclose(fp); return 0; }
#define LINE_NUM 12 int save_upgrade_version(char *file_path,const char *type, char *value) { int i; char flag = 0,cnt = 0; struct info_t info[LINE_NUM]; char linebuffer[LINE_BUF_SIZE] = {0}; char buffer[LINE_BUF_SIZE * 2]; char *pType = NULL; FILE *fp = fopen(file_path, "r"); if(fp == NULL) { printf("open error"); return 1; } for(i = 0 ; i < LINE_NUM ; i++) { char *ret = fgets(linebuffer, sizeof(linebuffer), fp); if(ret == NULL) { break; } pType = strstr(linebuffer, "="); if(pType == NULL) { continue; } memcpy(info[i].type, linebuffer, pType - linebuffer); info[i].type[pType - linebuffer] ='