iconvenc.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000 by Marco van de Voort([email protected])
  4. member of the Free Pascal development team
  5. libiconv header translation + a helper routine
  6. http://wiki.freepascal.org/iconvenc
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright. (LGPL)
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. }
  13. {$IFNDEF FPC_DOTTEDUNITS}
  14. unit iconvenc;
  15. {$ENDIF FPC_DOTTEDUNITS}
  16. interface
  17. {$mode objfpc}{$H+}
  18. {$IFDEF FPC_DOTTEDUNITS}
  19. uses
  20. System.CTypes,UnixApi.Types,UnixApi.Base,
  21. System.InitC;
  22. {$ELSE FPC_DOTTEDUNITS}
  23. uses
  24. ctypes,unixtype,baseunix,
  25. initc;
  26. {$ENDIF FPC_DOTTEDUNITS}
  27. const
  28. n = 1;
  29. {$ifdef beos}
  30. ESysEILSEQ = EILSEQ;
  31. {$endif}
  32. type
  33. piconv_t = ^iconv_t;
  34. iconv_t = pointer;
  35. Ticonv_open = function(__tocode: PAnsiChar; __fromcode: PAnsiChar): iconv_t; cdecl;
  36. Ticonv = function(__cd: iconv_t; __inbuf: PPAnsiChar; __inbytesleft: psize_t; __outbuf: PPAnsiChar; __outbytesleft: psize_t): size_t; cdecl;
  37. Ticonv_close = function(__cd: iconv_t): cint; cdecl;
  38. {$if not defined(linux) and not defined(solaris)} // Linux (and maybe glibc pl
  39. {$if defined(haiku)}
  40. {$linklib textencoding}
  41. {$else}
  42. {$linklib iconv}
  43. {$endif}
  44. {$define useiconv}
  45. {$endif linux}
  46. Const
  47. {$ifndef useiconv}
  48. libiconvname='c'; // is in libc under Linux.
  49. {$else}
  50. {$ifdef haiku}
  51. libiconvname='textencoding'; // is in libtextencoding under Haiku
  52. {$else}
  53. libiconvname='iconv';
  54. {$endif}
  55. {$endif}
  56. {$if (defined(darwin) and defined(cpupowerpc32)) or defined(haiku)}
  57. iconvprefix='lib';
  58. {$else}
  59. iconvprefix='';
  60. {$endif}
  61. function iconv_open(__tocode: PAnsiChar; __fromcode: PAnsiChar): iconv_t; cdecl; external libiconvname name iconvprefix+'iconv_open';
  62. function iconv (__cd: iconv_t; __inbuf: PPAnsiChar; __inbytesleft: psize_t; __outbuf: PPAnsiChar; __outbytesleft: psize_t): size_t; cdecl; external libiconvname name iconvprefix+'iconv';
  63. function iconv_close (__cd: iconv_t): cint; cdecl; external libiconvname name iconvprefix+'iconv_close';
  64. var
  65. IconvLibFound: boolean = False;
  66. function Iconvert(s: AnsiString; var res: AnsiString; const FromEncoding, ToEncoding: AnsiString): cint;
  67. function InitIconv(var error: String): boolean;
  68. implementation
  69. function InitIconv(var error:String ): boolean;
  70. begin
  71. result := true;
  72. iconvlibfound := iconvlibfound or result;
  73. end;
  74. {$i iconvert.inc}
  75. end.