티스토리 툴바

   개발자 로니강(Ronie.Kang)  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
ini 설정 파일에 특정 value 얻어오기

linux에서도 이런 API가 있는지 모르겠어서
하나 간단하게 함수로 만들어 보았습니다.

머리가 나쁜면 손발이 고생한다고 하는데 -0-;
필요하신 분들이 있으면 잘 활용하셔요!

예외 처리등이 부실하니, 좀더 낳은 버전으로 수정 하시면
피드백 부탁 드리겠습니다.

그럼 고운하루 되세요.

/*
 * ex) test.ini
 *     [Data]
 *     value= 30
 *     .....
 *
 * ex) GetProfileToString("[Data]", "value=", buffer, "/tmp/test.ini");
 * 텍스트로 작성된 ini 등 에서 특정 섹션의 값을 읽어 온다.
 */
void GetProfileToString(char *section, char *keyName, char *string, char *fileFullPath)
{
    char tempBuffer[MAX_PATH] = { 0 };
    char *result = NULL;
    FILE *fp = fopen(fileFullPath, "rt");
    if (fp == NULL) {
        goto FINALLY;
    }
    while (fgets((char *)tempBuffer, MAX_PATH, fp)) {
        if (0 == strncmp(section, tempBuffer, strlen(section))) {
            memset(tempBuffer, 0, MAX_PATH);
            while (fgets((char *)tempBuffer, MAX_PATH, fp)) {
                if(tempBuffer[0] == '[') {
                    goto FINALLY;
                }
               
                if(0 == strncmp(keyName, tempBuffer, strlen(keyName))) {
                    char *p = (char*)tempBuffer;
                    p += strlen(keyName);
                    memcpy(string, p, strlen(keyName));
                    fclose(fp);
                    return;
                }
            }
        }
        memset(tempBuffer, 0, MAX_PATH);
    }
FINALLY:
    if (fp) {
        fclose(fp);
    }
    string = result;
}
크리에이티브 커먼즈 라이선스
Creative Commons License
Tag : , ,

name    password    homepage
 hidden


BLOG main image
개발자 로니의 스토리.... 삽질, 날샘, 야근, 개발, 자취생, 일상, 프로그래밍 개발, 등등등....
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (76)
아이폰 (0)
Books (3)
Programming (86)
BroadCast (12)
Personal Projects (6)
유용한 프로그램 (0)
비공개 (0)
 TAGS
torrent SIP 메모리 누수 가카 벨소리 변경 sip 해킹 malloc 조중동 C++ VirtualBox Porter-Duff iPhone usb 인식 실수 스마트폰 warning Memory Leak 벨소리 인터넷전화 arduino uno 국내 토렌토 myLG070 directfb itunes 동기화 C iTunes 바보짓 빵꾸똥꾸 아이폰 It 아이튠즈 iphone 개발환경 토렌토 Linux 미라지 M480 강남역 MB ubuntu 용자
 Calendar
«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
 Recent Entries
Finding Memory Leaks Using t.. (2)
Program Arduino with AVR-GCC
새로운 장난감....
ATMEGA328P-PU
Arduino uno 간단한 보드 설명.
퇴근길 강남역에서 만난 도인?.. (1)
xper 5월 정기모임이 일정 (1)
국내 토렌토 주소 모음
미라지(SKT) M480 벨소리 변경..
myLG070 sip 추출하기 (3)
warning: braces around scala..
 Recent Comments
331-707 충청남도 천..
331-707 충청남도 천안시 서북구 성환읍 대학로 91번지 - 02/17
I think this is bes..
Thesis Writing Services - 02/15
great post nice work
Dissertation Help - 02/14
java/lang/Object j..
sumin - 2011
Common persons do n..
Research paper - 2011
At the essay writin..
buy essay - 2011
The hard working pe..
dissertation service - 2011
Pretty good text re..
buy essay - 2011
Yeah absolutely ve..
resume writing service - 2011
You know that you h..
buy a research paper - 2011
In fact, some stude..
Term Paper Online - 2011
 Recent Trackbacks
COFDM 방식에서의 Bi..
Steve Yoon's log
다중포인터 읽기
.
 Archive
2011/09
2010/06
2010/05
2010/04
2010/02
2010/01
2009/12
2009/11
2009/10
2009/09
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total : 85,600
Today : 47
Yesterday : 59
rss