unimsg_common.c revision 121326
1139826Simp/*
253541Sshin * Copyright (c) 2003-2003
353541Sshin *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
453541Sshin * 	All rights reserved.
553541Sshin *
653541Sshin * Redistribution and use in source and binary forms, with or without
753541Sshin * modification, are permitted provided that the following conditions
853541Sshin * are met:
953541Sshin * 1. Redistributions of source code must retain the above copyright
1053541Sshin *    notice, this list of conditions and the following disclaimer.
1153541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1253541Sshin *    notice, this list of conditions and the following disclaimer in the
1353541Sshin *    documentation and/or other materials provided with the distribution.
1453541Sshin *
1553541Sshin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1653541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1753541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1853541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1953541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2053541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2153541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2253541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2353541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2453541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2553541Sshin * SUCH DAMAGE.
2653541Sshin *
2753541Sshin * Author: Hartmut Brandt <harti@freebsd.org>
28174510Sobrien *
29174510Sobrien * $Begemot: libunimsg/atm/misc/unimsg_common.c,v 1.2 2003/09/19 12:05:45 hbb Exp $
30174510Sobrien */
3153541Sshin
3253541Sshin#include <netnatm/unimsg.h>
3353541Sshin
3462587Sitojun/*
3553541Sshin * Make sure there is enough space in front of the data for
3662587Sitojun * len bytes, and update the read pointer.
3762587Sitojun */
3862587Sitojunint
3962587Sitojununi_msg_prepend(struct uni_msg *msg, size_t len)
4062587Sitojun{
4153541Sshin	size_t need;
4278064Sume
4353541Sshin	if (uni_msg_leading(msg) >= len) {
4453541Sshin		msg->b_rptr -= len;
4553541Sshin		return (0);
4653541Sshin	}
4753541Sshin	need = len - uni_msg_leading(msg);
4853541Sshin	if (uni_msg_ensure(msg, need))
4953541Sshin		return (-1);
5053541Sshin	memcpy(msg->b_rptr + need, msg->b_rptr, uni_msg_len(msg));
5153541Sshin	msg->b_rptr += need - len;
5253541Sshin	msg->b_wptr += need;
5362587Sitojun	return (0);
54151539Ssuz}
55151539Ssuz