Back to index

glibc  2.9
tst-catgets.c
Go to the documentation of this file.
00001 #include <mcheck.h>
00002 #include <nl_types.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 
00007 static const char *msgs[] =
00008 {
00009 #define INPUT(str)
00010 #define OUTPUT(str) str,
00011 #include <intl/msgs.h>
00012 };
00013 #define nmsgs (sizeof (msgs) / sizeof (msgs[0]))
00014 
00015 #define ROUNDS 5
00016 
00017 int
00018 main (void)
00019 {
00020   int rnd;
00021   int result = 0;
00022 
00023   mtrace ();
00024 
00025   /* We do this a few times to stress the memory handling.  */
00026   for (rnd = 0; rnd < ROUNDS; ++rnd)
00027     {
00028       nl_catd cd = catopen ("libc", 0);
00029       size_t cnt;
00030 
00031       if (cd == (nl_catd) -1)
00032        {
00033          printf ("cannot load catalog: %m\n");
00034          result = 1;
00035          break;
00036        }
00037 
00038       /* Go through all the messages and compare the result.  */
00039       for (cnt = 0; cnt < nmsgs; ++cnt)
00040        {
00041          char *trans;
00042 
00043          trans = catgets (cd, 1, 1 + cnt,
00044                         "+#+# if this comes backs it's an error");
00045 
00046          if (trans == NULL)
00047            {
00048              printf ("catgets return NULL for %zd\n", cnt);
00049              result = 1;
00050            }
00051          else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0')
00052            {
00053              printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans);
00054              result = 1;
00055            }
00056        }
00057 
00058       if (catclose (cd) != 0)
00059        {
00060          printf ("catclose failed: %m\n");
00061          result = 1;
00062        }
00063     }
00064 
00065   return result;
00066 }