home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
FWRITE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
1KB
|
67 lines
/* from Dale Schumacher's dLibs */
#include <stddef.h>
#include <stdio.h>
#include <limits.h>
#include <assert.h>
#include <string.h>
#include "lib.h"
size_t fwrite(data, size, count, fp)
const register void *data;
size_t size;
size_t count;
register FILE *fp;
{
register size_t n, m;
register long l = 0;
long space;
unsigned int f = fp->_flag;
if(f & _IORW) {
fp->_flag |= _IOWRT;
f = (fp->_flag &= ~(_IOREAD | _IOEOF));
}
if(!(f & _IOWRT) /* not opened for write? */
|| (f & (_IOERR | _IOEOF))) /* error/eof conditions? */
return(0);
assert ((data != NULL));
assert ((size != 0));
n = count * size;
assert ( n <= (size_t)LONG_MAX); /* otherwise impl will not work */
space = fp->_bsiz - fp->_cnt;
while(n > 0)
{
m = (n > space)? space: n;
bcopy(data, fp->_ptr, m);
fp->_ptr += m;
fp->_cnt += m;
space -= m;
if(space == 0)
{
if(fflush(fp))
return 0;
space = fp->_bsiz;
if(f & _IORW)
fp->_flag |= _IOWRT; /* fflush resets this */
}
l += m;
data += m;
n -= m;
if(n < space)
continue;
if((m = _write(fp->_file, data, (long)n)) != (long)n)
{
fp->_flag |= _IOERR;
return 0;
}
l += m;
break;
}
return((l > 0) ? ((size_t)l / size) : 0);
}