My apologies if this is not the correct newsgroup.
I’m a newcomer to QNX 4.25. I’m having difficulty using the XDR routines. In particular, I create a XDR “memory stream” using xdrmem_create(), but as soon as I attempt to access it with xdr_getpos() I get a segmentation violation. The QNX 4 “knowledge base” at qnx.com mentions a similar problem, and says that XDR programs must be compiled with -Wc,-ei so I am using this flag. Nonetheless the following “simple” program gives segmentation fault when I run it. Any advice would be much appreciated.
#include <stdio.h>
#include <rpc/xdr.h>
#include <netinet/in.h>
int main(int argc, char **argv) {
// Allocate XDR state buffer - allocate lots of extra
unsigned int outBufSize = 1000;
char *outBuf = (char *)malloc(outBufSize);
XDR xdrStream;
xdrmem_create(&xdrStream, outBuf, outBufSize, XDR_ENCODE);
fprintf(stderr, “TEST xdr_getpos()\n”);
int pos = xdr_getpos(&xdrStream); // Seg fault occurs here!!!
fprintf(stderr, “xdr_getpos() OK\n”);
fprintf(stderr, “TEST xdr_setpos()\n”);
if (!xdr_setpos(&xdrStream, 0)) {
fprintf(stderr, “xdr_setpos() failed!\n”);
}
else {
fprintf(stderr, “xdr_setpos() OK\n”);
}
return 0;
}
Regards,
Tom