next up previous contents index
Next: Pipes and Sockets Up: XDR Streams Previous: XDR Streams

Files

Writing or reading files is supported with two functions:

XDR *g_xdr_open_file(char *filename, OPEN_MODE mode)
works like fopen, it opens the file filename for writing (if mode is omWrite) or reading (if mode is omRead) and returns the pointer to the XDR stream created for this file. A file created by g_xdr_open_file is closed by
int g_xdr_close_file(XDR *xdrp)
The functions return NULL resp. FALSE if they fail.

With these functions writing an GRAPE XDR file is as simple as writing a normal file. The code to write the instance inst to the file filename is (to read the instance just replace omWrite by omRead)

if((xdrp = g_xdr_open_file(filename, omWrite))) {
  if(!g_xdr_instance(xdrp, &inst))
    fprintf(stderr, "error writing instance\n");
  g_xdr_close_file(xdrp);
} else
  fprintf(stderr, "error opening file\n");

Of course you can write any kind of data to the file, you just have to replace the g_xdr_instance function by the appropriate XDR functions.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.