#ifndef lint
static char *RCSid = "$Header: /usr/brule/guest/empire/empire/emprcs/lib/gen/sendtext.c,v 2.0 1995/07/27 05:56:17 empire Exp $";
#endif

/*
 * sendtext.c
 *
 * Send text to a specified user.
 * from (glib), PSL 1985
 *
 */

#include "misc.h"

sendtext(user, text)
	s_char	*user;
	s_char	*text;
{
	int pfh[2];
	int len;
	s_char buf[4096];

	pipe(pfh);
	/* need to copy in case static text */
	strncpy(buf, text, sizeof(buf)-2);
	buf[sizeof(buf)-2] = '\0';
	len = strlen(buf);
	if (len > 1 && buf[len-1] != '\n') {
		buf[len-1] = '\n';
		buf[len] = 0;
		len++;
	}
	write(pfh[1], buf, len);
	close(pfh[1]);
	send_mail(user, pfh[0]);
	close(pfh[0]);
}
