Problem reading in file written with xdr using c

Posted by Inga on Stack Overflow See other posts from Stack Overflow or by Inga
Published on 2011-03-01T10:12:47Z Indexed on 2012/10/28 23:02 UTC
Read the original article Hit count: 155

Filed under:
|

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()");

© Stack Overflow or respective owner

Related posts about c

    Related posts about xdr