vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / crlf.c
bloba3a2eb5b0404143d3870188ae57cc26a2ec348a9
1 /* -*- c-basic-offset: 8; -*-
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 */
11 #include "sock.h"
13 /* Convert newline to return/newline. */
15 int
16 crlf_add(char *dst, int dstsize, const char *src, int lenin)
18 int lenout;
19 char c;
21 if ( (lenout = lenin) > dstsize)
22 err_quit("crlf_add: destination not big enough");
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';
30 *dst++ = c;
33 return(lenout);
36 int
37 crlf_strip(char *dst, int dstsize, const char *src, int lenin)
39 int lenout;
40 char c;
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;
50 return(lenout);