Blame snprintf/mbrtowc_sb.c

Packit c04fcb
/*	$OpenBSD: mbrtowc_sb.c,v 1.4 2005/11/27 20:03:06 cloder Exp $	*/
Packit c04fcb
/*	$NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $	*/
Packit c04fcb
Packit c04fcb
/*
Packit c04fcb
 * Copyright (c) 1991 The Regents of the University of California.
Packit c04fcb
 * All rights reserved.
Packit c04fcb
 *
Packit c04fcb
 * Redistribution and use in source and binary forms, with or without
Packit c04fcb
 * modification, are permitted provided that the following conditions
Packit c04fcb
 * are met:
Packit c04fcb
 * 1. Redistributions of source code must retain the above copyright
Packit c04fcb
 *    notice, this list of conditions and the following disclaimer.
Packit c04fcb
 * 2. Redistributions in binary form must reproduce the above copyright
Packit c04fcb
 *    notice, this list of conditions and the following disclaimer in the
Packit c04fcb
 *    documentation and/or other materials provided with the distribution.
Packit c04fcb
 * 3. Neither the name of the University nor the names of its contributors
Packit c04fcb
 *    may be used to endorse or promote products derived from this software
Packit c04fcb
 *    without specific prior written permission.
Packit c04fcb
 *
Packit c04fcb
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit c04fcb
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit c04fcb
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit c04fcb
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit c04fcb
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit c04fcb
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit c04fcb
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit c04fcb
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit c04fcb
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit c04fcb
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit c04fcb
 * SUCH DAMAGE.
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
#include <errno.h>
Packit c04fcb
#include <stdlib.h>
Packit c04fcb
#include <wchar.h>
Packit c04fcb
Packit c04fcb
/*ARGSUSED*/
Packit c04fcb
size_t
Packit c04fcb
ust_safe_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
Packit c04fcb
{
Packit c04fcb
Packit c04fcb
	/* pwc may be NULL */
Packit c04fcb
	/* s may be NULL */
Packit c04fcb
	/* ps appears to be unused */
Packit c04fcb
Packit c04fcb
	if (s == NULL)
Packit c04fcb
		return 0;
Packit c04fcb
	if (n == 0)
Packit c04fcb
		return (size_t)-1;
Packit c04fcb
	if (pwc)
Packit c04fcb
		*pwc = (wchar_t)(unsigned char)*s;
Packit c04fcb
	return (*s != '\0');
Packit c04fcb
}