annotate lib/xstriconveh.h @ 18029:e4a13d95b503

mgetgroups: port to strict OS X * doc/glibc-functions/getgrouplist.texi (getgrouplist): Document the getgrouplist problem. * lib/mgetgroups.c (getgrouplist_gids) [HAVE_GETGROUPLIST]: New macro. (mgetgroups): Use it. * m4/mgetgroups.m4 (gl_MGETGROUPS): Check for OS X signature for getgrouplist.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 28 Jun 2015 23:43:35 -0700
parents ab58d4870664
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Charset conversion with out-of-memory checking.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2001-2007, 2009-2015 Free Software Foundation, Inc.
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible and Simon Josefsson.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #ifndef _XSTRICONVEH_H
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #define _XSTRICONVEH_H
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stddef.h>
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Get the 'enum iconv_ilseq_handler' and iconveh_t types, and the
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 iconveh_open, iconveh_close declarations. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "striconveh.h"
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #ifdef __cplusplus
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 extern "C" {
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #endif
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #if HAVE_ICONV
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 /* Convert an entire string from one encoding to another, using iconv.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 The original string is at [SRC,...,SRC+SRCLEN-1].
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 CD points to the conversion descriptor from FROMCODE to TOCODE, created by
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 the function iconveh_open().
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 array is filled with offsets into the result, i.e. the character starting
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 and other offsets are set to (size_t)(-1).
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 or *RESULTP can initially be NULL.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 May erase the contents of the memory at *RESULTP.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 Upon memory allocation failure, report the error and exit.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 Return value: 0 if successful, otherwise -1 and errno set.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 If successful: The resulting string is stored in *RESULTP and its length
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 unchanged if no dynamic memory allocation was necessary. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 extern int
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 xmem_cd_iconveh (const char *src, size_t srclen,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
53 const iconveh_t *cd,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
54 enum iconv_ilseq_handler handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
55 size_t *offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
56 char **resultp, size_t *lengthp);
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 /* Convert an entire string from one encoding to another, using iconv.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 The original string is the NUL-terminated string starting at SRC.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 CD points to the conversion descriptor from FROMCODE to TOCODE, created by
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 the function iconveh_open().
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 Both the "from" and the "to" encoding must use a single NUL byte at the end
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 Allocate a malloced memory block for the result.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 Upon memory allocation failure, report the error and exit.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 Return value: the freshly allocated resulting NUL-terminated string if
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 successful, otherwise NULL and errno set. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 extern char *
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 xstr_cd_iconveh (const char *src,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
70 const iconveh_t *cd,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
71 enum iconv_ilseq_handler handler);
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 #endif
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 /* Convert an entire string from one encoding to another, using iconv.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 The original string is at [SRC,...,SRC+SRCLEN-1].
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 array is filled with offsets into the result, i.e. the character starting
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 and other offsets are set to (size_t)(-1).
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 or *RESULTP can initially be NULL.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 May erase the contents of the memory at *RESULTP.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 Upon memory allocation failure, report the error and exit.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 Return value: 0 if successful, otherwise -1 and errno set.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 If successful: The resulting string is stored in *RESULTP and its length
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 unchanged if no dynamic memory allocation was necessary. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 extern int
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 xmem_iconveh (const char *src, size_t srclen,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
91 const char *from_codeset, const char *to_codeset,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
92 enum iconv_ilseq_handler handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
93 size_t *offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
94 char **resultp, size_t *lengthp);
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 /* Convert an entire string from one encoding to another, using iconv.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 The original string is the NUL-terminated string starting at SRC.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 Both the "from" and the "to" encoding must use a single NUL byte at the
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 Allocate a malloced memory block for the result.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 Upon memory allocation failure, report the error and exit.
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 Return value: the freshly allocated resulting NUL-terminated string if
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 successful, otherwise NULL and errno set. */
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 extern char *
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 xstr_iconveh (const char *src,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
106 const char *from_codeset, const char *to_codeset,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11913
diff changeset
107 enum iconv_ilseq_handler handler);
11913
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 #ifdef __cplusplus
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 }
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 #endif
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
4d4630e8627a New module 'xstriconveh'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 #endif /* _XSTRICONVEH_H */