1121326Sharti/*
2121326Sharti * Copyright (c) 2003-2003
3121326Sharti *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4121326Sharti * 	All rights reserved.
5121326Sharti *
6131826Sharti * Author: Hartmut Brandt <harti@freebsd.org>
7131826Sharti *
8121326Sharti * Redistribution and use in source and binary forms, with or without
9121326Sharti * modification, are permitted provided that the following conditions
10121326Sharti * are met:
11121326Sharti * 1. Redistributions of source code must retain the above copyright
12121326Sharti *    notice, this list of conditions and the following disclaimer.
13121326Sharti * 2. Redistributions in binary form must reproduce the above copyright
14121326Sharti *    notice, this list of conditions and the following disclaimer in the
15121326Sharti *    documentation and/or other materials provided with the distribution.
16121326Sharti *
17121326Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18121326Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19121326Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20121326Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21121326Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22121326Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23121326Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24121326Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25121326Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26121326Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27121326Sharti * SUCH DAMAGE.
28121326Sharti *
29131826Sharti * $Begemot: libunimsg/netnatm/misc/unimsg_common.c,v 1.3 2004/07/08 08:22:03 brandt Exp $
30121326Sharti */
31121326Sharti
32121326Sharti#include <netnatm/unimsg.h>
33121326Sharti
34121326Sharti/*
35121326Sharti * Make sure there is enough space in front of the data for
36121326Sharti * len bytes, and update the read pointer.
37121326Sharti */
38121326Shartiint
39121326Shartiuni_msg_prepend(struct uni_msg *msg, size_t len)
40121326Sharti{
41121326Sharti	size_t need;
42121326Sharti
43121326Sharti	if (uni_msg_leading(msg) >= len) {
44121326Sharti		msg->b_rptr -= len;
45121326Sharti		return (0);
46121326Sharti	}
47121326Sharti	need = len - uni_msg_leading(msg);
48121326Sharti	if (uni_msg_ensure(msg, need))
49121326Sharti		return (-1);
50121326Sharti	memcpy(msg->b_rptr + need, msg->b_rptr, uni_msg_len(msg));
51121326Sharti	msg->b_rptr += need - len;
52121326Sharti	msg->b_wptr += need;
53121326Sharti	return (0);
54121326Sharti}
55