1 /* Tests for loading and unloading of iconv modules.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 /* How many load/unload operations do we do. */
27 #define TEST_ROUNDS 5000
30 enum state
{ unloaded
, loaded
};
39 #define MODULE(Name) { .name = #Name, .state = unloaded }
57 #define nmodules (sizeof (modules) / sizeof (modules[0]))
61 static const char inbuf
[] =
62 "The first step is the function to create a handle.\n"
64 " - Function: iconv_t iconv_open (const char *TOCODE, const char\n"
66 " The `iconv_open' function has to be used before starting a\n"
67 " conversion. The two parameters this function takes determine the\n"
68 " source and destination character set for the conversion and if the\n"
69 " implementation has the possibility to perform such a conversion the\n"
70 " function returns a handle.\n"
72 " If the wanted conversion is not available the function returns\n"
73 " `(iconv_t) -1'. In this case the global variable `errno' can have\n"
74 " the following values:\n"
77 " The process already has `OPEN_MAX' file descriptors open.\n"
80 " The system limit of open file is reached.\n"
83 " Not enough memory to carry out the operation.\n"
86 " The conversion from FROMCODE to TOCODE is not supported.\n"
88 " It is not possible to use the same descriptor in different threads\n"
89 " to perform independent conversions. Within the data structures\n"
90 " associated with the descriptor there is information about the\n"
91 " conversion state. This must not be messed up by using it in\n"
92 " different conversions.\n"
94 " An `iconv' descriptor is like a file descriptor as for every use a\n"
95 " new descriptor must be created. The descriptor does not stand for\n"
96 " all of the conversions from FROMSET to TOSET.\n"
98 " The GNU C library implementation of `iconv_open' has one\n"
99 " significant extension to other implementations. To ease the\n"
100 " extension of the set of available conversions the implementation\n"
101 " allows storing the necessary files with data and code in\n"
102 " arbitrarily many directories. How this extension has to be\n"
103 " written will be explained below (*note glibc iconv\n"
104 " Implementation::). Here it is only important to say that all\n"
105 " directories mentioned in the `GCONV_PATH' environment variable are\n"
106 " considered if they contain a file `gconv-modules'. These\n"
107 " directories need not necessarily be created by the system\n"
108 " administrator. In fact, this extension is introduced to help users\n"
109 " writing and using their own, new conversions. Of course this does\n"
110 " not work for security reasons in SUID binaries; in this case only\n"
111 " the system directory is considered and this normally is\n"
112 " `PREFIX/lib/gconv'. The `GCONV_PATH' environment variable is\n"
113 " examined exactly once at the first call of the `iconv_open'\n"
114 " function. Later modifications of the variable have no effect.\n";
120 size_t count
= TEST_ROUNDS
;
126 srandom (TEST_ROUNDS
);
130 int idx
= random () % nmodules
;
132 if (modules
[idx
].state
== unloaded
)
135 char *inptr
= (char *) inbuf
;
136 size_t insize
= sizeof (inbuf
) - 1;
137 char *outptr
= outbuf
;
138 size_t outsize
= sizeof (outbuf
);
140 /* Load the module and do the conversion. */
141 modules
[idx
].cd
= iconv_open ("UTF-8", modules
[idx
].name
);
143 if (modules
[idx
].cd
== (iconv_t
) -1)
145 printf ("opening of %s failed: %m\n", modules
[idx
].name
);
150 modules
[idx
].state
= loaded
;
152 /* Now a simple test. */
153 if (iconv (modules
[idx
].cd
, &inptr
, &insize
, &outptr
, &outsize
) != 0
156 printf ("conversion with %s failed\n", modules
[idx
].name
);
162 /* Unload the module. */
163 if (iconv_close (modules
[idx
].cd
) != 0)
165 printf ("closing of %s failed: %m\n", modules
[idx
].name
);
170 modules
[idx
].state
= unloaded
;
174 for (count
= 0; count
< nmodules
; ++count
)
175 if (modules
[count
].state
== loaded
&& iconv_close (modules
[count
].cd
) != 0)
177 printf ("closing of %s failed: %m\n", modules
[count
].name
);