home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdio / fwrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-27  |  707 b   |  34 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5.  
  6. size_t fwrite(void *ptr,size_t size,size_t nmemb,FILE *stream)
  7. {
  8.   signed long subsize;
  9.   unsigned long total;
  10.   unsigned char *b=(unsigned char *)ptr;
  11.   if(!(total=size*nmemb)) /* Just in case size==0 */
  12.     return total;
  13.   do
  14.   {
  15.     if(stream->outcount>0)
  16.     {
  17.       subsize=total>stream->outcount?stream->outcount:total;
  18.       memcpy(stream->p,b,subsize);
  19.       stream->p+=subsize;
  20.       stream->outcount-=subsize;
  21.       b+=subsize;
  22.       total-=subsize;
  23.     }else
  24.     {
  25.       int c;
  26.       c=*b++;
  27.       if(putc(c,stream)==EOF)
  28.         break;
  29.       total--;
  30.     }
  31.   }while(total);
  32.   return (b-(unsigned char *)ptr)/size;
  33. }
  34.