Путь: Toys/POSIX, команды версии: Ver.4 Ver.9 iconv Комментарии в файле iconv.c :
Исходный текст в файле iconv.c #define FOR_iconv #include "toys.h" #include <iconv.h> GLOBALS( char *f, *t; void *ic; ) static void do_iconv(int fd, char *name) { char *outstart = toybuf+2048; size_t outlen, inlen = 0; int readlen = 1; for (;;) { char *in = toybuf, *out = outstart; if (readlen && 0>(readlen = read(fd, in+inlen, 2048-inlen))) { perror_msg("read '%s'", name); return; } inlen += readlen; if (!inlen) break; outlen = 2048; iconv(TT.ic, &in, &inlen, &out, &outlen); if (in == toybuf) { // Skip first byte of illegal sequence to avoid endless loops if (toys.optflags & FLAG_c) in++; else *(out++) = *(in++); inlen--; } if (out != outstart) xwrite(1, outstart, out-outstart); memmove(toybuf, in, inlen); } } void iconv_main(void) { if (!TT.t) TT.t = "UTF-8"; if (!TT.f) TT.f = "UTF-8"; if ((iconv_t)-1 == (TT.ic = iconv_open(TT.t, TT.f))) perror_exit("%s/%s", TT.t, TT.f); loopfiles(toys.optargs, do_iconv); if (CFG_TOYBOX_FREE) iconv_close(TT.ic); } |