/* cgets.c (rsxnt) -- Copyright (c) 1996-1997 Rainer Schnitker */

#include "rsxnt.h"

void __cgets (char *buffer)
{
    char *buf = buffer + 2;
    unsigned int n;

    if (!buffer[0])
	return;

    n = __read(0, buf, buffer[0] - 1);

    if (n >= 2) {
	if (buf[n-1] == '\r' || buf[n-1] == '\n')
	    --n;
	if (buf[n-1] == '\r')
	    --n;
    }
    buf[n] = '\n';

    buffer[1] = n;
}
