/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mbuf.c,v 1.3 2004/12/13 00:25:22 lindak Exp $
*/
/*
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <libintl.h>
#include <assert.h>
#include "private.h"
#include "charsets.h"
/*
* Note: Leaving a little space (8 bytes) between the
* mbuf header and the start of the data so we can
* prepend a NetBIOS header in that space.
*/
#define M_ALIGNFACTOR (sizeof (long))
int
{
struct mbuf *m;
if (m == NULL)
return (ENOMEM);
*mpp = m;
return (0);
}
static void
{
free(m);
}
void
{
struct mbuf *m;
while (m0) {
m0 = m;
}
}
{
int len = 0;
while (m) {
m = m->m_next;
}
return (len);
}
int
{
char *dp;
int error;
return (0);
}
return (error);
while (m0) {
m0 = m;
}
return (0);
}
int
{
}
int
{
struct mbuf *m;
int error;
return (error);
return (0);
}
void
{
}
void
{
}
}
int
{
goto out;
break;
}
if (len > 0) {
return (error);
}
out:
return (0);
}
/*
* Routines to put data in a buffer
*/
void *
{
char *p;
return (NULL);
return (p);
}
/*
* Check if object of size 'size' fit to the current position and
* allocate new mbuf if not. Advance pointers and increase length of mbuf(s).
* Return pointer to the object placeholder or NULL if any error occured.
*/
int
{
int error;
if (M_TRAILINGSPACE(m) < (int)size) {
return (error);
m = mn;
}
return (0);
}
int
{
uint8_t y = x;
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
/* ARGSUSED */
int
{
struct mbuf *m;
const char *src;
char *dst;
int error;
if (size == 0)
return (0);
return (error);
while (size > 0) {
cplen = M_TRAILINGSPACE(m);
if (cplen == 0) {
m = m->m_next;
continue;
}
if (src) {
} else
}
return (0);
}
/*
* Append another mbuf to the mbuf chain.
* If what we're appending is smaller than
* the current trailing space, just copy.
* This always consumes the passed mbuf.
*/
int
{
/* just copy */
m_freem(m);
return (0);
}
while (m) {
break;
m = m->m_next;
}
return (0);
}
/*
* Convenience function to put an OEM or Unicode string,
* null terminated, and aligned if necessary.
*/
int
{
int err;
if (uc) {
/* Put Unicode. align(2) first. */
mb_put_uint8(mbp, 0);
} else {
/* Put ASCII (really OEM) */
}
return (err);
}
/*
* Put an ASCII string (really OEM), given a UTF-8 string.
*/
int
{
char *abuf;
abuf = convert_utf8_to_wincs(s);
return (ENOMEM);
return (err);
}
/*
* Put UCS-2LE, given a UTF-8 string.
*/
int
{
return (ENOMEM);
return (err);
}
/*
* Routines for fetching data from an mbuf chain
*/
int
{
}
int
{
uint16_t v;
int err;
return (err);
if (x != NULL)
*x = letohs(v);
return (0);
}
int
uint16_t v;
int err;
return (err);
if (x != NULL)
*x = betohs(v);
return (0);
}
int
{
uint32_t v;
int err;
return (err);
if (x != NULL)
*x = betohl(v);
return (0);
}
int
{
uint32_t v;
int err;
return (err);
if (x != NULL)
*x = letohl(v);
return (0);
}
int
{
uint64_t v;
int err;
return (err);
if (x != NULL)
*x = betohq(v);
return (0);
}
int
{
uint64_t v;
int err;
return (err);
if (x != NULL)
*x = letohq(v);
return (0);
}
/* ARGSUSED */
int
{
while (size > 0) {
if (m == NULL) {
/* DPRINT("incomplete copy"); */
return (EBADRPC);
}
if (count == 0) {
if (m)
continue;
}
if (dst) {
if (count == 1) {
} else {
}
}
}
return (0);
}
/*
* Get the next SIZE bytes as a separate mblk.
* Nothing fancy here - just copy.
*/
int
{
mbuf_t *m;
int err;
if (err)
return (err);
if (err) {
m_freem(m);
return (err);
}
*ret = m;
return (0);
}
/*
* Get a string from the mbuf chain,
* either Unicode or OEM chars.
*/
int
{
int err;
if (uc)
else
return (err);
}
/*
* Get an ASCII (really OEM) string from the mbuf chain
* and convert it to UTF-8
*
* Similar to md_get_ustring below.
*/
int
{
/*
* First, figure out the string length.
* Use a copy of the real_mbp so we don't
* actually consume it here, then search for
* the null (or end of data).
*/
slen = 0;
for (;;) {
if (err)
break;
if (ch == 0)
break;
slen++;
}
/*
* Now read the (OEM) string for real.
* No need to re-check errors.
*/
return (ENOMEM);
for (i = 0; i < slen; i++) {
}
tstr[i] = 0;
/*
* Convert OEM to UTF-8
*/
return (ENOMEM);
return (0);
}
/*
* Get a UCS-2LE string from the mbuf chain, and
* convert it to UTF-8.
*
* Similar to md_get_astring above.
*/
int
{
char *ostr;
/*
* First, align(2) on the real_mbp
*/
/*
* Next, figure out the string length.
* Use a copy of the real_mbp so we don't
* actually consume it here, then search for
* the null (or end of data).
*/
slen = 0;
for (;;) {
if (err)
break;
if (ch == 0)
break;
slen++;
}
/*
* Now read the (UCS-2) string for real.
* No need to re-check errors. Note:
* This puts the UCS-2 in NATIVE order!
*/
return (ENOMEM);
for (i = 0; i < slen; i++) {
}
tstr[i] = 0;
/*
* Convert UCS-2 (native!) to UTF-8
*/
return (ENOMEM);
return (0);
}