--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module hostio

#COMMENT "Host i/o library, V1.1, 14/05/90"
#COMMENT "(c) Copyright INMOS Limited 1989"
#INCLUDE "hostio.inc"
#USE "spwrite"
--{{{  so.write
--* Write an unlimited number of bytes to a stream.
--
-- @param fs from server
-- @param ts to server
-- @param streamid the identification number of the open stream to
--   write to
-- @param data a string of bytes ALL of which are to be written to the
--   file
-- @param length this gives the number of bytes written; if length <>
--   (SIZE data) then an error occurred
PROC so.write (CHAN OF SP fs, ts, VAL INT32 streamid, VAL []BYTE data,
               INT length)
  --{{{  more information
  -- Notes:    If more than a packet's worth of data is to be written
  --           to a file then one cannot guarantee that all of the data
  --           will be written to the file before any other process
  --           accesses the same file.
  --}}}  
  --{{{  history
  -- Removed the unnecessary test ( result = spr.ok ) from the WHILE loop
  -- condition since the present implementation of sp.write always returns
  -- spr.ok; V1.1, SRH 14-May-90
  --}}}  

  BOOL writing :
  SEQ
    writing := TRUE
    length  := 0
    WHILE writing AND (length < (SIZE data))
      INT length.to.write, length.written :
      SEQ
        IF
          ((SIZE data) - length) > sp.max.writebuffer.size
            length.to.write := sp.max.writebuffer.size
          TRUE
            length.to.write := ((SIZE data) - length)

        BYTE result :  -- a dummy for this routine
        sp.write (fs, ts, streamid, [data FROM length FOR length.to.write],
                  length.written, result)
        writing := (length.to.write = length.written)
        length  := length + length.written
:
--}}}  so.write
