mblen.c revision 102697
150477Speter/*- 21817Sdg * Copyright (c) 1993 31817Sdg * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Paul Borman at Krystal Technologies. 7160798Sjhb * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 9146806Srwatson * modification, are permitted provided that the following conditions 10146806Srwatson * are met: 11146806Srwatson * 1. Redistributions of source code must retain the above copyright 12146806Srwatson * notice, this list of conditions and the following disclaimer. 13146806Srwatson * 2. Redistributions in binary form must reproduce the above copyright 14194390Sjhb * notice, this list of conditions and the following disclaimer in the 15203660Sed * documentation and/or other materials provided with the distribution. 16194390Sjhb * 3. All advertising materials mentioning features or use of this software 17194390Sjhb * must display the following acknowledgement: 1811294Sswallace * This product includes software developed by the University of 1910905Sbde * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 2110905Sbde * may be used to endorse or promote products derived from this software 2210905Sbde * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2899855Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29194645Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30194833Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3369449Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34194383Sjhb * SUCH DAMAGE. 35160797Sjhb */ 36181972Sobrien 37181972Sobrien#include <sys/cdefs.h> 38183361Sjhb__FBSDID("$FreeBSD: head/lib/libc/locale/mblen.c 102697 2002-08-31 11:26:55Z tjr $"); 39181972Sobrien 40181972Sobrien#include <stdlib.h> 41181972Sobrien#include <stddef.h> 42181972Sobrien#include <rune.h> 43211838Skib 44104747Srwatsonint 45104747Srwatsonmblen(s, n) 46123408Speter const char *s; 47123408Speter size_t n; 481541Srgrimes{ 491541Srgrimes char const *e; 5011294Sswallace 5111294Sswallace if (s == 0 || *s == 0) 5211294Sswallace return (0); /* No support for state dependent encodings. */ 5311294Sswallace 541541Srgrimes if (sgetrune(s, n, &e) == _INVALID_RUNE) 551541Srgrimes return (s - e); 561541Srgrimes return (e - s); 571541Srgrimes} 581541Srgrimes