I am using Ubuntu 10.4 and have two (long) C programs, one that writes a file using XDR, and one that uses this file as input. However, the second program does not manage to read in the written file. Everything looks perfectly fine, it just does not work. More spesifically it fails at the last line added here with the error message xdr_string(), which indicates that it can not read in the first line of the input file. I do no see any obvious errors. The input file is written out, have a content and I can see the right strings using stings -a -n 2 "inputfile". Anyone have any idea what is going wrong?
Relevant parts of program 1 (writer):
/**
* create compressed XDR output stream
*/
output_file=open_write_pipe(output_filename);
xdrstdio_create(&xdrs, output_file, XDR_ENCODE);
/**
* print material name
*/
if( xdr_string(&xdrs, &name, _POSIX_NAME_MAX) == FALSE )
xdr_err("xdr_string()");
Relevant parts of program 2 (reader):
/**
* open data file
*/
input_file=open_data_file(input_filename, "r");
if( input_file == NULL ){
ERROR(input_filename);
exit(EXIT_FAILURE);
}
/**
* create input XDR stream
*/
xdrstdio_create(&xdrs, input_file, XDR_DECODE);
/**
* read material name
*/
if(xdr_string(&xdrs, &name, _POSIX_NAME_MAX) == FALSE)
XDR_ERR("xdr_string()");
I don't know how
open_write_pipe
oropen_data_file
works, but have you tried writing/reading the file in binary mode? This was the case for Portable XDR for Windows. Admittedly, the sample is for integers but it should be the same for strings.