Back to index

glibc  2.9
Defines | Functions
tst-xdrmem2.c File Reference
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <rpc/rpc.h>
#include <sys/mman.h>
#include <unistd.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define T(type, val)
#define T(type, val)
#define TEST_FUNCTION   do_test ()

Functions

static int do_test (void)

Define Documentation

#define T (   type,
  val 
)
Value:
v_##type = val;                    \
  if (! xdr_##type (&xdrs, &v_##type))    \
    {                              \
      puts ("encoding of " #type   \
           " " #val " failed");    \
      return 1;                           \
    }
#define T (   type,
  val 
)
Value:
v_##type = 0x15;                   \
  if (! xdr_##type (&xdrs, &v_##type))    \
    {                              \
      puts ("decoding of " #type   \
           " " #val " failed");    \
      return 1;                           \
    }                              \
  if (v_##type != val)                    \
    {                              \
      puts ("decoded value differs, "     \
           "type " #type " " #val);       \
      return 1;                           \
    }
#define TEST_FUNCTION   do_test ()

Definition at line 113 of file tst-xdrmem2.c.


Function Documentation

static int do_test ( void  ) [static]

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

{
  XDR xdrs;
  void *buf;
  size_t ps = sysconf (_SC_PAGESIZE);
  uintptr_t half = -1;
  int v_int;
  u_short v_u_short;

  half = (half >> 1) & ~(uintptr_t) (ps - 1);
  buf = mmap ((void *) half, 2 * ps, PROT_READ | PROT_WRITE,
             MAP_PRIVATE | MAP_ANON, -1, 0);
  if (buf == MAP_FAILED || buf != (void *) half)
    {
      puts ("Couldn't mmap 2 pages in the middle of address space");
      return 0;
    }

  xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_ENCODE);

#define T(type, val) \
  v_##type = val;                  \
  if (! xdr_##type (&xdrs, &v_##type))    \
    {                              \
      puts ("encoding of " #type   \
           " " #val " failed");    \
      return 1;                           \
    }

  T(int, 127)

  u_int pos = xdr_getpos (&xdrs);

  T(u_short, 31)

  if (! xdr_setpos (&xdrs, pos))
    {
      puts ("xdr_setpos during encoding failed");
      return 1;
    }

  T(u_short, 36)

#undef T

  xdr_destroy (&xdrs);

  xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_DECODE);

#define T(type, val) \
  v_##type = 0x15;                 \
  if (! xdr_##type (&xdrs, &v_##type))    \
    {                              \
      puts ("decoding of " #type   \
           " " #val " failed");    \
      return 1;                           \
    }                              \
  if (v_##type != val)                    \
    {                              \
      puts ("decoded value differs, "     \
           "type " #type " " #val);       \
      return 1;                           \
    }

  T(int, 127)

  pos = xdr_getpos (&xdrs);

  T(u_short, 36)

  if (! xdr_setpos (&xdrs, pos))
    {
      puts ("xdr_setpos during encoding failed");
      return 1;
    }

  T(u_short, 36)

#undef T

  xdr_destroy (&xdrs);

  return 0;
}

Here is the call graph for this function: