unimsg_common.c revision 256281
1696Spaul/* 2696Spaul * Copyright (c) 2003-2003 3696Spaul * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4696Spaul * All rights reserved. 5696Spaul * 6696Spaul * Author: Hartmut Brandt <harti@freebsd.org> 7696Spaul * 8696Spaul * Redistribution and use in source and binary forms, with or without 9696Spaul * modification, are permitted provided that the following conditions 10696Spaul * are met: 11696Spaul * 1. Redistributions of source code must retain the above copyright 12696Spaul * notice, this list of conditions and the following disclaimer. 13696Spaul * 2. Redistributions in binary form must reproduce the above copyright 14696Spaul * notice, this list of conditions and the following disclaimer in the 15696Spaul * documentation and/or other materials provided with the distribution. 16696Spaul * 171153Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18696Spaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19696Spaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20696Spaul * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21696Spaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22696Spaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23696Spaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24696Spaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25696Spaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26696Spaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27696Spaul * SUCH DAMAGE. 28696Spaul * 29696Spaul * $Begemot: libunimsg/netnatm/misc/unimsg_common.c,v 1.3 2004/07/08 08:22:03 brandt Exp $ 30696Spaul */ 3195648Smarkm 3295648Smarkm#include <netnatm/unimsg.h> 3369827Scharnier 34696Spaul/* 3595648Smarkm * Make sure there is enough space in front of the data for 3676224Sobrien * len bytes, and update the read pointer. 3795648Smarkm */ 3895153Smikeint 3995648Smarkmuni_msg_prepend(struct uni_msg *msg, size_t len) 40696Spaul{ 4190172Ssobomax size_t need; 421741Srich 43180236Sedwin if (uni_msg_leading(msg) >= len) { 441741Srich msg->b_rptr -= len; 451741Srich return (0); 461741Srich } 47181136Sjhb need = len - uni_msg_leading(msg); 481741Srich if (uni_msg_ensure(msg, need)) 49696Spaul return (-1); 5095648Smarkm memcpy(msg->b_rptr + need, msg->b_rptr, uni_msg_len(msg)); 5118600Speter msg->b_rptr += need - len; 52180646Sedwin msg->b_wptr += need; 53180877Sedwin return (0); 54180877Sedwin} 55180877Sedwin