Presentation is loading. Please wait.

Presentation is loading. Please wait.

/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch.

Similar presentations


Presentation on theme: "/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch."— Presentation transcript:

1 /* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch (filekind kind) { case TEXT: void; case DATA: string creator ; case EXEC: string interpretor ; }; struct file { string filename ; filetype type; string owner ; opaque data ; }; fileXDR.x

2 #include #define MAXUSERNAME 32 #define MAXFILELEN #define MAXNAMELEN 255 enum filekind { TEXT = 0, DATA = 1, EXEC = 2, }; typedef enum filekind filekind; bool_t xdr_filekind(); struct filetype { filekind kind; union { char *creator; char *interpretor; } filetype_u; }; typedef struct filetype filetype; bool_t xdr_filetype(); struct file { char *filename; filetype type; char *owner; struct { u_int data_len; char *data_val; } data; }; typedef struct file file; bool_t xdr_file(); fileXDR.h

3 #include #include "fileXDR.h" bool_t xdr_filekind(xdrs, objp) XDR *xdrs; filekind *objp; { if (!xdr_enum(xdrs, (enum_t *)objp)) { return (FALSE); } return (TRUE); } fileXDR_xdr.c (I)

4 bool_t xdr_filetype(xdrs, objp) XDR *xdrs; filetype *objp; { if (!xdr_filekind(xdrs, &objp->kind)) { return (FALSE); } switch (objp->kind) { case TEXT: break; case DATA: if (!xdr_string(xdrs, &objp->filetype_u.creator, MAXNAMELEN)) { return (FALSE); } break; case EXEC: if (!xdr_string(xdrs, &objp->filetype_u.interpretor, MAXNAMELEN)){ return (FALSE); } break; default: return (FALSE); } return (TRUE); } fileXDR_xdr.c (II)

5 bool_t xdr_file(xdrs, objp) XDR *xdrs; file *objp; { if (!xdr_string(xdrs, &objp->filename, MAXNAMELEN)) { return (FALSE); } if (!xdr_filetype(xdrs, &objp->type)) { return (FALSE); } if (!xdr_string(xdrs, &objp->owner, MAXUSERNAME)) { return (FALSE); } if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, MAXFILELEN)) { return (FALSE); } return (TRUE); } fileXDR_xdr.c (III)

6 #include #include "fileXDR.h" int main() { XDR xdr_handle; FILE *fp; file fichero; char data[5]; data[0]='a'; data[1]='b'; data[2]='c'; data[3]='d'; data[4]='e'; if((fp=fopen("salida","w"))!=NULL) { xdrstdio_create(&xdr_handle,fp,XDR_ENCODE); fichero.filename="nombrefichero"; fichero.type.kind=TEXT; fichero.owner="nombrepropietario"; fichero.data.data_len=5; fichero.data.data_val=data; xdr_file(&xdr_handle,&fichero); xdr_destroy(&xdr_handle); fclose(fp); } Escribir.c


Download ppt "/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch."

Similar presentations


Ads by Google