Back to index

glibc  2.9
Defines | Enumerations | Functions | Variables
tst-loading.c File Reference
#include <iconv.h>
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define TEST_ROUNDS   5000
#define MODULE(Name)   { .name = #Name, .state = unloaded }
#define nmodules   (sizeof (modules) / sizeof (modules[0]))

Enumerations

enum  state { unloaded, loaded }

Functions

int main (void)

Variables

struct {
const char * name
modules []
static const char inbuf [] = " function. Later modifications of the variable have no effect.\n"

Define Documentation

#define MODULE (   Name)    { .name = #Name, .state = unloaded }
#define nmodules   (sizeof (modules) / sizeof (modules[0]))

Definition at line 58 of file tst-loading.c.

#define TEST_ROUNDS   5000

Definition at line 28 of file tst-loading.c.


Enumeration Type Documentation

enum state
Enumerator:
unloaded 
loaded 

Definition at line 31 of file tst-loading.c.


Function Documentation

int main ( void  )

Definition at line 119 of file tst-loading.c.

{
  size_t count = TEST_ROUNDS;
  int result = 0;

  mtrace ();

  /* Just a seed.  */
  srandom (TEST_ROUNDS);

  while (count--)
    {
      int idx = random () % nmodules;

      if (modules[idx].state == unloaded)
       {
         char outbuf[10000];
         char *inptr = (char *) inbuf;
         size_t insize = sizeof (inbuf) - 1;
         char *outptr = outbuf;
         size_t outsize = sizeof (outbuf);

         /* Load the module and do the conversion.  */
         modules[idx].cd = iconv_open ("UTF-8", modules[idx].name);

         if (modules[idx].cd == (iconv_t) -1)
           {
             printf ("opening of %s failed: %m\n", modules[idx].name);
             result = 1;
             break;
           }

         modules[idx].state = loaded;

         /* Now a simple test.  */
         if (iconv (modules[idx].cd, &inptr, &insize, &outptr, &outsize) != 0
             || *inptr != '\0')
           {
             printf ("conversion with %s failed\n", modules[idx].name);
             result = 1;
           }
       }
      else
       {
         /* Unload the module.  */
         if (iconv_close (modules[idx].cd) != 0)
           {
             printf ("closing of %s failed: %m\n", modules[idx].name);
             result = 1;
             break;
           }

         modules[idx].state = unloaded;
       }
    }

  for (count = 0; count < nmodules; ++count)
    if (modules[count].state == loaded && iconv_close (modules[count].cd) != 0)
      {
       printf ("closing of %s failed: %m\n", modules[count].name);
       result = 1;
      }

  return result;
}

Here is the call graph for this function:


Variable Documentation

const char inbuf[] = " function. Later modifications of the variable have no effect.\n" [static]

Definition at line 62 of file tst-loading.c.

struct { ... } modules[]