본문 바로가기
C 언어

PHP_STRLCPY

by SpeeDr00t 2016. 7. 27.
반응형

PHP_STRLCPY(dst, src, size, src_size)

- 부제 : php7.0.6 소스 쪼개서 사용하기

1.소스(php.h)

// 
// PHP_STRLCPY
// write by jang, kyoung chip
//
#include <stdio.h>
#include <string.h>


/*
 * This is a fast version of strlcpy which should be used, if you
 * know the size of the destination buffer and if you know
 * the length of the source string.
 *
 * size is the allocated number of bytes of dst
 * src_size is the number of bytes excluding the NUL of src
 */


#define PHP_STRLCPY(dst, src, size, src_size)    \
        {                                        \
                size_t php_str_len;              \
                                                 \
                if (src_size >= size)            \
                        php_str_len = size - 1;  \
                else                             \
                        php_str_len = src_size;  \
                memcpy(dst, src, php_str_len);   \
                dst[php_str_len] = '\0';         \
        }                                        \



int main( int argc , char ** argv )
{
    const char * protocol  = "data://testest";
    char wrapper_name[32];

    memset( wrapper_name , 0x00 , sizeof(wrapper_name) );

    PHP_STRLCPY( wrapper_name , protocol, sizeof(wrapper_name) , strlen(protocol) );

    printf("\nwrapper_name = %s \n", wrapper_name );

return 0;
}                   

결과

hacker@ubuntu:~/c$ ./php_strcpy 

wrapper_name = data://testest                   


반응형

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

time  (0) 2016.08.03
[c] printf  (0) 2016.08.03
매크로 사용하기(php소스 쪼개서 사용하기)  (0) 2016.07.21
strdup  (0) 2016.07.20
공유(shared) 라이브러리 만들기  (0) 2016.07.19