home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / syscall / Fs_WriteVector.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-30  |  2.6 KB  |  89 lines

  1. /* 
  2.  * Fs_WriteVector.c --
  3.  *
  4.  *    Source code for the Fs_WriteVector library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Fs_WriteVector.c,v 1.5 88/07/29 17:08:39 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <sprite.h>
  21. #include <fs.h>
  22. #include <status.h>
  23. #include <stdlib.h>
  24.  
  25.  
  26. /*
  27.  *----------------------------------------------------------------------
  28.  *
  29.  * Fs_WriteVector --
  30.  *
  31.  *      The "normal" Fs_WriteVector routine for user code.  Write to the file
  32.  *      indicated by the stream ID from the buffers described in vectorArray.
  33.  *    The vectorArray indicates how much data to write, and amtWrittenPtr 
  34.  *    is an output parameter that indicates how much data were written.  
  35.  *
  36.  *    Restarting from a signal is automatically handled by Fs_Write.
  37.  *
  38.  * Results:
  39.  *    Result from Fs_Write.
  40.  *
  41.  * Side effects:
  42.  *    See Fs_Write.
  43.  *
  44.  *----------------------------------------------------------------------
  45.  */
  46.  
  47. ReturnStatus
  48. Fs_WriteVector(streamID, numVectors, vectorArray, amtWrittenPtr)
  49.     int         streamID;    /* The user's index into its open file list. */
  50.     int         numVectors;    /* The # of vectors in userVectorArray. */
  51.     Fs_IOVector vectorArray[];    /* The vectors defining where and how much to
  52.                  * write. */
  53.     int        *amtWrittenPtr;    /* The amount of bytes actually written. */
  54. {
  55.     register int     i;
  56.     register Fs_IOVector *vectorPtr;
  57.     register int    bufSize;
  58.     Address        buffer;
  59.     Address        ptr;
  60.     ReturnStatus    status;
  61.  
  62.     /*
  63.      * Calculate the total number of bytes to be write.
  64.      */
  65.     bufSize = 0;
  66.     for (i = 0, vectorPtr = vectorArray; i < numVectors; i++, vectorPtr++) {
  67.     if (vectorPtr->bufSize < 0) {
  68.         return SYS_INVALID_ARG;
  69.     }
  70.     bufSize += vectorPtr->bufSize;
  71.     }
  72.     buffer = (Address) malloc((unsigned) bufSize);
  73.  
  74.     /*
  75.      * Copy the data from the individual buffers specified in the 
  76.      * vectorArray to the big buffer so the data can be written all at
  77.      * once.
  78.      */
  79.     ptr = buffer;
  80.     for (i = 0, vectorPtr = vectorArray; i < numVectors; i++, vectorPtr++) {
  81.     bcopy(vectorPtr->buffer, ptr, vectorPtr->bufSize);
  82.     ptr += vectorPtr->bufSize;
  83.     }
  84.  
  85.     status = Fs_Write(streamID, bufSize, buffer, amtWrittenPtr);
  86.     free((char *) buffer);
  87.     return(status);
  88. }
  89.