그리고 iconv() 함수는
문자열 변수들은 2중 포인터로 넘겨주고(왜?) inbytesleft는 strlen(*inbuf) 의 값을 outbytesleft는 strlen(*outbuf) 의 값을 넣어주면된다.
물론 변환에 따라서, 길이가 가변적으로 달라질수 있기 때문에 주의해야 한다.
만약, 변환중 메모리가 넘치게 되면 EILSEQ 에러가 발생하게 되며, (물론 넘치기 전에 데이터는 빼낼수 있다.)
변수의 포인터가 2중 포인터가 아니면 "__gconv: Assertion `outbuf != ((void *)0) && *outbuf != ((void *)0)' failed."
이런 에러를 만나게 될 것이다.
iconv는 utf 나 iso8859 등, 여러가지 방법으로
문자열 코딩을 변환해주는 역활을 하는 함수/유틸리티이다.
$ man -k iconv
iconv (1) - Convert encoding of given files from one encoding to another
iconv (1p) - codeset conversion
iconv (3) - perform character set conversion
iconv (3p) - codeset conversion function
iconv.h [iconv] (0p) - codeset conversion facility
iconv_close (3) - deallocate descriptor for character set conversion
iconv_close (3p) - codeset conversion deallocation function
iconv_open (3) - allocate descriptor for character set conversion
iconv_open (3p) - codeset conversion allocation function
아무튼, iconv는 함수(3/3p) 이자 유틸리티(1) 인데
함수의 경우 iconv_open() - iconv() - iconv_close() 를 이용하여 사용한다.
$ iconv --list
The following list contain all the coded character sets known. This
does
not necessarily mean that all combinations of these names can be used
for
the FROM and TO command line parameters. One coded character set can be
listed with several different names (aliases).
이런 의미를 가지는데, 굳이 해석하자면, 호출 규약 혹은 관용적인 호출방법 이라고 하면 되려나?
아무튼 문득 Iczelion 의 강좌를 읽다보니 어셈블리 기본 구조에
STDCALL 이라는 용어가 나오고, calling convention 이 나오길래 자세히 읽어 봤더니
'함수를 호출시에 인자를 넘겨주는 데이터를 stack에 넣는 방법'을 의미한다.
.MODEL FLAT,
STDCALL .MODEL
is an assembler directive that specifies memory model of your program.
Under
Win32, there's only on model, FLAT
model. STDCALL tells
MASM about
parameter passing convention. Parameter passing convention specifies
the order
of parameter passing, left-to-right or right-to-left, and also who
will
balance the stack frame after the function call. Under Win16, there are two types of calling
convention,
C and PASCAL C calling
convention passes
parameters from right to left, that is , the rightmost parameter is
pushed first.
The caller is responsible for balancing the stack frame after the
call. For
example, in order to call a function named foo(int first_param, int
second_param,
int third_param) in C calling convention the asm codes will look like
this:
push
[third_param]
; Push the third parameter push [second_param]
; Followed by the second push [first_param]
; And the first call foo add sp, 12
; The caller balances the stack frame
PASCAL
calling convention is the reverse of C calling convention. It passes
parameters
from left to right and the callee is responsible for the stack balancing
after
the call. Win16 adopts PASCAL
convention because it produces smaller codes. C convention is useful
when you
don't know how many parameters will be passed to the function as in the
case of
wsprintf(). In the case of wsprintf(), the function has no way to
determine beforehand
how many parameters will be pushed on the stack, so it cannot do the
stack balancing. STDCALL is
the hybrid of C and PASCAL convention. It passes parameter from right to
left
but the callee is responsible for stack balancing after the call.Win32
platform
use STDCALL
exclusively.
Except in one case: wsprintf(). You must use C calling convention with
wsprintf().