home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / FWRITE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.7 KB  |  84 lines

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