Changeset 128 in libcf


Ignore:
Timestamp:
06/22/13 12:03:53 (11 years ago)
Author:
cheese
Message:

#1 add bitwise util from ARIA of chevalier

Location:
trunk
Files:
3 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_base.h

    r119 r128  
    11/**
    2  * \file    cf_base.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_base.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
     5 *
    46 * \version 0.1
    57 *
  • trunk/include/cf_codec.h

    r119 r128  
    11/**
    2  * \file    cf_codec.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_codec.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 데이터 변환
     
    1112
    1213#include "cf_base.h"
     14#include "cf_type.h"
    1315
    1416#include <stddef.h>
     
    1921
    2022CF_EXPORT int
    21 CF_Codec_Hex_Encode         (const unsigned char    * bin,
    22                              const size_t           len,
    23                              char                   * hex);
     23CF_Codec_Hex_Encode         (const cf_byte  * bin,
     24                             const size_t   len,
     25                             char           * hex);
    2426
    2527CF_EXPORT int
    26 CF_Codec_Hex_Decode         (const char     * hex,
    27                              unsigned char  * bin,
    28                              size_t         * len);
     28CF_Codec_Hex_Decode         (const char * hex,
     29                             cf_byte    * bin,
     30                             size_t     * len);
    2931
    3032CF_EXPORT int
    31 CF_Codec_Base64_Encode      (const unsigned char    * bin,
    32                              const size_t           len,
    33                              char                   * base64);
     33CF_Codec_Base64_Encode      (const cf_byte  * bin,
     34                             const size_t   len,
     35                             char           * base64);
    3436
    3537CF_EXPORT int
    36 CF_Codec_Base64_Decode      (const char     * base64,
    37                              unsigned char  * bin,
    38                              size_t         * len);
     38CF_Codec_Base64_Decode      (const char * base64,
     39                             cf_byte    * bin,
     40                             size_t     * len);
    3941
    4042#ifdef __cplusplus
  • trunk/include/cf_debug.h

    r120 r128  
    11/**
    2  * \file    cf_debug.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_debug.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 디버그 유틸
     
    1718
    1819#include "cf_base.h"
     20#include "cf_type.h"
    1921
    2022#include <stdio.h>
     
    9294
    9395CF_EXPORT int
    94 CF_Debug_PrintBin       (FILE                   * fp,
    95                          const char             * file,
    96                          const char             * func,
    97                          const int              line,
    98                          const unsigned char    * bin,
    99                          const size_t           len,
    100                          const char             * fmt, ...);
     96CF_Debug_PrintBin       (FILE           * fp,
     97                         const char     * file,
     98                         const char     * func,
     99                         const int      line,
     100                         const cf_byte  * bin,
     101                         const size_t   len,
     102                         const char     * fmt, ...);
    101103
    102104CF_EXPORT int
  • trunk/include/cf_error.h

    r123 r128  
    11/**
    2  * \file    cf_error.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_error.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 오류코드 모음
     
    1415
    1516/* file {{{ */
    16 #define CF_ERROR_FILE                       CF_ERROR_BASE * 2
     17#define CF_ERROR_FILE                       CF_ERROR_BASE * 1
    1718/*------------------------------------------------------------*/
    1819#define CF_ERROR_FILE_OPEN                  CF_ERROR_FILE - 1
     
    2425#define CF_ERROR_FILE_GET_SIZE              CF_ERROR_FILE - 7
    2526#define CF_ERROR_FILE_MAKE_DIRECTORY        CF_ERROR_FILE - 8
    26 
    2727/* }}} file */
    2828
    2929/* socket {{{ */
    30 #define CF_ERROR_SOCKET                     CF_ERROR_BASE * 3
     30#define CF_ERROR_SOCKET                     CF_ERROR_BASE * 2
    3131/*------------------------------------------------------------*/
    3232#define CF_ERROR_SOCKET_INITIALIZE          CF_ERROR_SOCKET - 1
     
    5151
    5252/* thread {{{ */
    53 #define CF_ERROR_THREAD                     CF_ERROR_BASE * 4
     53#define CF_ERROR_THREAD                     CF_ERROR_BASE * 3
    5454/*------------------------------------------------------------*/
    5555#define CF_ERROR_THREAD_CREATE_CTX          CF_ERROR_THREAD - 1
     
    6464
    6565/* mutex {{{ */
    66 #define CF_ERROR_MUTEX                      CF_ERROR_BASE * 5
     66#define CF_ERROR_MUTEX                      CF_ERROR_BASE * 4
    6767/*------------------------------------------------------------*/
    6868#define CF_ERROR_MUTEX_CREATE_CTX           CF_ERROR_MUTEX - 1
     
    7373
    7474/* debug {{{ */
    75 #define CF_ERROR_DEBUG                      CF_ERROR_BASE * 6
     75#define CF_ERROR_DEBUG                      CF_ERROR_BASE * 5
    7676/*------------------------------------------------------------*/
    7777#define CF_ERROR_DEBUG_INVALID_CTX          CF_ERROR_DEBUG - 1
     
    8383
    8484/* log {{{ */
    85 #define CF_ERROR_LOG                        CF_ERROR_BASE * 7
     85#define CF_ERROR_LOG                        CF_ERROR_BASE * 6
    8686/*------------------------------------------------------------*/
    8787#define CF_ERROR_LOG_INITIALIZE             CF_ERROR_LOG - 1
     
    103103
    104104/* codec {{{ */
    105 #define CF_ERROR_CODEC                      CF_ERROR_BASE * 8
     105#define CF_ERROR_CODEC                      CF_ERROR_BASE * 7
    106106/*------------------------------------------------------------*/
    107107#define CF_ERROR_CODEC_INVALID_ARGS         CF_ERROR_CODEC - 1
     
    111111
    112112/* data structure - list/queue/stack {{{ */
    113 #define CF_ERROR_DS                         CF_ERROR_BASE * 9
     113#define CF_ERROR_DS                         CF_ERROR_BASE * 8
    114114/*------------------------------------------------------------*/
    115115#define CF_ERROR_DS_INVALID_CTX             CF_ERROR_DS - 1
     
    121121/* }}} data structure - list/queue/stack */
    122122
     123/* bitwise {{{ */
     124#define CF_ERROR_BITWISE                    CF_ERROR_BASE * 9
     125/*------------------------------------------------------------*/
     126#define CF_ERROR_BITWISE_INVALID_ARGS       CF_ERROR_BITWISE - 1
     127#define CF_ERROR_BITWISE_ALLOCATE_BUFFER    CF_ERROR_BITWISE - 2
     128/* }}} bitwise */
     129
    123130#endif // #ifndef __CF_ERROR_H__
  • trunk/include/cf_file.h

    r119 r128  
    11/**
    2  * \file    cf_file.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_file.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 파일 입출력
  • trunk/include/cf_list.h

    r119 r128  
    11/**
    2  * \file    cf_list.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_list.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 연결 리스트
  • trunk/include/cf_log.h

    r119 r128  
    11/**
    2  * \file    cf_log.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_log.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 로그
  • trunk/include/cf_mutex.h

    r126 r128  
    11/**
    2  * \file    cf_mutex.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_mutex.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 뮤텍스 지원
  • trunk/include/cf_queue.h

    r119 r128  
    11/**
    2  * \file    cf_queue.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_queue.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 큐
  • trunk/include/cf_socket.h

    r119 r128  
    11/**
    2  * \file    cf_socket.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_socket.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief TCP 소켓 지원
  • trunk/include/cf_stack.h

    r119 r128  
    11/**
    2  * \file    cf_stack.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_stack.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 스택
  • trunk/include/cf_thread.h

    r126 r128  
    11/**
    2  * \file    cf_thread.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_thread.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 멀티스레드 지원
  • trunk/src/cf_codec.c

    r119 r128  
    11/**
    2  * \file    cf_codec.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_codec.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 데이터 변환 구현
    67 */
    78#include "cf_codec.h"
     9#include "cf_type.h"
    810#include "cf_error.h"
    911
     
    1517        return CF_ERROR_CODEC_INVALID_ARGS
    1618
    17 const static unsigned char g_ascii_HexDecode[] = {
     19const static cf_byte g_ascii_HexDecode[] = {
    1820    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /*  00 -  15 */
    1921    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /*  16 -  31 */
     
    4850};
    4951
    50 const static unsigned char g_ascii_Base64Decode[] = {
     52const static cf_byte g_ascii_Base64Decode[] = {
    5153    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,    /*  00 -  15 */
    5254    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,    /*  16 -  31 */
     
    8284 */
    8385int
    84 CF_Codec_Hex_Encode (const unsigned char    * bin,
    85                      const size_t           len,
    86                      char                   * hex)
     86CF_Codec_Hex_Encode (const cf_byte  * bin,
     87                     const size_t   len,
     88                     char           * hex)
    8789{
    8890    size_t  iter = 0;
    8991    size_t  hexlen = len * 2 + 1;
    9092
    91     const unsigned char * ptr = bin;
     93    const cf_byte   * ptr = bin;
    9294
    9395    const static char   hexchar[] = {'0', '1', '2', '3',
     
    122124 */
    123125int
    124 CF_Codec_Hex_Decode (const char     * hex,
    125                      unsigned char  * bin,
    126                      size_t         * len)
     126CF_Codec_Hex_Decode (const char * hex,
     127                     cf_byte    * bin,
     128                     size_t     * len)
    127129{
    128     size_t  length = 0; /* absolutely even-number */
    129     size_t  iter = 0;
    130     size_t  binlen = 0;
    131 
    132     const char      * ptr = hex;
    133     char            buf = 0;
    134     unsigned char   val = 0;
    135     unsigned char   asciiHex = 0;
     130    size_t      length = 0; /* absolutely even-number */
     131    size_t      iter = 0;
     132    size_t      binlen = 0;
     133
     134    const char  * ptr = hex;
     135    char        buf = 0;
     136    cf_byte     val = 0;
     137    cf_byte     asciiHex = 0;
    136138
    137139    ASSERT_ARGS (hex == NULL);
     
    156158        do {                                        \
    157159        buf = *(x);                                 \
    158         val = (unsigned char)(val << 4);            \
     160        val = (cf_byte)(val << 4);          \
    159161        asciiHex = g_ascii_HexDecode[(int)buf];     \
    160162                                                    \
    161         val |=  (unsigned char)                     \
     163        val |=  (cf_byte)                       \
    162164                (buf - asciiHex + (asciiHex == '0' ? 0 : 10));  \
    163165        } while (0)
     
    188190 */
    189191int
    190 CF_Codec_Base64_Encode (const unsigned char * bin,
     192CF_Codec_Base64_Encode (const cf_byte   * bin,
    191193                        const size_t        len,
    192194                        char                * base64)
    193195{
    194     const unsigned char * src = bin;
    195     char                * dst = base64;
     196    const cf_byte   * src = bin;
     197    char            * dst = base64;
    196198
    197199    ASSERT_ARGS (src == NULL);
     
    252254int
    253255CF_Codec_Base64_Decode (const char      * base64,
    254                         unsigned char   * bin,
     256                        cf_byte * bin,
    255257                        size_t          * len)
    256258{
    257     const char      * src = base64;
    258     unsigned char   * dst = bin;
    259     int             remain = 0;
    260     int             binlen = 0;
     259    const char  * src = base64;
     260    cf_byte     * dst = bin;
     261    int         remain = 0;
     262    int         binlen = 0;
    261263
    262264    ASSERT_ARGS (src == NULL);
     
    283285    for (src = base64 ; remain > 4 ; remain -= 4, src += 4)
    284286    {
    285         *dst++ = (unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));
    286         *dst++ = (unsigned char)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));
    287         *dst++ = (unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));
     287        *dst++ = (cf_byte)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));
     288        *dst++ = (cf_byte)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));
     289        *dst++ = (cf_byte)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));
    288290    }
    289291
    290292    if (remain > 1)
    291         *dst++ = (unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));
     293        *dst++ = (cf_byte)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));
    292294    if (remain > 2)
    293         *dst++ = (unsigned char)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));
     295        *dst++ = (cf_byte)(SEXTUPLE_D_3 (src) | SEXTUPLE_D_4 (src));
    294296    if (remain > 3)
    295         *dst++ = (unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));
     297        *dst++ = (cf_byte)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));
    296298
    297299    return binlen - (4 - remain);
  • trunk/src/cf_debug.c

    r125 r128  
    11/**
    2  * \file    cf_debug.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_debug.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 디버그 유틸 구현
     
    7576
    7677static int
    77 CF_Debug_Local_PrintBin (FILE                   * fp,
    78                          const char             * file,
    79                          const char             * func,
    80                          const int              line,
    81                          const unsigned char    * bin,
    82                          const size_t           len)
     78CF_Debug_Local_PrintBin (FILE           * fp,
     79                         const char     * file,
     80                         const char     * func,
     81                         const int      line,
     82                         const cf_byte  * bin,
     83                         const size_t   len)
    8384{
    8485    size_t i, j;
     
    156157 */
    157158int
    158 CF_Debug_PrintBin (FILE                 * fp,
    159                    const char           * file,
    160                    const char           * func,
    161                    const int            line,
    162                    const unsigned char  * bin,
    163                    const size_t         len,
    164                    const char           * fmt, ...)
     159CF_Debug_PrintBin (FILE             * fp,
     160                   const char       * file,
     161                   const char       * func,
     162                   const int        line,
     163                   const cf_byte    * bin,
     164                   const size_t     len,
     165                   const char       * fmt, ...)
    165166{
    166167    va_list valist;
  • trunk/src/cf_file.c

    r119 r128  
    11/**
    2  * \file    cf_file.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_file.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 파일 입출력 구현
  • trunk/src/cf_list.c

    r119 r128  
    11/**
    2  * \file    cf_list.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_list.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 연결 리스트 구현
  • trunk/src/cf_local.h

    r119 r128  
    11/**
    2  * \file    cf_local.h
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_local.h
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 */
    56#ifndef __CF_LOCAL_H__
  • trunk/src/cf_log.c

    r127 r128  
    11/**
    2  * \file    cf_log.c
    3  * \author  myusgun <myusgun@gmail.com>
    4  * \author  vfire
     2 * \file cf_log.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
     5 * \author vfire
    56 *
    67 * \brief 로그 구현
  • trunk/src/cf_mutex.c

    r126 r128  
    11/**
    2  * \file    cf_mutex.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_mutex.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 뮤텍스 구현
  • trunk/src/cf_queue.c

    r119 r128  
    11/**
    2  * \file    cf_queue.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_queue.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 큐 구현
  • trunk/src/cf_socket.c

    r119 r128  
    11/**
    2  * \file    cf_socket.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_socket.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief TCP 소켓 구현
  • trunk/src/cf_stack.c

    r119 r128  
    11/**
    2  * \file    cf_stack.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_stack.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 스택 구현
  • trunk/src/cf_thread.c

    r126 r128  
    11/**
    2  * \file    cf_thread.c
    3  * \author  myusgun <myusgun@gmail.com>
     2 * \file cf_thread.c
     3 *
     4 * \author myusgun <myusgun@gmail.com>
    45 *
    56 * \brief 멀티 스레드 구현
  • trunk/src/makefile

    r126 r128  
    1919                    cf_queue        \
    2020                    cf_stack        \
     21                    cf_bitwise      \
    2122
    2223TARGET_NAME     = cf
Note: See TracChangeset for help on using the changeset viewer.