Lines 7-13
Link Here
|
7 |
#include <stdlib.h> |
7 |
#include <stdlib.h> |
8 |
#include <string.h> |
8 |
#include <string.h> |
9 |
#include <ctype.h> |
9 |
#include <ctype.h> |
10 |
#include <iconv.h> |
|
|
11 |
#include "git-compat-util.h" |
10 |
#include "git-compat-util.h" |
12 |
#include "cache.h" |
11 |
#include "cache.h" |
13 |
|
12 |
|
Lines 439-474
Link Here
|
439 |
|
438 |
|
440 |
static void convert_to_utf8(char *line, char *charset) |
439 |
static void convert_to_utf8(char *line, char *charset) |
441 |
{ |
440 |
{ |
442 |
char *in, *out; |
441 |
char * *out; |
443 |
size_t insize, outsize, nrc; |
|
|
444 |
char outbuf[4096]; /* cheat */ |
442 |
char outbuf[4096]; /* cheat */ |
445 |
static char latin_one[] = "latin-1"; |
443 |
|
446 |
char *input_charset = *charset ? charset : latin_one; |
|
|
447 |
iconv_t conv = iconv_open(metainfo_charset, input_charset); |
448 |
|
449 |
if (conv == (iconv_t) -1) { |
450 |
static int warned_latin1_once = 0; |
451 |
if (input_charset != latin_one) { |
452 |
fprintf(stderr, "cannot convert from %s to %s\n", |
453 |
input_charset, metainfo_charset); |
454 |
*charset = 0; |
455 |
} |
456 |
else if (!warned_latin1_once) { |
457 |
warned_latin1_once = 1; |
458 |
fprintf(stderr, "tried to convert from %s to %s, " |
459 |
"but your iconv does not work with it.\n", |
460 |
input_charset, metainfo_charset); |
461 |
} |
462 |
return; |
463 |
} |
464 |
in = line; |
465 |
insize = strlen(in); |
466 |
out = outbuf; |
467 |
outsize = sizeof(outbuf); |
468 |
nrc = iconv(conv, &in, &insize, &out, &outsize); |
469 |
iconv_close(conv); |
470 |
if (nrc == (size_t) -1) |
471 |
return; |
472 |
*out = 0; |
444 |
*out = 0; |
473 |
strcpy(line, outbuf); |
445 |
strcpy(line, outbuf); |
474 |
} |
446 |
} |