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

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

作者: 遇银 | 来源:发表于2020-04-23 15:43 被阅读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;
    }
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/szsaihtx.html