본문 바로가기
C 언어

매크로 사용하기(php소스 쪼개서 사용하기)

by SpeeDr00t 2016. 7. 21.
반응형

매크로 사용하기

부제 :  php소스 쪼개서 사용하기(php7.0.8-src/sapi/cgi/cgi_main.c)

발췌 소스

if (!env_document_root && PG(doc_root)) {
    env_document_root = CGI_PUTENV("DOCUMENT_ROOT", PG(doc_root));
    /* fix docroot */
    TRANSLATE_SLASHES(env_document_root);
}

1.소스

#include <stdio.h>
#include <string.h>

#define TRANSLATE_SLASHES(path) \
        { \
                char *tmp = path; \
                while (*tmp) { \
                        if (*tmp == '\\') *tmp = '/'; \
                        tmp++; \
                } \
        }


int main( int argc , char ** argv )
{
    char * buf = "c:\\test\\path\\";

    char env_document_root[256];
    strcpy( env_document_root, buf );

    TRANSLATE_SLASHES(env_document_root);

    printf("result = %s \n", env_document_root );

return 0;
}

결과

gcc -o translate_slashes translate_slashes.c 
hacker@ubuntu:~/c/php$ ./translate_slashes 
result = c:/test/path/ 


반응형

'C 언어' 카테고리의 다른 글

[c] printf  (0) 2016.08.03
PHP_STRLCPY  (0) 2016.07.27
strdup  (0) 2016.07.20
공유(shared) 라이브러리 만들기  (0) 2016.07.19
정적 라이브러리 만들기  (0) 2016.07.19