본문 바로가기
개발 업무(코딩)-개발자였을때 썼던..

환경파일 콜

by 주용사 2023. 1. 9.
728x90
void    Get_SCfg_Value(char *zkey, char *zvalue, char *zfile, int fpointer)
/*----------------------------------------------------------------------------*/
{
    char    buf[1024], *sp;
    int     nkeylen;
    struct  stat config_stat;

    sprintf (buf, "%s/%s", getenv ("_Q_CFG"), zfile);

    if(!fpFiles[fpointer])
    {
        if ((fpFiles[fpointer] = fopen (buf, "r")) == 0)
        {
            Exit_Process ();
        }
        stat(buf, &config_stat);
        tVerFile[fpointer] = config_stat.st_ctime;
    }
    else
    {
        stat(buf, &config_stat);
        if(tVerFile[fpointer] != config_stat.st_ctime)
        {
            if ((fpFiles[fpointer] = fopen (buf, "r")) == 0)
            {
                Exit_Process ();
            }
            tVerFile[fpointer] = config_stat.st_ctime;
        }
        else
            rewind(fpFiles[fpointer]);
    }

    nkeylen = strlen(zkey);

    while (1)
    {
        memset (buf, 0, sizeof (buf));

        sp = fgets (buf, sizeof (buf), fpFiles[fpointer]);

        if (sp == NULL)
            break;

        buf[strlen(buf)-1] = 0;

        if (*buf == '#' || (int)*buf == 0x00 || *buf == '\t' || *buf == ' ')
            continue;

        if (memcmp (buf, zkey, nkeylen) == 0)
        {
            memcpy (zvalue, buf + nkeylen + 1, strlen (buf) - (nkeylen + 1));
            return;
        }
    }

    return;
}
728x90

'개발 업무(코딩)-개발자였을때 썼던..' 카테고리의 다른 글

CryptoJS.enc.Utf8.parse in c  (0) 2023.01.09
linux javac 사용 예시  (0) 2023.01.09
네트워크 관련(L2, L3, L4 스위치)  (0) 2023.01.09
swagger 함수들 예시  (0) 2023.01.09
was 시작  (0) 2023.01.09