home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / FWRITE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.5 KB  |  83 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - fwrite.c
  3.  *
  4.  * function(s)
  5.  *        fwrite  - writes data to a stream
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <_stdio.h>
  19. #include <asmrules.h>
  20.  
  21. /*---------------------------------------------------------------------*
  22.  
  23. Name            fwrite - writes data to a stream
  24.  
  25. Usage           #include <stdio.h>
  26.                 size_t fwrite(void *ptr, size_t size, size_t nitems,
  27.                               FILE *stream);
  28.  
  29. Related
  30. functions usage size_t fread(void *ptr, size_t size, size_t nitems,
  31.                              FILE *stream);
  32.  
  33. Prototype in    stdio.h
  34.  
  35. Description     fread reads nitems of data, each of length size
  36.                 bytes, from the named input stream into a block pointed to by
  37.                 ptr.
  38.  
  39.                 fwrite appends nitems of data, each of length size bytes, to
  40.                 the named output stream. The data appended begins at ptr.
  41.  
  42.                 For both functions, the total number of bytes read is (nitems
  43.                 * size).
  44.  
  45.                 ptr in the declarations is a pointer to any object.
  46.                 size is the size of the object ptr points to. The
  47.                 expression sizeof *ptr will produce the proper value.
  48.  
  49. Return value    On successful completion, each function returns the
  50.                 number of items (not bytes) actually read or written. fread
  51.                 returns a short count (possibly 0) on end-of-file or error.
  52.                 fwrite returns a short count on error.
  53.  
  54. *---------------------------------------------------------------------*/
  55. size_t _FARFUNC fwrite( const void *ptr, register size_t psize, size_t nitems, FILE *fp )
  56.   {
  57. #if (LDATA)
  58.   register size_t n;
  59. #endif
  60.   unsigned long temp;
  61.  
  62.   if( !psize )  return( nitems );
  63.  
  64.   if( (temp = (unsigned long)psize * (unsigned long)nitems) < 0x10000L )
  65.     {
  66.     return( __fputn( ptr, (unsigned)temp, fp ) / psize );
  67.     }
  68.   else
  69. #if (!LDATA)
  70.     return 0;
  71. #else
  72.     for( n = 0; n < nitems; ++n )
  73.       {
  74.       if( (temp = __fputn( ptr, psize, fp )) != psize )
  75.         return( n );
  76.       else
  77.         ptr = (const void *) (((char huge *) ptr) + psize);
  78.       }
  79.   return( nitems );
  80. #endif
  81.   }
  82.  
  83.