diff options
author | tjr <tjr@FreeBSD.org> | 2004-04-06 13:14:03 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2004-04-06 13:14:03 +0000 |
commit | 4212f9711ffee179c943b9f40b788b759a1ad9e6 (patch) | |
tree | 6779dc19a3df61ca545f851748ebd5f5de3a255e /lib/libc/locale/mbsrtowcs.c | |
parent | fcc4fa555ff7fcd7b9e4327aa717b090a18361b5 (diff) | |
download | FreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.zip FreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.tar.gz |
Prepare to handle state-dependent encodings. This mainly involves not
taking shortcuts when it comes to storing and passing around conversion
states.
Diffstat (limited to 'lib/libc/locale/mbsrtowcs.c')
-rw-r--r-- | lib/libc/locale/mbsrtowcs.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libc/locale/mbsrtowcs.c b/lib/libc/locale/mbsrtowcs.c index 3e7b3b8..8b3de2f 100644 --- a/lib/libc/locale/mbsrtowcs.c +++ b/lib/libc/locale/mbsrtowcs.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,8 +34,9 @@ __FBSDID("$FreeBSD$"); size_t mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, - mbstate_t * __restrict ps __unused) + mbstate_t * __restrict ps) { + static mbstate_t mbs; const char *s; size_t nchr; wchar_t wc; @@ -44,9 +45,11 @@ mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, s = *src; nchr = 0; + if (ps == NULL) + ps = &mbs; if (dst == NULL) { for (;;) { - if ((nb = (int)mbrtowc(&wc, s, MB_CUR_MAX, NULL)) < 0) + if ((nb = (int)mbrtowc(&wc, s, MB_CUR_MAX, ps)) < 0) /* Invalid sequence - mbrtowc() sets errno. */ return ((size_t)-1); else if (nb == 0) @@ -58,7 +61,7 @@ mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, } while (len-- > 0) { - if ((nb = (int)mbrtowc(dst, s, MB_CUR_MAX, NULL)) < 0) { + if ((nb = (int)mbrtowc(dst, s, MB_CUR_MAX, ps)) < 0) { *src = s; return ((size_t)-1); } else if (nb == 0) { |