{"id":214,"date":"2010-04-18T00:42:02","date_gmt":"2010-04-18T09:42:02","guid":{"rendered":"\/blog\/?p=214"},"modified":"2023-09-21T09:39:10","modified_gmt":"2023-09-21T00:39:10","slug":"iconv-%eb%ac%b8%ec%9e%90%ec%bd%94%eb%93%9c-%eb%b3%80%ed%99%98","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=214","title":{"rendered":"iconv \ubb38\uc790\ucf54\ub4dc \ubcc0\ud658"},"content":{"rendered":"\n<p style=\"font-family: GulimChe,Sans-serif;\">\/*<br \/>&nbsp;* iconv\ub97c \uc0ac\uc6a9\ud558\uc5ec \ubb38\uc790\ucf54\ub4dc\ub97c \ubcc0\uacbd\ud55c\ub2e4.<br \/>&nbsp;* \uc774 \ud568\uc218\uc5d0\uc11c \ubc18\ud658\ub41c \ud3ec\uc778\ud130\ub294 \ubc18\ub4dc\uc2dc safe_free \ub418\uc5b4\uc57c \n\ud55c\ub2e4.<br \/>&nbsp;* \uc2e4\ud328\ud588\uc744 \uacbd\uc6b0 NULL\uc744 \ubc18\ud658\ud55c\ub2e4.<br \/>&nbsp;* \uc0ac\uc6a9 \uc608\uc81c : p2 = iconv_convert(p1, \"EUC-KR\", \n\"UTF-8\"); safe_free(p1);<br \/>&nbsp;*\/<br \/>#define ICONV_BYTES(n) ((n) * 6 + 1)<br \/>char \n*iconv_convert(const char *srcp, const char *to, const char *from)<br \/>{<br \/>&nbsp; &nbsp; \niconv_t iconv_value;<br \/>&nbsp; &nbsp; size_t iconv_ret, in_bytes, dstp_bytes, \nlast_bytes;<br \/>&nbsp; &nbsp; char *dstp, *clone_dstp;<\/p>\n<p style=\"font-family: GulimChe,Sans-serif;\">&nbsp; &nbsp; \/\/ iconv \ud568\uc218\ub97c \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c iconv_open\uc744 \ud638\ucd9c\ud55c\ub2e4.<br \/>&nbsp; &nbsp; if ((iconv_value = \niconv_open(to, from)) == (iconv_t)-1)<br \/>&nbsp; &nbsp; {<br \/>iconv_error: \/\/ Error \ucc98\ub9ac \nLabel<br \/>&nbsp; &nbsp; &nbsp; &nbsp; iconv_close(iconv_value);<\/p>\n<p style=\"font-family: GulimChe,Sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; return NULL;<br \/>&nbsp; &nbsp; }<br \/>&nbsp; &nbsp; else<br \/>&nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ in_bytes\uc5d0 \uc6d0\ubcf8 \n\ubb38\uc790\uc5f4 \uae38\uc774\ub97c \ub123\ub294\ub2e4.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; in_bytes = strlen(srcp);<\/p>\n<p style=\"font-family: GulimChe,Sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \ubcc0\ud658\ub41c \ubb38\uc790\uc5f4\uc774 \ub4e4\uc5b4\uac08 \uacf5\uac04\uc744 \uc900\ube44\ud55c\ub2e4.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; dstp = (char \n*)safe_malloc(ICONV_BYTES(in_bytes));<br \/>&nbsp; &nbsp; &nbsp; &nbsp; if (dstp == \nNULL)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; goto iconv_error;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; clone_dstp = dstp;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \ndstp_bytes = ICONV_BYTES(in_bytes);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; do<br \/>&nbsp; &nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \nlast_bytes = in_bytes;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \ubcc0\ud658 \ud55c\ub2e4.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iconv_ret = \niconv(iconv_value, &amp;srcp, (size_t *)&amp;in_bytes, (char **)&amp;clone_dstp, \n(size_t *)&amp;dstp_bytes);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (iconv_ret &lt; \n(size_t)0)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \uc624\ub958 \ucc98\ub9ac<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \nif(errno == EILSEQ || errno == EINVAL)<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \n{<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; srcp++; &nbsp; &nbsp; &nbsp;&nbsp; \/\/ skip broken \nbyte<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in_bytes--;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \nelse<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; goto \niconv_error;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; while \n(in_bytes &gt; 0 &amp;&amp; in_bytes &lt; last_bytes);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \niconv_close(iconv_value);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; *clone_dstp = '\\0';<\/p>\n<p style=\"font-family: GulimChe,Sans-serif;\">&nbsp; &nbsp; &nbsp; &nbsp; return dstp;<br \/>&nbsp; &nbsp; }<\/p>\n<p style=\"font-family: GulimChe,Sans-serif;\">&nbsp; &nbsp; return NULL;<br \/>}\n<\/p><p style=\"font-family: GulimChe,Sans-serif;\"><br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/*&nbsp;* iconv\ub97c \uc0ac\uc6a9\ud558\uc5ec \ubb38\uc790\ucf54\ub4dc\ub97c \ubcc0\uacbd\ud55c\ub2e4.&nbsp;* \uc774 \ud568\uc218\uc5d0\uc11c \ubc18\ud658\ub41c \ud3ec\uc778\ud130\ub294 \ubc18\ub4dc\uc2dc safe_free \ub418\uc5b4\uc57c \ud55c\ub2e4.&nbsp;* \uc2e4\ud328\ud588\uc744 \uacbd\uc6b0 NULL\uc744 \ubc18\ud658\ud55c\ub2e4.&nbsp;* \uc0ac\uc6a9 \uc608\uc81c : p2 = iconv_convert(p1, &#8220;EUC-KR&#8221;, &#8220;UTF-8&#8221;); safe_free(p1);&nbsp;*\/#define ICONV_BYTES(n) ((n) * 6 + 1)char *iconv_convert(const char *srcp, const char *to, const char *from){&nbsp; &nbsp; iconv_t iconv_value;&nbsp; &nbsp; size_t iconv_ret, in_bytes, dstp_bytes, last_bytes;&nbsp; &nbsp; char *dstp, *clone_dstp; &nbsp; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[19],"tags":[],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-development_lib"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=214"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}