| 133 | } |
| 134 | |
| 135 | struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir) |
| 136 | { |
| 137 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 138 | struct dirent *res; |
| 139 | |
| 140 | res = readdir(prec_dir->dirp); |
| 141 | if (res) { |
| 142 | size_t namelenz = strlen(res->d_name) + 1; /* \0 */ |
| 143 | size_t new_maxlen = namelenz; |
| 144 | |
| 145 | int ret_errno = errno; |
| 146 | |
| 147 | if (new_maxlen > prec_dir->dirent_nfc->max_name_len) { |
| 148 | size_t new_len = sizeof(dirent_prec_psx) + new_maxlen - |
| 149 | sizeof(prec_dir->dirent_nfc->d_name); |
| 150 | |
| 151 | prec_dir->dirent_nfc = xrealloc(prec_dir->dirent_nfc, new_len); |
| 152 | prec_dir->dirent_nfc->max_name_len = new_maxlen; |
| 153 | } |
| 154 | |
| 155 | prec_dir->dirent_nfc->d_ino = res->d_ino; |
| 156 | prec_dir->dirent_nfc->d_type = res->d_type; |
| 157 | |
| 158 | if ((cfg->precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) { |
| 159 | if (prec_dir->ic_precompose == (iconv_t)-1) { |
| 160 | die("iconv_open(%s,%s) failed, but needed:\n" |
| 161 | " precomposed unicode is not supported.\n" |
| 162 | " If you want to use decomposed unicode, run\n" |
| 163 | " \"git config core.precomposeunicode false\"\n", |
| 164 | repo_encoding, path_encoding); |
| 165 | } else { |
| 166 | iconv_ibp cp = (iconv_ibp)res->d_name; |
| 167 | size_t inleft = namelenz; |
| 168 | char *outpos = &prec_dir->dirent_nfc->d_name[0]; |
| 169 | size_t outsz = prec_dir->dirent_nfc->max_name_len; |
| 170 | errno = 0; |
| 171 | iconv(prec_dir->ic_precompose, &cp, &inleft, &outpos, &outsz); |
| 172 | if (errno || inleft) { |
| 173 | /* |
| 174 | * iconv() failed and errno could be E2BIG, EILSEQ, EINVAL, EBADF |
| 175 | * MacOS X avoids illegal byte sequences. |
| 176 | * If they occur on a mounted drive (e.g. NFS) it is not worth to |
| 177 | * die() for that, but rather let the user see the original name |
| 178 | */ |
| 179 | namelenz = 0; /* trigger strlcpy */ |
| 180 | } |
| 181 | } |
| 182 | } else |
| 183 | namelenz = 0; |
| 184 | |
| 185 | if (!namelenz) |
| 186 | strlcpy(prec_dir->dirent_nfc->d_name, res->d_name, |
| 187 | prec_dir->dirent_nfc->max_name_len); |
| 188 | |
| 189 | errno = ret_errno; |
| 190 | return prec_dir->dirent_nfc; |
| 191 | } |
| 192 | return NULL; |
nothing calls this directly
no test coverage detected