1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
* $Id: fwrite.c,v 1.3 2008/01/29 15:22:53 baud Exp $
*/
/*
* Copyright (C) 1990-2008 by CERN/IT/PDP/DM
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: fwrite.c,v $ $Revision: 1.3 $ $Date: 2008/01/29 15:22:53 $ CERN/IT/PDP/DM F. Hemmer, A. Trannoy";
#endif /* not lint */
/* fwrite.c Remote File I/O - write a binary file */
/*
* System remote file I/O definitions
*/
#define RFIO_KERNEL 1
#include "rfio.h"
#include "rfio_rfilefdt.h"
/*
* Remote file buffered write
*/
int DLL_DECL rfio_fwrite(ptr, size, items, fp)
void *ptr; /* buffer pointer */
int size, items;
RFILE *fp;
{
int rc ;
INIT_TRACE("RFIO_TRACE");
TRACE(1, "rfio", "rfio_fwrite(%x, %d, %d, %x)", ptr, size, items, fp);
if (fp == NULL ) {
errno = EBADF ;
END_TRACE() ;
return 0 ;
}
if (rfio_rfilefdt_findptr(fp,FINDRFILE_WITH_SCAN) == -1) {
rc= fwrite(ptr, size, items, (FILE *)fp) ;
if ( rc == 0 ) serrno = 0;
END_TRACE() ;
rfio_errno = 0;
return rc ;
}
/*
* Checking magic number
*/
if ( fp->magic != RFIO_MAGIC) {
int fps = fp->s;
serrno = SEBADVERSION ;
free((char *)fp);
(void) close(fps) ;
END_TRACE();
return 0 ;
}
/*
* The file is remote
*/
rc= rfio_write(fp->s,ptr,size*items) ;
switch(rc) {
case -1:
#ifdef linux
((RFILE *)fp)->eof |= _IO_ERR_SEEN ;
#else
#if defined( __APPLE__)
((RFILE *)fp)->eof |= __SERR ;
#else
#ifdef __Lynx__
((RFILE *)fp)->eof |= _ERR ;
#else
((RFILE *)fp)->eof |= _IOERR ;
#endif
#endif
#endif
rc= 0 ;
break ;
case 0:
#ifdef linux
((RFILE *)fp)->eof |= _IO_EOF_SEEN ;
#else
#if defined( __APPLE__)
((RFILE *)fp)->eof |= __SEOF ;
#else
#ifdef __Lynx__
((RFILE *)fp)->eof |= _EOF ;
#else
((RFILE *)fp)->eof |= _IOEOF ;
#endif
#endif
#endif
break ;
default:
rc= (rc+size-1)/size ;
break ;
}
END_TRACE() ;
return rc ;
}
|