2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
27 $Date: 2010/11/08 10:11:19 $
32 /*#include <sys/stat.h>
44 #include <sys/types.h>
48 #include <sysutils.hpp>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
54 #include <sys/socket.h>
58 #include <sys/types.h>
64 #include <sys/socket.h>
65 #include <netinet/in.h>
66 #include <arpa/inet.h>
80 #ifndef INET_ADDRSTRLEN
81 # define INET_ADDRSTRLEN 16
87 //-----------------------------------------------------------------------------
88 const char * inet_ntop(int af, const void * src, char * dst, unsigned long length)
90 struct sockaddr_in addr;
93 memcpy(&addr.sin_addr.s_addr, src, sizeof(addr.sin_addr.s_addr));
94 if (WSAAddressToStringA(reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr), 0, dst, &length))
100 //-----------------------------------------------------------------------------
101 int inet_pton(int af, const char * src, void * dst)
103 // Fuck you Microsoft!
104 // Why the hell not to use const char *?
105 size_t slen = strlen(src);
106 char * buf = new char[slen + 1];
107 strncpy(buf, src, slen + 1);
109 struct sockaddr_in addr;
110 addr.sin_family = af;
112 addr.sin_addr.s_addr = 0;
113 int length = sizeof(addr);
114 if (WSAStringToAddressA(buf, af, 0, reinterpret_cast<struct sockaddr *>(&addr), &length))
119 memcpy(dst, &addr, sizeof(addr));
124 //-----------------------------------------------------------------------------
125 int strtodouble2(const char * s, double &a)
136 //-----------------------------------------------------------------------------
138 int printfd(const char * __file__, const char * fmt, ...)
140 int printfd(const char *, const char *, ...)
146 time_t t = time(NULL);
150 vsnprintf(buff, sizeof(buff), fmt, vl);
153 printf("%18s > %s > ", __file__, LogDate(t)+11);
159 //-----------------------------------------------------------------------------
160 int strprintf(string * str, const char * fmt, ...)
166 int n = vsnprintf(buff, sizeof(buff), fmt, vl);
173 //-----------------------------------------------------------------------------
174 const char *IntToKMG(long long a, int stat)
176 static int64_t M = 1024*1024;
177 static int64_t G = 1024*1024*1024;
184 sprintf(str, "%Ld", a);
186 sprintf(str, "%lld", a);
190 sprintf(str, "%.2f kb", double(a)/1024.0);
193 sprintf(str, "%.2f Mb", double(a)/(1024.0*1024.0));
198 sprintf(str, "%.2f Gb", double(a)/double(G));
203 sprintf(str, "%.2f Gb", double(a)/double(G));
208 sprintf(str, "%.2f Mb", double(a)/double(M));
213 sprintf(str, "%.2f Mb", double(a)/double(M));
217 sprintf(str, "%.2f kb", double(a)/1024.0);
222 //---------------------------------------------------------------------------
223 unsigned char koi2win[] = {
224 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
225 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
226 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
227 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
228 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
229 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
230 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
231 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
232 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
233 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
234 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
235 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
236 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
237 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
238 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
239 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
240 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
241 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
242 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
243 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
244 0xA0, 0xA1, 0xA2, 0xB8, 0xBA, 0xA5, 0xB3, 0xBF,
245 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xB4, 0xAE, 0xAF,
246 0xB0, 0xB1, 0xB2, 0xA8, 0xAA, 0xB5, 0xB2, 0xAF,
247 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xA5, 0xBE, 0xBF,
248 0xFE, 0xE0, 0xE1, 0xF6, 0xE4, 0xE5, 0xF4, 0xE3,
249 0xF5, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE,
250 0xEF, 0xFF, 0xF0, 0xF1, 0xF2, 0xF3, 0xE6, 0xE2,
251 0xFC, 0xFB, 0xE7, 0xF8, 0xFD, 0xF9, 0xF7, 0xFA,
252 0xDE, 0xC0, 0xC1, 0xD6, 0xC4, 0xC5, 0xD4, 0xC3,
253 0xD5, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE,
254 0xCF, 0xDF, 0xD0, 0xD1, 0xD2, 0xD3, 0xC6, 0xC2,
255 0xDC, 0xDB, 0xC7, 0xD8, 0xDD, 0xD9, 0xD7, 0xDA};
258 unsigned char win2koi[] = {
259 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
260 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
261 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
262 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
263 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
264 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
265 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
266 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
267 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
268 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
269 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
270 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
271 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
272 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
273 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
274 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
275 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
276 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
277 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
278 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
279 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xBD, 0xA6, 0xA7,
280 0xB3, 0xA9, 0xB4, 0xAB, 0xAC, 0xAD, 0xAE, 0xB7,
281 0xB0, 0xB1, 0xB6, 0xA6, 0xAD, 0xB5, 0xB6, 0xB7,
282 0xA3, 0xB9, 0xA4, 0xBB, 0xBC, 0xBD, 0xBE, 0xA7,
283 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
284 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
285 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
286 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
287 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
288 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
289 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
290 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1};
291 //---------------------------------------------------------------------------
292 void KOIToWin(const char * s1, char * s2, int l)
295 for (int j = 0; j < l; j++)
304 //---------------------------------------------------------------------------
305 void WinToKOI(const char * s1, char * s2, int l)
308 for (int j = 0; j < l; j++)
317 //---------------------------------------------------------------------------
318 void KOIToWin(const string & s1, string * s2)
320 s2->erase(s2->begin(), s2->end());
322 s2->reserve(s1.length());
323 for (int j = 0; j < (int)s1.length(); j++)
326 s2->push_back(koi2win[t]);
329 //---------------------------------------------------------------------------
330 void WinToKOI(const string & s1, string * s2)
332 s2->erase(s2->begin(), s2->end());
334 s2->reserve(s1.length());
335 for (int j = 0; j < (int)s1.length(); j++)
338 s2->push_back(win2koi[t]);
341 //---------------------------------------------------------------------------
342 void Encode12str(string & dst, const string & src)
344 dst.erase(dst.begin(), dst.end());
345 for (size_t i = 0; i < src.length(); i++)
347 dst.push_back('a' + (src[i] & 0x0f));
348 dst.push_back('a' + ((src[i] & 0xf0) >> 4));
351 //---------------------------------------------------------------------------
352 void Decode21str(std::string & dst, const std::string & src)
354 dst.erase(dst.begin(), dst.end());
355 for (size_t i = 0; i < src.length() / 2; i++)
357 char c1 = src[i * 2];
358 char c2 = src[i * 2 + 1];
363 dst.push_back(c1 + (c2 << 4));
366 //---------------------------------------------------------------------------
367 void Encode12(char * dst, const char * src, size_t srcLen)
369 for (size_t i = 0; i <= srcLen; i++)
374 dst[i * 2 + 1] = 'a';
377 char c1 = src[i] & 0x0f;
378 char c2 = (src[i] & 0xf0) >> 4;
388 //---------------------------------------------------------------------------
389 void Decode21(char * dst, const char * src)
391 for (size_t i = 0; ; i++)
396 char c1 = src[i * 2];
397 char c2 = src[i * 2 + 1];
402 dst[i] = c1 + (c2 << 4);
404 dst[strlen(src) / 2] = 0;
406 //---------------------------------------------------------------------------
407 int ParseIPString(const char * str, uint32_t * ips, int maxIP)
410 *Function Name:ParseIPString
413 ÓÔÒÏËÁ ÄÌÑ ÒÁÚÂÏÒÁ É ÍÁÓÓÉ× ËÕÄÁ ÚÁÎÏÓÉÔØ ÐÏÌÕÞÅÎÎÙÅ ÁÄÒÅÓÁ
416 îÁ ×ÈÏÄÅ ÄÏÌÖÎÁ ÂÙÔØ ÓÔÒÏËÁ ×ÉÄÁ "ip1,ip2,ip3" ÉÌÉ "*"
417 ÷ ÐÅÒ×ÏÍ ÓÌÕÞÁÅ × ÍÁÓÓÉ× ÚÁÎÏÓÑÔÓÑ ÒÁÚÏÂÒÁÎÎÙÅ ÁÄÒÅÓÁ.
418 åÓÌÉ ÉÈ ÍÅÎØÛÅ MAX_IP?, ÔÏ ÐÏÓÌÅÄÎÉÊ ÁÄÒÅÓ ÂÕÄÅÔ 255.255.255.255
419 åÓÌÉ ÓÔÒÏËÁ * , ÔÏ ÐÅÒ×ÁÙÊ ÁÄÒÅÓ ÂÕÄÅÔ 0.0.0.0, Ô.Å. ÌÀÂÏÊ
421 *Returns: 0 ÅÓÌÉ ×ÓÅ ïë
429 strncpy(p, str, 254);
432 memset(ips, 0xFF, sizeof(unsigned long) * maxIP);
434 if (str[0] == '*' && strlen(str) == 1)
440 for (int i = 0; i < maxIP; i++)
442 p1 = strtok(pp, ",\n ");
445 if (p1 == NULL && n == 0)// ÕËÁÚÁÔÅÌØ ÎÕÌØ É ÐÒÏÞÉÔÁÎÏ ÁÄÒÅÓÏ× ÔÏÖÅ ÎÏÌØ
456 if (inet_pton(AF_INET, p1, &in) != 1)
458 //printf("INADDR_NONE\n");
464 /*if (ips[n] == INADDR_NONE)
476 //-----------------------------------------------------------------------------
477 int DaysInCurrentMonth()
479 time_t t = time(NULL);
481 struct tm * lt = localtime(&t);
483 return DaysInMonth(lt->tm_year, lt->tm_mon);
485 //-----------------------------------------------------------------------------
486 int DaysInMonth(unsigned year, unsigned mon)
488 assert(mon < 12 && "Month number should be 0 - 11");
491 case 0: return 31; //jan
493 if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
496 case 2: return 31; //mar
497 case 3: return 30; //apr
498 case 4: return 31; //may
499 case 5: return 30; //june
500 case 6: return 31; //jule
501 case 7: return 31; //aug
502 case 8: return 30; //sep
503 case 9: return 31; //oct
504 case 10: return 30; //nov
505 case 11: return 31; //dec
507 return -1; // We will never reach here
509 //-----------------------------------------------------------------------------
513 æÕÎËÃÉÑ ×ÏÚ×ÒÁÝÁÅÔ ÎÁÉÍÅÎØÛÅÅ ÞÉÓÌÏ ËÒÁÔÎÏÅ 8-ÍÉ ÂÏÌØÛÅÅ ÉÌÉ ÒÁ×ÎÏÅ ÚÁÄÁÎÎÏÍÕ
518 return a + (8 - a % 8);
520 //-----------------------------------------------------------------------------
521 /*char * inet_ntostr(unsigned long ip)
523 struct in_addr addr = {ip};
524 return inet_ntoa(addr);
526 //-----------------------------------------------------------------------------
527 std::string inet_ntostring(uint32_t ip)
529 char buf[INET_ADDRSTRLEN + 1];
530 return inet_ntop(AF_INET, &ip, buf, INET_ADDRSTRLEN);
532 //-----------------------------------------------------------------------------
533 uint32_t inet_strington(const std::string & value)
537 if (inet_pton(AF_INET, value.c_str(), &result) <= 0)
542 //-----------------------------------------------------------------------------
543 int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2)
545 char hs1[10], ms1[10], hs2[10], ms2[10];
550 strncpy(ss, str, 48);
552 p1 = strtok(ss, "-");
558 p2 = strtok(NULL, "-");
564 p1 = strtok(s1, ":");
570 p2 = strtok(NULL, ":");
576 p1 = strtok(s2, ":");
582 p2 = strtok(NULL, ":");
588 if (str2x(hs1, h1) != 0)
591 if (str2x(ms1, m1) != 0)
594 if (str2x(hs2, h2) != 0)
597 if (str2x(ms2, m2) != 0)
602 /*//---------------------------------------------------------------------------
605 if (c >= '0' && c <= '9')
609 //-----------------------------------------------------------------------------
612 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
616 //-----------------------------------------------------------------------------
617 const char * LogDate(time_t t)
620 struct tm * tt = localtime(&t);
622 snprintf(s, 20, "%d-%s%d-%s%d %s%d:%s%d:%s%d",
624 tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1,
625 tt->tm_mday < 10 ? "0" : "", tt->tm_mday,
626 tt->tm_hour < 10 ? "0" : "", tt->tm_hour,
627 tt->tm_min < 10 ? "0" : "", tt->tm_min,
628 tt->tm_sec < 10 ? "0" : "", tt->tm_sec);
632 //-----------------------------------------------------------------------------
633 uint32_t CalcMask(uint32_t msk)
635 if (msk >= 32) return 0xFFffFFff;
636 if (msk == 0) return 0;
637 return htonl(0xFFffFFff << (32 - msk));
639 //---------------------------------------------------------------------------
640 void TouchFile(const string & fileName)
642 FILE * f = fopen(fileName.c_str(), "w");
646 //---------------------------------------------------------------------------
648 void EncodeStr(char * str, unsigned long serial, int useHDD)
650 int len = strlen(str);
654 char serial_c[sizeof(serial)];
655 memcpy(serial_c, &serial, sizeof(serial));
657 for (i = 0; i < len; i++)
663 str[i] = str[i]^serial_c[j%sizeof(serial)];
668 for (i = 0; i < 2*len; i++)
672 c1 = (str[i/2] >> 4);
678 c2 = (str[i/2] & 0x0f);
686 //---------------------------------------------------------------------------
687 void DecodeStr(char * str, unsigned long serial, int useHDD)
689 int len = strlen(str);
693 char serial_c[sizeof(serial)];
694 memcpy(serial_c, &serial, sizeof(serial));
696 for (i = 0; i < len; i += 2)
699 c2 = (str[i+1] - 50)<<4;
702 for (i = 0; i < len/2; i++)
705 strdc[i] = strdc[i]^49;
708 strdc[i] = strdc[i]^serial_c[j%sizeof(serial)];
715 //---------------------------------------------------------------------------
717 void SwapBytes(uint16_t & value)
719 value = (value >> 8) |
722 //---------------------------------------------------------------------------
723 void SwapBytes(uint32_t & value)
725 value = (value >> 24) |
726 ((value << 8) & 0x00FF0000L)|
727 ((value >> 8) & 0x0000FF00L)|
730 //---------------------------------------------------------------------------
731 void SwapBytes(uint64_t & value)
733 value = (value >> 56) |
734 ((value << 40) & 0x00FF000000000000LL) |
735 ((value << 24) & 0x0000FF0000000000LL) |
736 ((value << 8) & 0x000000FF00000000LL) |
737 ((value >> 8) & 0x00000000FF000000LL) |
738 ((value >> 24) & 0x0000000000FF0000LL) |
739 ((value >> 40) & 0x000000000000FF00LL) |
742 //---------------------------------------------------------------------------
743 void SwapBytes(int16_t & value)
745 uint16_t temp = value;
749 //---------------------------------------------------------------------------
750 void SwapBytes(int32_t & value)
752 uint32_t temp = value;
756 //---------------------------------------------------------------------------
757 void SwapBytes(int64_t & value)
759 uint64_t temp = value;
763 //---------------------------------------------------------------------------
764 int str2x(const std::string & str, int & x)
766 x = strtol(str.c_str(), NULL, 10);
773 //---------------------------------------------------------------------------
774 int str2x(const std::string & str, unsigned & x)
776 x = strtoul(str.c_str(), NULL, 10);
783 //---------------------------------------------------------------------------
784 int str2x(const std::string & str, long & x)
786 x = strtol(str.c_str(), NULL, 10);
793 //---------------------------------------------------------------------------
794 int str2x(const std::string & str, unsigned long & x)
796 x = strtoul(str.c_str(), NULL, 10);
804 //---------------------------------------------------------------------------
805 int str2x(const std::string & str, long long & x)
807 x = strtoll(str.c_str(), NULL, 10);
814 //---------------------------------------------------------------------------
815 int str2x(const std::string & str, unsigned long long & x)
817 x = strtoull(str.c_str(), NULL, 10);
825 //---------------------------------------------------------------------------
826 const std::string & x2str(unsigned x, std::string & s)
828 return unsigned2str(x, s);
830 //---------------------------------------------------------------------------
831 const std::string & x2str(unsigned long x, std::string & s)
833 return unsigned2str(x, s);
835 //---------------------------------------------------------------------------
836 const std::string & x2str(unsigned long long x, std::string & s)
838 return unsigned2str(x, s);
840 //---------------------------------------------------------------------------
841 std::string & TrimL(std::string & val)
843 size_t pos = val.find_first_not_of(" \t");
844 if (pos == std::string::npos)
846 val.erase(val.begin(), val.end());
854 //---------------------------------------------------------------------------
855 std::string & TrimR(std::string & val)
857 size_t pos = val.find_last_not_of(" \t");
858 if (pos != std::string::npos)
864 //---------------------------------------------------------------------------
865 std::string & Trim(std::string & val)
867 return TrimR(TrimL(val));
869 //---------------------------------------------------------------------------
871 static int is_leap(unsigned y)
874 return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0);
877 //---------------------------------------------------------------------------
879 time_t stg_timegm(struct tm * brokenTime)
882 static const unsigned ndays[2][12] ={
883 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
884 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
886 for (int i = 70; i < brokenTime->tm_year; ++i)
887 res += is_leap(i) ? 366 : 365;
888 for (int i = 0; i < brokenTime->tm_mon; ++i)
889 res += ndays[is_leap(brokenTime->tm_year)][i];
890 res += brokenTime->tm_mday - 1;
892 res += brokenTime->tm_hour;
894 res += brokenTime->tm_min;
896 res += brokenTime->tm_sec;
900 return timegm(brokenTime);
907 ret = mktime(brokenTime);
914 #endif // HAVE_TIMEGM
917 //---------------------------------------------------------------------------
918 std::string IconvString(const std::string & source,
919 const std::string & from,
920 const std::string & to)
923 return std::string();
925 size_t inBytesLeft = source.length() + 1;
926 size_t outBytesLeft = source.length() * 2 + 1;
928 char * inBuf = new char[inBytesLeft];
929 char * outBuf = new char[outBytesLeft];
931 strncpy(inBuf, source.c_str(), source.length());
933 inBuf[source.length()] = 0;
935 #if defined(FREE_BSD) || defined(FREE_BSD5) || defined(WIN32)
936 const char * srcPos = inBuf;
938 char * srcPos = inBuf;
940 char * dstPos = outBuf;
942 iconv_t handle = iconv_open(to.c_str(),
945 if (handle == iconv_t(-1))
949 printfd(__FILE__, "IconvString(): iconv from %s to %s failed\n", from.c_str(), to.c_str());
955 printfd(__FILE__, "IconvString(): iconv_open error\n");
962 size_t res = iconv(handle,
963 &srcPos, &inBytesLeft,
964 &dstPos, &outBytesLeft);
966 if (res == size_t(-1))
968 printfd(__FILE__, "IconvString(): '%s'\n", strerror(errno));
978 std::string dst(outBuf);
987 //---------------------------------------------------------------------------