/* Copyright 1998 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * Generic (c.status)
 *
 * � Acorn Computers Ltd. 1997
 */
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include <string.h>
#include "sys/errno.h"
#include "module.h"
#include "protocol.h"

_kernel_oserror *generic_status(_kernel_swi_regs *r)
{
        int *pollword=(int *)r->r[1];
        Session *ses;

        ses = find_session(r->r[1]);
        if (ses == NULL) {
                r->r[0] = r->r[2] = r->r[3] = r->r[4] = 0;
                return NULL;
        }

        r->r[0] = *pollword = ses->reported_state;
        r->r[3] = ses->sent;

        /* Note.  The following condition is CORRECT.  We don't want to confuse the caller
         * into thinking that there is no more data left just because we've seen a
         * Content-Length: 0   header.  We need it to continue to read the header information.
         * Only once we are into body transfers can be legally set this to zero
         */
        r->r[4] = ses->size > 0 ? ses->size : -1;

        return NULL;
}