Mercurial > gnulib
annotate lib/striconveh.h @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
7882 | 1 /* Character set conversion with error handling. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2001-2007, 2009-2013 Free Software Foundation, Inc. |
7882 | 3 Written by Bruno Haible and Simon Josefsson. |
4 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8605
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
7882 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8605
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8605
diff
changeset
|
8 (at your option) any later version. |
7882 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8605
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7882 | 17 |
18 #ifndef _STRICONVEH_H | |
19 #define _STRICONVEH_H | |
20 | |
21 #include <stddef.h> | |
22 #if HAVE_ICONV | |
23 #include <iconv.h> | |
24 #endif | |
25 | |
11476
d053b39f7091
New include file "iconveh.h".
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
26 #include "iconveh.h" |
d053b39f7091
New include file "iconveh.h".
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
27 |
7882 | 28 |
29 #ifdef __cplusplus | |
30 extern "C" { | |
31 #endif | |
32 | |
33 | |
34 #if HAVE_ICONV | |
35 | |
13685 | 36 /* A conversion descriptor for use by the iconveh functions. */ |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
37 typedef struct |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
38 { |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
39 /* Conversion descriptor from FROM_CODESET to TO_CODESET, or (iconv_t)(-1) |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
40 if the system does not support a direct conversion from FROM_CODESET to |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
41 TO_CODESET. */ |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
42 iconv_t cd; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
43 /* Conversion descriptor from FROM_CODESET to UTF-8 (or (iconv_t)(-1) if |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
44 FROM_CODESET is UTF-8). */ |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
45 iconv_t cd1; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
46 /* Conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) if |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
47 TO_CODESET is UTF-8). */ |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
48 iconv_t cd2; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
49 } |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
50 iconveh_t; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
51 |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
52 /* Open a conversion descriptor for use by the iconveh functions. |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
53 If successful, fills *CDP and returns 0. Upon failure, return -1 with errno |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
54 set. */ |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
55 extern int |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
56 iconveh_open (const char *to_codeset, const char *from_codeset, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
57 iconveh_t *cdp); |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
58 |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
59 /* Close a conversion descriptor created by iconveh_open(). |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
60 Return value: 0 if successful, otherwise -1 and errno set. */ |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
61 extern int |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
62 iconveh_close (const iconveh_t *cd); |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
63 |
7882 | 64 /* Convert an entire string from one encoding to another, using iconv. |
65 The original string is at [SRC,...,SRC+SRCLEN-1]. | |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
66 CD points to the conversion descriptor from FROMCODE to TOCODE, created by |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
67 the function iconveh_open(). |
7928 | 68 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
69 array is filled with offsets into the result, i.e. the character starting |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
70 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
71 and other offsets are set to (size_t)(-1). |
7914
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
72 *RESULTP and *LENGTH should initially be a scratch buffer and its size, |
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
73 or *RESULTP can initially be NULL. |
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
74 May erase the contents of the memory at *RESULTP. |
7882 | 75 Return value: 0 if successful, otherwise -1 and errno set. |
7914
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
76 If successful: The resulting string is stored in *RESULTP and its length |
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
77 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is |
9862bb358a30
Change specification of mem_cd_iconveh.
Bruno Haible <bruno@clisp.org>
parents:
7882
diff
changeset
|
78 unchanged if no dynamic memory allocation was necessary. */ |
7882 | 79 extern int |
80 mem_cd_iconveh (const char *src, size_t srclen, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
81 const iconveh_t *cd, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
82 enum iconv_ilseq_handler handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
83 size_t *offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
84 char **resultp, size_t *lengthp); |
7882 | 85 |
86 /* Convert an entire string from one encoding to another, using iconv. | |
87 The original string is the NUL-terminated string starting at SRC. | |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
88 CD points to the conversion descriptor from FROMCODE to TOCODE, created by |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11476
diff
changeset
|
89 the function iconveh_open(). |
8605
414a0a3d5fac
Do an indirect conversion if iconv_open does not support a direct conversion.
Bruno Haible <bruno@clisp.org>
parents:
7928
diff
changeset
|
90 Both the "from" and the "to" encoding must use a single NUL byte at the end |
414a0a3d5fac
Do an indirect conversion if iconv_open does not support a direct conversion.
Bruno Haible <bruno@clisp.org>
parents:
7928
diff
changeset
|
91 of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32). |
7882 | 92 Allocate a malloced memory block for the result. |
93 Return value: the freshly allocated resulting NUL-terminated string if | |
94 successful, otherwise NULL and errno set. */ | |
95 extern char * | |
96 str_cd_iconveh (const char *src, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
97 const iconveh_t *cd, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
98 enum iconv_ilseq_handler handler); |
7882 | 99 |
100 #endif | |
101 | |
102 /* Convert an entire string from one encoding to another, using iconv. | |
7915 | 103 The original string is at [SRC,...,SRC+SRCLEN-1]. |
7928 | 104 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
105 array is filled with offsets into the result, i.e. the character starting |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
106 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7918
diff
changeset
|
107 and other offsets are set to (size_t)(-1). |
7915 | 108 *RESULTP and *LENGTH should initially be a scratch buffer and its size, |
109 or *RESULTP can initially be NULL. | |
110 May erase the contents of the memory at *RESULTP. | |
111 Return value: 0 if successful, otherwise -1 and errno set. | |
112 If successful: The resulting string is stored in *RESULTP and its length | |
113 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is | |
114 unchanged if no dynamic memory allocation was necessary. */ | |
115 extern int | |
116 mem_iconveh (const char *src, size_t srclen, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
117 const char *from_codeset, const char *to_codeset, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
118 enum iconv_ilseq_handler handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
119 size_t *offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
120 char **resultp, size_t *lengthp); |
7915 | 121 |
122 /* Convert an entire string from one encoding to another, using iconv. | |
7882 | 123 The original string is the NUL-terminated string starting at SRC. |
124 Both the "from" and the "to" encoding must use a single NUL byte at the | |
125 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32). | |
126 Allocate a malloced memory block for the result. | |
127 Return value: the freshly allocated resulting NUL-terminated string if | |
128 successful, otherwise NULL and errno set. */ | |
129 extern char * | |
130 str_iconveh (const char *src, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
131 const char *from_codeset, const char *to_codeset, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
132 enum iconv_ilseq_handler handler); |
7882 | 133 |
134 | |
135 #ifdef __cplusplus | |
136 } | |
137 #endif | |
138 | |
139 | |
140 #endif /* _STRICONVEH_H */ |