/* * $Header$ * * Copyright (c) 2006 Gene Michael Stover. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 * USA */ /* * Use a memory XDR stream to decode a couple of chars. * We hard-code the individual octets of the XDR stream, & * we check the chars that it decodes. * Also check that the getpos after we've decoded the int. */ #include "this.h" int main () { int rc = 0; XDR xdr; /* These octets should decode to 'A' and 'z'. */ char buffer[8] = { 0, 0, 0, 'A', 0, 0, 0, 'z' }; char c; xdrmem_create (&xdr, buffer, sizeof buffer, XDR_DECODE); if (xdr_char (&xdr, &c)) { if (c == 'A') { if (xdr_char (&xdr, &c)) { if (c == 'z') { if (xdr_getpos (&xdr) == 8) { /* good */ } else { printf ("\n%s:%d:", __FILE__, __LINE__); printf (" xdr_getpos returns"); printf (" %lu.", (unsigned long) xdr_getpos (&xdr)); printf (" Expected 8."); rc = -2; } } else { printf ("\n%s:%d:", __FILE__, __LINE__); printf (" The second xdr_char decoded '%c'. Expected 'z'.", c); rc = -2; } } else { printf ("\n%s:%d:", __FILE__, __LINE__); printf (" The second xdr_char failed"); rc = -2; } } else { printf ("\n%s:%d:", __FILE__, __LINE__); printf (" The first xdr_char decoded '%c'. Expected 'A'.", c); rc = -2; } } else { printf ("\n%s:%d:", __FILE__, __LINE__); printf (" The first xdr_char failed"); rc = -2; } xdr_destroy (&xdr); return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } /* --- end of file --- */