--
--	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 hostsp

#COMMENT "Host i/o library, V1.00, 10/03/89"
#COMMENT "(c) Copyright INMOS Limited 1989"
#COMMENT "KROC hostsp version 1996"
#INCLUDE "hostio.inc"
--{{{  sp.rename
--* Rename the specified file.
--
-- @param fs from server
-- @param ts to server
-- @param oldname the present name of the file to be renamed
-- @param newname the desired name of the file to be renamed
-- @param result equals spr.ok if the renaming was successful;
--   otherwise takes on a value indicating what went wrong:
--   spr.bad.packet.size   the combined lengths of oldname and newname
--   is too large - it must be less than sp.max.renamename.size
--   spr.bad.name          either or both of the filenames are null
--   >=spr.operation.failed  the renaming failed - see hostio.inc or
--   iserver documentation for further details
PROC sp.rename (CHAN OF SP fs, ts, VAL []BYTE oldname, newname, BYTE result)
  IF
    (((SIZE oldname) + (SIZE newname)) > sp.max.renamename.size)
      result := spr.bad.packet.size
    ((SIZE oldname) = 0) OR ((SIZE newname) = 0)
      result := spr.bad.name
    TRUE
      [sp.max.packet.data.size]BYTE buffer :
      INT16 temp.INT16 :
      SEQ
        --{{{  pack up the data into the buffer (5 bytes plus data)
        buffer [0] := sp.rename.tag
        
        temp.INT16 := INT16 (SIZE oldname)
        VAL [2]BYTE b.temp RETYPES temp.INT16 :
        [buffer FROM 1 FOR 2] := b.temp
        
        [buffer FROM 3 FOR SIZE oldname] := oldname
        
        temp.INT16 := INT16 (SIZE newname)
        VAL [2]BYTE b.temp RETYPES temp.INT16 :
        [buffer FROM (SIZE oldname) + 3 FOR 2] := b.temp
        
        [buffer FROM (SIZE oldname) + 5 FOR SIZE newname] := newname
        --}}}pack up the data into the buffer (5 bytes plus data)
        --{{{  send and receive the buffer
        SEQ
          INT len :
          SEQ
            -- Size of buffer is ((SIZE oldname) + (SIZE newname)) + 5
            -- Add 1, then mask off bottom bit, to ensure it is even
            len := (((SIZE oldname) + (SIZE newname)) + 6) /\ ((-1) << 1)
            IF
              len < sp.min.packet.data.size
                temp.INT16 := INT16 sp.min.packet.data.size
              TRUE
                temp.INT16 := INT16 len
        
          ts ! temp.INT16 :: buffer
          fs ? temp.INT16 :: buffer
        --}}}send and receive the buffer
        --{{{  unpack the data                  (1 byte)
        result := buffer [0]
        --}}}
:
--}}}sp.rename
--{{{  so.rename
PROC so.rename (CHAN OF SP fs, ts, VAL []BYTE oldname, newname, BYTE result)

  sp.rename (fs, ts, oldname, newname, result)
:
--}}}so.rename
