Back to index

glibc  2.9
Classes | Functions | Variables
tst-strtoll.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  ltest

Functions

static void expand (char *dst, int c)
int main (void)

Variables

static struct ltest []

Class Documentation

struct ltest

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

Class Members
int base
int err
unsigned long int expect
unsigned long long int expect
double expect
char left
const char * str

Function Documentation

static void expand ( char *  dst,
int  c 
) [static]

Definition at line 164 of file tst-strtoll.c.

{
  if (isprint (c))
    {
      dst[0] = c;
      dst[1] = '\0';
    }
  else
    (void) sprintf (dst, "%#.3o", (unsigned int) c);
}

Here is the caller graph for this function:

int main ( void  )

Definition at line 88 of file tst-strtoll.c.

{
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      register long long int l;

      errno = 0;
      l = strtoll (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoll(\"%s\", , %d) test %u",
             lt->str, lt->base, (unsigned int) (lt - tests));
      if (l == (long long int) lt->expect && *ep == lt->left
         && save_errno == lt->err)
       puts("\tOK");
      else
       {
         puts("\tBAD");
         if (l != (long long int) lt->expect)
           printf("  returns %lld, expected %lld\n",
                 l, (long long int) lt->expect);
         if (lt->left != *ep)
           {
             char exp1[5], exp2[5];
             expand (exp1, *ep);
             expand (exp2, lt->left);
             printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
           }
         if (save_errno != lt->err)
           printf ("  errno %d (%s)  instead of %d (%s)\n",
                  save_errno, strerror (save_errno),
                  lt->err, strerror (lt->err));
         status = 1;
       }
    }

  for (++lt; lt->str != NULL; lt++)
    {
      register unsigned long long int ul;

      errno = 0;
      ul = strtoull (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoull(\"%s\", , %d) test %u",
             lt->str, lt->base, (unsigned int) (lt - tests));
      if (ul == lt->expect && *ep == lt->left && save_errno == lt->err)
       puts("\tOK");
      else
       {
         puts ("\tBAD");
         if (ul != lt->expect)
           printf ("  returns %llu, expected %llu\n",
                  ul, lt->expect);
         if (lt->left != *ep)
           {
             char exp1[5], exp2[5];
             expand (exp1, *ep);
             expand (exp2, lt->left);
             printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
           }
         if (save_errno != lt->err)
           printf ("  errno %d (%s) instead of %d (%s)\n",
                  save_errno, strerror (save_errno),
                  lt->err, strerror (lt->err));
         status = 1;
       }
    }

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}

Here is the call graph for this function:


Variable Documentation

struct ltest[] [static]

Definition at line 19 of file tst-strtoll.c.