git on Mac OS and precomposed unicode

Mac OS X mangles file names containing unicode on file systems HFS+, VFAT or SAMBA. When a file using unicode code points outside ASCII is created on a HFS+ drive, the file name is converted into decomposed unicode and written to disk. No conversion is done if the file name is already decomposed unicode. Calling open("\xc3\x84", ...) with a precomposed "Ä" yields the same result as open("\x41\xcc\x88",...) with a decomposed "Ä". As a consequence, readdir() returns the file names in decomposed unicode, even if the user expects precomposed unicode. Unlike on HFS+, Mac OS X stores files on a VFAT drive (e.g. an USB drive) in precomposed unicode, but readdir() still returns file names in decomposed unicode. When a git repository is stored on a network share using SAMBA, file names are send over the wire and written to disk on the remote system in precomposed unicode, but Mac OS X readdir() returns decomposed unicode to be compatible with its behaviour on HFS+ and VFAT. The unicode decomposition causes many problems: - The names "git add" and other commands get from the end user may often be precomposed form (the decomposed form is not easily input from the keyboard), but when the commands read from the filesystem to see what it is going to update the index with already is on the filesystem, readdir() will give decomposed form, which is different. - Similarly "git log", "git mv" and all other commands that need to compare pathnames found on the command line (often but not always precomposed form; a command line input resulting from globbing may be in decomposed) with pathnames found in the tree objects (should be precomposed form to be compatible with other systems and for consistency in general). - The same for names stored in the index, which should be precomposed, that may need to be compared with the names read from readdir(). NFS mounted from Linux is fully transparent and does not suffer from the above. As Mac OS X treats precomposed and decomposed file names as equal, we can - wrap readdir() on Mac OS X to return the precomposed form, and - normalize decomposed form given from the command line also to the precomposed form, to ensure that all pathnames used in Git are always in the precomposed form. This behaviour can be requested by setting "core.precomposedunicode" configuration variable to true. The code in compat/precomposed_utf8.c implements basically 4 new functions: precomposed_utf8_opendir(), precomposed_utf8_readdir(), precomposed_utf8_closedir() and precompose_argv(). The first three are to wrap opendir(3), readdir(3), and closedir(3) functions. The argv[] conversion allows to use the TAB filename completion done by the shell on command line. It tolerates other tools which use readdir() to feed decomposed file names into git. When creating a new git repository with "git init" or "git clone", "core.precomposedunicode" will be set "false". The user needs to activate this feature manually. She typically sets core.precomposedunicode to "true" on HFS and VFAT, or file systems mounted via SAMBA. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Jul 8, 2012 at 15:50 UTC 76759c7dff53e8c84e975b88cb8245587c14c7ba
13 files changed +446 -10
Documentation/config.txt
+9
@@ -210,6 +210,15 @@ The default is false, except linkgit:git-clone[1] or linkgit:git-init[1]
210 will probe and set core.ignorecase true if appropriate when the repository
211 is created.
212
213 +core.precomposeunicode::
214 + This option is only used by Mac OS implementation of git.
215 + When core.precomposeunicode=true, git reverts the unicode decomposition
216 + of filenames done by Mac OS. This is useful when sharing a repository
217 + between Mac OS and Linux or Windows.
218 + (Git for Windows 1.7.10 or higher is needed, or git under cygwin 1.7).
219 + When false, file names are handled fully transparent by git,
220 + which is backward compatible with older versions of git.
221 +
222 core.trustctime::
223 If false, the ctime differences between the index and the
224 working tree are ignored; useful when the inode change time
Makefile
+3
@@ -600,6 +600,7 @@ LIB_H += compat/bswap.h
600 LIB_H += compat/cygwin.h
601 LIB_H += compat/mingw.h
602 LIB_H += compat/obstack.h
603 +LIB_H += compat/precompose_utf8.h
604 LIB_H += compat/terminal.h
605 LIB_H += compat/win32/dirent.h
606 LIB_H += compat/win32/poll.h
@@ -990,6 +991,8 @@ ifeq ($(uname_S),Darwin)
991 NO_MEMMEM = YesPlease
992 USE_ST_TIMESPEC = YesPlease
993 HAVE_DEV_TTY = YesPlease
994 + COMPAT_OBJS += compat/precompose_utf8.o
995 + BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
996 endif
997 ifeq ($(uname_S),SunOS)
998 NEEDS_SOCKET = YesPlease
builtin/init-db.c
+1
@@ -290,6 +290,7 @@ static int create_default_files(const char *template_path)
290 strcpy(path + len, "CoNfIg");
291 if (!access(path, F_OK))
292 git_config_set("core.ignorecase", "true");
293 + probe_utf8_pathname_composition(path, len);
294 }
295
296 return reinit;
cache.h
+1
@@ -560,6 +560,7 @@ extern int read_replace_refs;
560 extern int fsync_object_files;
561 extern int core_preload_index;
562 extern int core_apply_sparse_checkout;
563 +extern int precomposed_unicode;
564
565 enum branch_track {
566 BRANCH_TRACK_UNSPECIFIED = -1,
compat/precompose_utf8.c new
+190
@@ -0,0 +1,190 @@
1 +/*
2 + * Converts filenames from decomposed unicode into precomposed unicode.
3 + * Used on MacOS X.
4 +*/
5 +
6 +
7 +#define PRECOMPOSE_UNICODE_C
8 +
9 +#include "cache.h"
10 +#include "utf8.h"
11 +#include "precompose_utf8.h"
12 +
13 +typedef char *iconv_ibp;
14 +const static char *repo_encoding = "UTF-8";
15 +const static char *path_encoding = "UTF-8-MAC";
16 +
17 +
18 +static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
19 +{
20 + const uint8_t *utf8p = (const uint8_t*) s;
21 + size_t strlen_chars = 0;
22 + size_t ret = 0;
23 +
24 + if ((!utf8p) || (!*utf8p)) {
25 + return 0;
26 + }
27 +
28 + while((*utf8p) && maxlen) {
29 + if (*utf8p & 0x80)
30 + ret++;
31 + strlen_chars++;
32 + utf8p++;
33 + maxlen--;
34 + }
35 + if (strlen_c)
36 + *strlen_c = strlen_chars;
37 +
38 + return ret;
39 +}
40 +
41 +
42 +void probe_utf8_pathname_composition(char *path, int len)
43 +{
44 + const static char *auml_nfc = "\xc3\xa4";
45 + const static char *auml_nfd = "\x61\xcc\x88";
46 + int output_fd;
47 + if (precomposed_unicode != -1)
48 + return; /* We found it defined in the global config, respect it */
49 + path[len] = 0;
50 + strcpy(path + len, auml_nfc);
51 + output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
52 + if (output_fd >=0) {
53 + close(output_fd);
54 + path[len] = 0;
55 + strcpy(path + len, auml_nfd);
56 + /* Indicate to the user, that we can configure it to true */
57 + if (0 == access(path, R_OK))
58 + git_config_set("core.precomposeunicode", "false");
59 + /* To be backward compatible, set precomposed_unicode to 0 */
60 + precomposed_unicode = 0;
61 + path[len] = 0;
62 + strcpy(path + len, auml_nfc);
63 + unlink(path);
64 + }
65 +}
66 +
67 +
68 +void precompose_argv(int argc, const char **argv)
69 +{
70 + int i = 0;
71 + const char *oldarg;
72 + char *newarg;
73 + iconv_t ic_precompose;
74 +
75 + if (precomposed_unicode != 1)
76 + return;
77 +
78 + ic_precompose = iconv_open(repo_encoding, path_encoding);
79 + if (ic_precompose == (iconv_t) -1)
80 + return;
81 +
82 + while (i < argc) {
83 + size_t namelen;
84 + oldarg = argv[i];
85 + if (has_utf8(oldarg, (size_t)-1, &namelen)) {
86 + newarg = reencode_string_iconv(oldarg, namelen, ic_precompose);
87 + if (newarg)
88 + argv[i] = newarg;
89 + }
90 + i++;
91 + }
92 + iconv_close(ic_precompose);
93 +}
94 +
95 +
96 +PREC_DIR *precompose_utf8_opendir(const char *dirname)
97 +{
98 + PREC_DIR *prec_dir = xmalloc(sizeof(PREC_DIR));
99 + prec_dir->dirent_nfc = xmalloc(sizeof(dirent_prec_psx));
100 + prec_dir->dirent_nfc->max_name_len = sizeof(prec_dir->dirent_nfc->d_name);
101 +
102 + prec_dir->dirp = opendir(dirname);
103 + if (!prec_dir->dirp) {
104 + free(prec_dir->dirent_nfc);
105 + free(prec_dir);
106 + return NULL;
107 + } else {
108 + int ret_errno = errno;
109 + prec_dir->ic_precompose = iconv_open(repo_encoding, path_encoding);
110 + /* if iconv_open() fails, die() in readdir() if needed */
111 + errno = ret_errno;
112 + }
113 +
114 + return prec_dir;
115 +}
116 +
117 +struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
118 +{
119 + struct dirent *res;
120 + res = readdir(prec_dir->dirp);
121 + if (res) {
122 + size_t namelenz = strlen(res->d_name) + 1; /* \0 */
123 + size_t new_maxlen = namelenz;
124 +
125 + int ret_errno = errno;
126 +
127 + if (new_maxlen > prec_dir->dirent_nfc->max_name_len) {
128 + size_t new_len = sizeof(dirent_prec_psx) + new_maxlen -
129 + sizeof(prec_dir->dirent_nfc->d_name);
130 +
131 + prec_dir->dirent_nfc = xrealloc(prec_dir->dirent_nfc, new_len);
132 + prec_dir->dirent_nfc->max_name_len = new_maxlen;
133 + }
134 +
135 + prec_dir->dirent_nfc->d_ino = res->d_ino;
136 + prec_dir->dirent_nfc->d_type = res->d_type;
137 +
138 + if ((precomposed_unicode == 1) && has_utf8(res->d_name, (size_t)-1, NULL)) {
139 + if (prec_dir->ic_precompose == (iconv_t)-1) {
140 + die("iconv_open(%s,%s) failed, but needed:\n"
141 + " precomposed unicode is not supported.\n"
142 + " If you wnat to use decomposed unicode, run\n"
143 + " \"git config core.precomposeunicode false\"\n",
144 + repo_encoding, path_encoding);
145 + } else {
146 + iconv_ibp cp = (iconv_ibp)res->d_name;
147 + size_t inleft = namelenz;
148 + char *outpos = &prec_dir->dirent_nfc->d_name[0];
149 + size_t outsz = prec_dir->dirent_nfc->max_name_len;
150 + size_t cnt;
151 + errno = 0;
152 + cnt = iconv(prec_dir->ic_precompose, &cp, &inleft, &outpos, &outsz);
153 + if (errno || inleft) {
154 + /*
155 + * iconv() failed and errno could be E2BIG, EILSEQ, EINVAL, EBADF
156 + * MacOS X avoids illegal byte sequemces.
157 + * If they occur on a mounted drive (e.g. NFS) it is not worth to
158 + * die() for that, but rather let the user see the original name
159 + */
160 + namelenz = 0; /* trigger strlcpy */
161 + }
162 + }
163 + }
164 + else
165 + namelenz = 0;
166 +
167 + if (!namelenz)
168 + strlcpy(prec_dir->dirent_nfc->d_name, res->d_name,
169 + prec_dir->dirent_nfc->max_name_len);
170 +
171 + errno = ret_errno;
172 + return prec_dir->dirent_nfc;
173 + }
174 + return NULL;
175 +}
176 +
177 +
178 +int precompose_utf8_closedir(PREC_DIR *prec_dir)
179 +{
180 + int ret_value;
181 + int ret_errno;
182 + ret_value = closedir(prec_dir->dirp);
183 + ret_errno = errno;
184 + if (prec_dir->ic_precompose != (iconv_t)-1)
185 + iconv_close(prec_dir->ic_precompose);
186 + free(prec_dir->dirent_nfc);
187 + free(prec_dir);
188 + errno = ret_errno;
189 + return ret_value;
190 +}
compat/precompose_utf8.h new
+45
@@ -0,0 +1,45 @@
1 +#ifndef PRECOMPOSE_UNICODE_H
2 +#include <sys/stat.h>
3 +#include <sys/types.h>
4 +#include <dirent.h>
5 +#include <iconv.h>
6 +
7 +
8 +typedef struct dirent_prec_psx {
9 + ino_t d_ino; /* Posix */
10 + size_t max_name_len; /* See below */
11 + unsigned char d_type; /* available on all systems git runs on */
12 +
13 + /*
14 + * See http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html
15 + * NAME_MAX + 1 should be enough, but some systems have
16 + * NAME_MAX=255 and strlen(d_name) may return 508 or 510
17 + * Solution: allocate more when needed, see precompose_utf8_readdir()
18 + */
19 + char d_name[NAME_MAX+1];
20 +} dirent_prec_psx;
21 +
22 +
23 +typedef struct {
24 + iconv_t ic_precompose;
25 + DIR *dirp;
26 + struct dirent_prec_psx *dirent_nfc;
27 +} PREC_DIR;
28 +
29 +void precompose_argv(int argc, const char **argv);
30 +void probe_utf8_pathname_composition(char *, int);
31 +
32 +PREC_DIR *precompose_utf8_opendir(const char *dirname);
33 +struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *dirp);
34 +int precompose_utf8_closedir(PREC_DIR *dirp);
35 +
36 +#ifndef PRECOMPOSE_UNICODE_C
37 +#define dirent dirent_prec_psx
38 +#define opendir(n) precompose_utf8_opendir(n)
39 +#define readdir(d) precompose_utf8_readdir(d)
40 +#define closedir(d) precompose_utf8_closedir(d)
41 +#define DIR PREC_DIR
42 +#endif /* PRECOMPOSE_UNICODE_C */
43 +
44 +#define PRECOMPOSE_UNICODE_H
45 +#endif /* PRECOMPOSE_UNICODE_H */
config.c
+5
@@ -758,6 +758,11 @@ static int git_default_core_config(const char *var, const char *value)
758 return 0;
759 }
760
761 + if (!strcmp(var, "core.precomposeunicode")) {
762 + precomposed_unicode = git_config_bool(var, value);
763 + return 0;
764 + }
765 +
766 /* Add other config variables here and to Documentation/config.txt. */
767 return 0;
768 }
environment.c
+1
@@ -58,6 +58,7 @@ char *notes_ref_name;
58 int grafts_replace_parents = 1;
59 int core_apply_sparse_checkout;
60 int merge_log_config = -1;
61 +int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
62 struct startup_info *startup_info;
63 unsigned long pack_size_limit_cfg;
64
git-compat-util.h
+9
@@ -153,6 +153,15 @@
153 #endif
154 #endif
155
156 +/* used on Mac OS X */
157 +#ifdef PRECOMPOSE_UNICODE
158 +#include "compat/precompose_utf8.h"
159 +#else
160 +#define precompose_str(in,i_nfd2nfc)
161 +#define precompose_argv(c,v)
162 +#define probe_utf8_pathname_composition(a,b)
163 +#endif
164 +
165 #ifndef NO_LIBGEN_H
166 #include <libgen.h>
167 #else
parse-options.c
+1
@@ -476,6 +476,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
476 usage_with_options(usagestr, options);
477 }
478
479 + precompose_argv(argc, argv);
480 return parse_options_end(&ctx);
481 }
482
t/t3910-mac-os-precompose.sh new
+164
@@ -0,0 +1,164 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2012 Torsten Bögershausen
4 +#
5 +
6 +test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)'
7 +
8 +. ./test-lib.sh
9 +
10 +Adiarnfc=`printf '\303\204'`
11 +Adiarnfd=`printf 'A\314\210'`
12 +
13 +# check if the feature is compiled in
14 +mkdir junk &&
15 +>junk/"$Adiarnfc" &&
16 +case "$(cd junk && echo *)" in
17 + "$Adiarnfd")
18 + test_nfd=1
19 + ;;
20 + *) ;;
21 +esac
22 +rm -rf junk
23 +
24 +
25 +if test "$test_nfd"
26 +then
27 + # create more utf-8 variables
28 + Odiarnfc=`printf '\303\226'`
29 + Odiarnfd=`printf 'O\314\210'`
30 + AEligatu=`printf '\303\206'`
31 + Invalidu=`printf '\303\377'`
32 +
33 +
34 + #Create a string with 255 bytes (decomposed)
35 + Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte
36 + Alongd=$Alongd$Alongd$Alongd #63 Byte
37 + Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte
38 +
39 + #Create a string with 254 bytes (precomposed)
40 + Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte
41 + Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte
42 + Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte
43 + Alongc=$Alongc$AEligatu$AEligatu #254 Byte
44 +
45 + test_expect_success "detect if nfd needed" '
46 + precomposeunicode=`git config core.precomposeunicode` &&
47 + test "$precomposeunicode" = false &&
48 + git config core.precomposeunicode true
49 + '
50 + test_expect_success "setup" '
51 + >x &&
52 + git add x &&
53 + git commit -m "1st commit" &&
54 + git rm x &&
55 + git commit -m "rm x"
56 + '
57 + test_expect_success "setup case mac" '
58 + git checkout -b mac_os
59 + '
60 + # This will test nfd2nfc in readdir()
61 + test_expect_success "add file Adiarnfc" '
62 + echo f.Adiarnfc >f.$Adiarnfc &&
63 + git add f.$Adiarnfc &&
64 + git commit -m "add f.$Adiarnfc"
65 + '
66 + # This will test nfd2nfc in git stage()
67 + test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" '
68 + mkdir d.$Adiarnfd &&
69 + echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&
70 + git stage d.$Adiarnfd/f.$Adiarnfd &&
71 + git commit -m "add d.$Adiarnfd/f.$Adiarnfd"
72 + '
73 + test_expect_success "add link Adiarnfc" '
74 + ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&
75 + git add l.$Adiarnfc &&
76 + git commit -m "add l.Adiarnfc"
77 + '
78 + # This will test git log
79 + test_expect_success "git log f.Adiar" '
80 + git log f.$Adiarnfc > f.Adiarnfc.log &&
81 + git log f.$Adiarnfd > f.Adiarnfd.log &&
82 + test -s f.Adiarnfc.log &&
83 + test -s f.Adiarnfd.log &&
84 + test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
85 + rm f.Adiarnfc.log f.Adiarnfd.log
86 + '
87 + # This will test git ls-files
88 + test_expect_success "git lsfiles f.Adiar" '
89 + git ls-files f.$Adiarnfc > f.Adiarnfc.log &&
90 + git ls-files f.$Adiarnfd > f.Adiarnfd.log &&
91 + test -s f.Adiarnfc.log &&
92 + test -s f.Adiarnfd.log &&
93 + test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
94 + rm f.Adiarnfc.log f.Adiarnfd.log
95 + '
96 + # This will test git mv
97 + test_expect_success "git mv" '
98 + git mv f.$Adiarnfd f.$Odiarnfc &&
99 + git mv d.$Adiarnfd d.$Odiarnfc &&
100 + git mv l.$Adiarnfd l.$Odiarnfc &&
101 + git commit -m "mv Adiarnfd Odiarnfc"
102 + '
103 + # Files can be checked out as nfc
104 + # And the link has been corrected from nfd to nfc
105 + test_expect_success "git checkout nfc" '
106 + rm f.$Odiarnfc &&
107 + git checkout f.$Odiarnfc
108 + '
109 + # Make it possible to checkout files with their NFD names
110 + test_expect_success "git checkout file nfd" '
111 + rm -f f.* &&
112 + git checkout f.$Odiarnfd
113 + '
114 + # Make it possible to checkout links with their NFD names
115 + test_expect_success "git checkout link nfd" '
116 + rm l.* &&
117 + git checkout l.$Odiarnfd
118 + '
119 + test_expect_success "setup case mac2" '
120 + git checkout master &&
121 + git reset --hard &&
122 + git checkout -b mac_os_2
123 + '
124 + # This will test nfd2nfc in git commit
125 + test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" '
126 + mkdir d2.$Adiarnfd &&
127 + echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&
128 + git add d2.$Adiarnfd/f.$Adiarnfd &&
129 + git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd
130 + '
131 + test_expect_success "setup for long decomposed filename" '
132 + git checkout master &&
133 + git reset --hard &&
134 + git checkout -b mac_os_long_nfd_fn
135 + '
136 + test_expect_success "Add long decomposed filename" '
137 + echo longd >$Alongd &&
138 + git add * &&
139 + git commit -m "Long filename"
140 + '
141 + test_expect_success "setup for long precomposed filename" '
142 + git checkout master &&
143 + git reset --hard &&
144 + git checkout -b mac_os_long_nfc_fn
145 + '
146 + test_expect_success "Add long precomposed filename" '
147 + echo longc >$Alongc &&
148 + git add * &&
149 + git commit -m "Long filename"
150 + '
151 + # Test if the global core.precomposeunicode stops autosensing
152 + # Must be the last test case
153 + test_expect_success "respect git config --global core.precomposeunicode" '
154 + git config --global core.precomposeunicode true &&
155 + rm -rf .git &&
156 + git init &&
157 + precomposeunicode=`git config core.precomposeunicode` &&
158 + test "$precomposeunicode" = "true"
159 + '
160 +else
161 + say "Skipping nfc/nfd tests"
162 +fi
163 +
164 +test_done
utf8.c
+16 -10
@@ -433,19 +433,12 @@ int is_encoding_utf8(const char *name)
433 #else
434 typedef char * iconv_ibp;
435 #endif
436 -char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding)
436 +char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv)
437 {
438 - iconv_t conv;
439 - size_t insz, outsz, outalloc;
438 + size_t outsz, outalloc;
439 char *out, *outpos;
440 iconv_ibp cp;
441
443 - if (!in_encoding)
444 - return NULL;
445 - conv = iconv_open(out_encoding, in_encoding);
446 - if (conv == (iconv_t) -1)
447 - return NULL;
448 - insz = strlen(in);
442 outsz = insz;
443 outalloc = outsz + 1; /* for terminating NUL */
444 out = xmalloc(outalloc);
@@ -459,7 +452,6 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
452 size_t sofar;
453 if (errno != E2BIG) {
454 free(out);
462 - iconv_close(conv);
455 return NULL;
456 }
457 /* insz has remaining number of bytes.
@@ -478,6 +470,20 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
470 break;
471 }
472 }
473 + return out;
474 +}
475 +
476 +char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding)
477 +{
478 + iconv_t conv;
479 + char *out;
480 +
481 + if (!in_encoding)
482 + return NULL;
483 + conv = iconv_open(out_encoding, in_encoding);
484 + if (conv == (iconv_t) -1)
485 + return NULL;
486 + out = reencode_string_iconv(in, strlen(in), conv);
487 iconv_close(conv);
488 return out;
489 }
utf8.h
+1
@@ -14,6 +14,7 @@ int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
14 int indent, int indent2, int width);
15
16 #ifndef NO_ICONV
17 +char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv);
18 char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);
19 #else
20 #define reencode_string(a,b,c) NULL