1/* -*- c-basic-offset: 8; -*-
2 *
3 * Copyright (c) 1993 W. Richard Stevens.  All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies.  The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
9 */
10
11#include	"sock.h"
12
13/* Convert newline to return/newline. */
14
15int
16crlf_add(char *dst, int dstsize, const char *src, int lenin)
17{
18	int 	lenout;
19	char	c;
20
21	if ( (lenout = lenin) > dstsize)
22			err_quit("crlf_add: destination not big enough");
23
24	for ( ; lenin > 0; lenin--) {
25		if ( (c = *src++) == '\n') {
26			if (++lenout >= dstsize)
27				err_quit("crlf_add: destination not big enough");
28			*dst++ = '\r';
29		}
30		*dst++ = c;
31	}
32
33	return(lenout);
34}
35
36int
37crlf_strip(char *dst, int dstsize, const char *src, int lenin)
38{
39	int		lenout;
40	char	c;
41
42	for (lenout = 0; lenin > 0; lenin--) {
43		if ( (c = *src++) != '\r') {
44			if (++lenout >= dstsize)
45				err_quit("crlf_strip: destination not big enough");
46			*dst++ = c;
47		}
48	}
49
50	return(lenout);
51}
52