本文整理汇总了C++中xdrstdio_create函数的典型用法代码示例。如果您正苦于以下问题:C++ xdrstdio_create函数的具体用法?C++ xdrstdio_create怎么用?C++ xdrstdio_create使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xdrstdio_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prot_x
int prot_x (int connfd)
{
XDR xdrs_r, xdrs_w;
//char buf[MAXBUFL];
//int nread;
int op1 = 0;
int op2 = 0;
int res;
//xdrmem_create(xdrs, buf, MAXBUFL, XDR_DECODE);
FILE *stream_socket_r = fdopen(connfd, "r");
if (stream_socket_r == NULL)
err_sys ("(%s) error - fdopen() failed", prog_name);
xdrstdio_create(&xdrs_r, stream_socket_r, XDR_DECODE);
FILE *stream_socket_w = fdopen(connfd, "w");
if (stream_socket_w == NULL)
err_sys ("(%s) error - fdopen() failed", prog_name);
xdrstdio_create(&xdrs_w, stream_socket_w, XDR_ENCODE);
trace( err_msg("(%s) - waiting for operands ...", prog_name) );
/* get the operands */
if ( ! xdr_int(&xdrs_r, &op1) ) {
trace( err_msg("(%s) - cannot read op1 with XDR", prog_name) );
} else {
trace( err_msg("(%s) - read op1 = %d", prog_name, op1) );
}
if ( ! xdr_int(&xdrs_r, &op2) ) {
trace( err_msg("(%s) - cannot read op2 with XDR", prog_name) );
} else {
trace( err_msg("(%s) - read op2 = %d", prog_name, op2) );
}
/* do the operation */
res = op1 + op2;
xdr_destroy(&xdrs_r);
trace( err_msg("(%s) --- result of the sum: %d", prog_name, res) );
/* send the result */
xdr_int(&xdrs_w, &res);
fflush(stream_socket_w);
xdr_destroy(&xdrs_w);
fclose(stream_socket_w);
/* NB: Close read streams only after writing operations have also been done */
fclose(stream_socket_r);
trace( err_msg("(%s) --- result just sent back", prog_name) );
return 0;
}
示例2: mbbs_rdversion
int
mbbs_rdversion(FILE *fp, int *version)
{
XDR xdrs;
if (sizeof(int) < 4)
return BS_BADARCH;
bs_iobytecnt= 0;
xdrstdio_create(&xdrs, fp, XDR_DECODE);
if (!xdr_int(&xdrs, version))
return BS_FAILURE;
bs_iobytecnt+= 4;
switch (*version) {
case MR1_VERSION_1_0:
case MR1_VERSION_2_0:
case BS_VERSION_1_0:
case BS_VERSION_1_1:
case BS_VERSION_1_2:
case BS_VERSION_1_3:
case BS_VERSION_1_4:
break;
default:
return BS_BADDATA;
}
xdr_destroy(&xdrs);
return BS_SUCCESS;
}
示例3: main
main ()
{
FILE *fp; /*указатель файла */
XDR xdrs; /*дескpиптоp XDR */
long val1=10; /*целое */
float val2=4.456789; /*с плавающей точкой */
char val3s[] = "qwerty123456uvwxyz"; /* 18+1 bytes null terminated string */
char *val3;
int r;
val3 = malloc(20);
strcpy(val3,val3s);
/*откpытие файла на запись */
fp = fopen(FIC, "w");
/* создание потока XDR для кодиpования */
xdrstdio_create(&xdrs, fp, XDR_ENCODE);
/*запись целого */
xdr_long(&xdrs, &val1);
/*запись числа с плавающей точкой */
xdr_float(&xdrs, &val2);
/* write string */
r = xdr_string(&xdrs, &val3, strlen(val3));
printf("r=%d\n",r);
free(val3);
fclose(fp);
exit(0);
}
示例4: read_nis_obj
static void *
read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
size_t objsize)
{
FILE *in = fopen (name, "rce");
if (in == NULL)
return NULL;
void *obj = calloc (1, objsize);
if (obj != NULL)
{
XDR xdrs;
xdrstdio_create (&xdrs, in, XDR_DECODE);
bool_t status = readfct (&xdrs, obj);
xdr_destroy (&xdrs);
if (!status)
{
freefct (obj);
obj = NULL;
}
}
fclose (in);
return obj;
}
示例5: write_struct
static bool_t
write_struct(char *filename, xdrproc_t structproc, void *list)
{
FILE *fp;
XDR xdrs;
mode_t omask;
omask = umask(077);
fp = fopen(filename, "w");
if (fp == NULL) {
int i;
for (i = 0; i < 10; i++)
close(i);
fp = fopen(filename, "w");
if (fp == NULL) {
syslog(LOG_ERR,
"cannot open file = %s for writing", filename);
syslog(LOG_ERR, "cannot save any registration");
return (FALSE);
}
}
(void) umask(omask);
xdrstdio_create(&xdrs, fp, XDR_ENCODE);
if (structproc(&xdrs, list) == FALSE) {
syslog(LOG_ERR, "rpcbind: xdr_%s: failed", filename);
fclose(fp);
return (FALSE);
}
XDR_DESTROY(&xdrs);
fclose(fp);
return (TRUE);
}
示例6: xdrstdio_create_cb
/* opens test file for read or write */
bool_t
xdrstdio_create_cb (XDR *xdrs, enum xdr_op op, void * data)
{
bool_t rVal = TRUE;
xdrstdio_creation_data* xdrstdio_data = (xdrstdio_creation_data*)data;
switch (op)
{
case XDR_DECODE:
case XDR_FREE:
xdrstdio_data->f = fopen (xdrstdio_data->fullname, FOPEN_RB);
break;
case XDR_ENCODE:
xdrstdio_data->f = fopen (xdrstdio_data->fullname, FOPEN_WB);
break;
}
if (!xdrstdio_data->f)
{
log_msg (xdrstdio_data->o->log, XDR_LOG_NORMAL,
"could not open data file: %s\n", xdrstdio_data->fullname);
rVal = FALSE;
}
else
{
xdrstdio_create (xdrs, xdrstdio_data->f, op);
xdrstdio_data->finish_guard = 1;
}
return rVal;
}
示例7: nis_read_obj
nis_object *
nis_read_obj (const char *name)
{
XDR xdrs;
FILE *in;
bool_t status;
nis_object *obj;
in = fopen (name, "rb");
if (in == NULL)
return NULL;
obj = calloc (1, sizeof (nis_object));
if (obj == NULL)
{
fclose (in);
return NULL;
}
xdrstdio_create (&xdrs, in, XDR_DECODE);
status =_xdr_nis_object (&xdrs, obj);
xdr_destroy (&xdrs);
fclose (in);
if (status)
return obj;
else
{
nis_free_object (obj);
return NULL;
}
}
示例8: malloc
void *restore_data(void *data){
//Deserialization
/*This way I can actually recover the data in the same process*/
container *old_data;
old_data=(container *) malloc(sizeof(container));
FILE *fp;
XDR xdrs;
fp=fopen(ser_process_var,"r");
xdrstdio_create(&xdrs,fp, XDR_DECODE);
if(!xdr_container(&xdrs,old_data)) printf("Deserialization error\n"); //Do sth!!!
//else printf("Data restored\n");
xdr_destroy (&xdrs);
fclose (fp);
// printf("From old version:\nage %f name %s address %s option %d\n",old_data->age,old_data->name, old_data->address, old_data->option);
container_2 *new_data;
new_data=(container_2 *) malloc(sizeof(container_2));
new_data->name=old_data->name;
new_data->num_executions=(int)old_data->num_executions;
// printf("Restored :\nage %d name %s address %s option %d\n",new_data->age,new_data->name, new_data->address, new_data->option);
free(old_data);
return (void *)new_data;
}
示例9: readColdStartFile
directory_obj *
readColdStartFile (void)
{
XDR xdrs;
FILE *in;
bool_t status = TRUE;
directory_obj *obj;
in = fopen (cold_start_file, "rb");
if (in == NULL)
return NULL;
obj = calloc (1, sizeof (directory_obj));
if (obj != NULL)
{
xdrstdio_create (&xdrs, in, XDR_DECODE);
status = _xdr_directory_obj (&xdrs, obj);
xdr_destroy (&xdrs);
if (!status)
{
nis_free_directory (obj);
obj = NULL;
}
}
fclose (in);
return obj;
}
示例10: mda_dump
int mda_dump( char *file)
{
XDR xdrstream;
FILE *input;
int extraflag;
if( (input = fopen( file, "rb")) == NULL)
{
fprintf(stderr, "Can't open file!\n");
return 1;
}
xdrstdio_create(&xdrstream, input, XDR_DECODE);
extraflag = mda_dump_header( &xdrstream);
mda_dump_scan( &xdrstream);
if( extraflag)
mda_dump_extra( &xdrstream);
xdr_destroy( &xdrstream);
fclose(input);
return 0;
}
示例11: strcpy
long *kdReadLongArray(char *filename, int bAscii, char *arrayName)
// Reads a tipsy array file
{
XDR xdrs;
FILE *fp;
long np;
long *arr, temp;
int i;
char arrFile[256];
strcpy(arrFile, filename);
strcat(arrFile, ".");
strcat(arrFile, arrayName);
fprintf(stderr, "array = %s\n", arrFile);
if (!bAscii) {
assert(sizeof(Real)==sizeof(float)); /* Otherwise, this XDR stuff
ain't gonna work */
fp = fopen(arrFile, "r");
xdrstdio_create(&xdrs, fp, XDR_DECODE);
xdr_long(&xdrs, &np);
arr = malloc(sizeof(float)*np);
for(i=0;i<np;i++) xdr_long(&xdrs,&temp);
}
fclose(fp);
return arr;
}
示例12: main
main()
{
xdrstdio_create(&xdrs, stdin, XDR_DECODE);
forever {
if(xdr_header() != 1)
break;
if(gas_particles != NULL) free(gas_particles);
if(header.nsph != 0) {
gas_particles = (struct gas_particle *)
malloc(header.nsph*sizeof(*gas_particles));
if(gas_particles == NULL) {
printf("<sorry, no memory for gas particles, master>\n") ;
return ;
}
}
else
gas_particles = NULL;
if(dark_particles != NULL) free(dark_particles);
if(header.ndark != 0) {
dark_particles = (struct dark_particle *)
malloc(header.ndark*sizeof(*dark_particles));
if(dark_particles == NULL) {
printf("<sorry, no memory for dark particles, master>\n") ;
return ;
}
}
else
dark_particles = NULL;
if(star_particles != NULL) free(star_particles);
if(header.nstar != 0) {
star_particles = (struct star_particle *)
malloc(header.nstar*sizeof(*star_particles));
if(star_particles == NULL) {
printf("<sorry, no memory for star particles, master>\n") ;
return ;
}
}
else
star_particles = NULL;
xdr_gas();
xdr_dark();
xdr_star();
fwrite((char *)&header,sizeof(header),1,stdout) ;
fwrite((char *)gas_particles,sizeof(struct gas_particle),
header.nsph, stdout) ;
fwrite((char *)dark_particles,sizeof(struct dark_particle),
header.ndark,stdout) ;
fwrite((char *)star_particles,sizeof(struct star_particle),
header.nstar, stdout) ;
fprintf(stderr, "read time %lf\n",header.time) ;
}
xdr_destroy(&xdrs);
}
示例13: main
int
main ()
{
XDR xdr;
stringlist strings;
stringentry *entry;
FILE *fp;
fp = fopen ("test1.out", "w");
xdrstdio_create (&xdr, fp, XDR_ENCODE);
strings = malloc (sizeof (struct stringentry));
strings->item = strdup ("hello");
strings->next = malloc (sizeof (struct stringentry));
strings->next->item = strdup ("goodbye");
strings->next->next = NULL;
if (!xdr_stringlist (&xdr, &strings)) {
fprintf (stderr, "test1: could not encode\n");
exit (1);
}
xdr_free ((xdrproc_t) xdr_stringlist, (char *) &strings);
xdr_destroy (&xdr);
fclose (fp);
fp = fopen ("test1.out", "r");
xdrstdio_create (&xdr, fp, XDR_DECODE);
strings = NULL;
if (!xdr_stringlist (&xdr, &strings)) {
fprintf (stderr, "test1: could not decode\n");
exit (1);
}
fclose (fp);
for (entry = strings; entry; entry = entry->next)
printf ("entry->item = %s\n", entry->item);
xdr_free ((xdrproc_t) xdr_stringlist, (char *) &strings);
xdr_destroy (&xdr);
exit (0);
}
示例14: wrxdr
/**
* Write a SAC data file from memory to disk is XDR (portable) format
*
* @param idfl
* Data file list index number
* @param kname
* Name of file to write
* @param kname_s
* Length of \p kname
* @param ldta
* - TRUE to write the data and header
* - FALSE to write only the header, not data
* @param nerr
* Error Return Flag
* - 0 on Success
* - ERROR_WRITING_XDR_FILE
* - ERROR_ENCODING_XDR_FILE
*
* @date 010496: Original version.
*
*/
void
wrxdr(int idfl,
char *kname,
int kname_s,
int ldta,
int *nerr) {
int jcomp, ncerr, nlcmem, nptwr;
FILE *nun;
XDR xdrs;
*nerr = 0;
if( !ldta ){
*nerr = ERROR_WRITING_XDR_FILE;
return;
}
/* create a file */
znfiles(&nun, kname, kname_s, "TEXT", 5, nerr);
if( *nerr != 0 )
return;
/* create a stream for the XDR conversions */
xdrstdio_create(&xdrs, nun, XDR_ENCODE);
/* - Write the header to disk. */
nlcmem = Ndxhdr[idfl];
xdrhdr(xdrs, cmmem.sacmem[nlcmem],nerr);
if( *nerr != 0 )
goto L_8888;
/* - Write each data component, if requested. */
if( ldta ){
for( jcomp = 0; jcomp < Ncomp[idfl]; jcomp++ ){
nlcmem = cmdfm.ndxdta[idfl - 1][jcomp];
nptwr = Nlndta[idfl];
if( !xdr_array(&xdrs, (caddr_t *)&cmmem.sacmem[nlcmem],
(u_int *)&nptwr, (u_int)nptwr, sizeof(float), xdr_float)){
*nerr = ERROR_ENCODING_XDR_FILE;
goto L_8888;
}
}
}
/* - Close disk file. */
L_8888:
xdr_destroy(&xdrs);
zcloses( &nun, &ncerr );
return;
}
示例15: mint_1_readfh
void mint_1_readfh(mint_1 *dest, FILE *fh)
{
XDR xdrs;
xdrstdio_create(&xdrs, fh, XDR_DECODE);
if (!xdr_mint_1(&xdrs, dest))
panic("error decoding MINT input file");
xdr_destroy(&xdrs);
mint_1_check(dest);
}