将模块版本号和编译日期写入指定文件

2020-04-23  本文已影响0人  遇银
#define MODULE_VERSION   "1.0.1"          //模块版本号
#define MODULE_VERSION_FILE  "/tmp/appversion/module_version_file"   //最后存储文件

void _write_version_date(void)
{
    const char year_month[12][4] = {"Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Oct","Ncv","Dec"};
    char compile_date[20] = {0};
    char str_month[4] = {0};
    int year;
    int month=0;
    int day;
    int i;
    char versionpath[40] = {0};
    File *fp = NULL;

    sprintf(compile_date,"%s",__DATE__);
    sscanf(compile_date,"%s %d %d",str_month,&day,&year);
    for(i=0;i<12;i++)
    {
        if(strncmp(str_month,year_month[i],3))
        {
            month = i+1;
            break;
        }
    }

    sprintf(versionpath,"Company Module_%s_%d%02d%02d",MODULE_VERSION,year,month,day);
    //检查存储目录是否存在
    if(access("/tmp/appversion",F_OK) != 0)
    {
        mkdir("/tmp/appversion",S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    }
    fp = fopen(MODULE_VERSION_FILE,"w");
    fprintf(fp,"%s",versionpath);
    fclose(fp);
    fp = NULL;
}
上一篇下一篇

猜你喜欢

热点阅读