Back to index

glibc  2.9
Defines | Functions | Variables
tstdiomisc.c File Reference
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>

Go to the source code of this file.

Defines

#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL)

Functions

static int t1 (void)
static int t2 (void)
static int F (void)
int main (int argc, char *argv[])

Variables

volatile double nanval

Define Documentation

#define SCAN (   INPUT,
  FORMAT,
  VAR,
  EXP_RES,
  EXP_VAL 
)
Value:
VAR = -1; \
  retval = sscanf (INPUT, FORMAT, &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
         INPUT, FORMAT, retval, (long int) VAR); \
  result |= retval != EXP_RES || VAR != EXP_VAL

Function Documentation

static int F ( void  ) [static]

Definition at line 53 of file tstdiomisc.c.

{
  char buf[20];
  wchar_t wbuf[10];
  int result;

  nanval = NAN;

  snprintf (buf, sizeof buf, "%f %F", nanval, nanval);
  result = strcmp (buf, "nan NAN") != 0;
  printf ("expected \"nan NAN\", got \"%s\"\n", buf);

  snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
  result |= strcmp (buf, "inf INF") != 0;
  printf ("expected \"inf INF\", got \"%s\"\n", buf);

  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", nanval, nanval);
  result |= wcscmp (wbuf, L"nan NAN") != 0;
  printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf);

  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F",
           DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
  result |= wcscmp (wbuf, L"inf INF") != 0;
  printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 82 of file tstdiomisc.c.

{
  int result = 0;

  result |= t1 ();
  result |= t2 ();
  result |= F ();

  result |= fflush (stdout) == EOF;

  return result;
}

Here is the call graph for this function:

static int t1 ( void  ) [static]

Definition at line 8 of file tstdiomisc.c.

{
  int n = -1;
  sscanf ("abc  ", "abc %n", &n);
  printf ("t1: count=%d\n", n);

  return n != 5;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int t2 ( void  ) [static]

Definition at line 18 of file tstdiomisc.c.

{
  int result = 0;
  int n;
  long N;
  int retval;
#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
  VAR = -1; \
  retval = sscanf (INPUT, FORMAT, &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
         INPUT, FORMAT, retval, (long int) VAR); \
  result |= retval != EXP_RES || VAR != EXP_VAL

  SCAN ("12345", "%ld", N, 1, 12345);
  SCAN ("12345", "%llllld", N, 0, -1);
  SCAN ("12345", "%LLLLLd", N, 0, -1);
  SCAN ("test ", "%*s%n",  n, 0, 4);
  SCAN ("test ", "%2*s%n",  n, 0, -1);
  SCAN ("12 ",   "%l2d",  n, 0, -1);
  SCAN ("12 ",   "%2ld",  N, 1, 12);

  n = -1;
  N = -1;
  retval = sscanf ("1 1", "%d %Z", &n, &N);
  printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
         retval, n, N); \
  result |= retval != 1 || n != 1 || N != -1;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

volatile double nanval

Definition at line 49 of file tstdiomisc.c.