mblen.c (f0c6c306f91a839c0ad2e84a3e1b84aa81b26c8f) | mblen.c (b6f33850e0b8ee9cc071000b1ed108a9144a8609) |
---|---|
1/*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 24 unchanged lines hidden (view full) --- 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD$"); 39 40#include <errno.h> | 1/*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 24 unchanged lines hidden (view full) --- 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD$"); 39 40#include <errno.h> |
41#include <stdlib.h> | |
42#include <stddef.h> | 41#include <stddef.h> |
42#include <stdlib.h> |
|
43#include <rune.h> 44 45int | 43#include <rune.h> 44 45int |
46mblen(s, n) 47 const char *s; 48 size_t n; | 46mblen(const char *s, size_t n) |
49{ | 47{ |
50 char const *e; | 48 const char *e; |
51 | 49 |
52 if (s == 0 || *s == 0) 53 return (0); /* No support for state dependent encodings. */ | 50 if (s == NULL || *s == '\0') 51 /* No support for state dependent encodings. */ 52 return (0); |
54 55 if (sgetrune(s, n, &e) == _INVALID_RUNE) { 56 errno = EILSEQ; 57 return (s - e); 58 } 59 return (e - s); 60} | 53 54 if (sgetrune(s, n, &e) == _INVALID_RUNE) { 55 errno = EILSEQ; 56 return (s - e); 57 } 58 return (e - s); 59} |