wcsnrtombs.c (610b5a1fb1076cc591ceda87680d1caf69564def) wcsnrtombs.c (1949a3470f29c5edaa5fc2770c2886d653fa68d1)
1/*-
2 * Copyright (c) 2002-2004 Tim J. Robbins.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 nbytes = 0;
59
60 if (dst == NULL) {
61 while (nwc-- > 0) {
62 if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1)
63 /* Invalid character - wcrtomb() sets errno. */
64 return ((size_t)-1);
65 else if (*s == L'\0')
1/*-
2 * Copyright (c) 2002-2004 Tim J. Robbins.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 nbytes = 0;
59
60 if (dst == NULL) {
61 while (nwc-- > 0) {
62 if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1)
63 /* Invalid character - wcrtomb() sets errno. */
64 return ((size_t)-1);
65 else if (*s == L'\0')
66 return (nbytes + nb - 1);
66 break;
67 s++;
68 nbytes += nb;
69 }
67 s++;
68 nbytes += nb;
69 }
70 return (nbytes);
70 return (nbytes + nb - 1);
71 }
72
73 while (len > 0 && nwc-- > 0) {
74 if (len > (size_t)MB_CUR_MAX) {
75 /* Enough space to translate in-place. */
71 }
72
73 while (len > 0 && nwc-- > 0) {
74 if (len > (size_t)MB_CUR_MAX) {
75 /* Enough space to translate in-place. */
76 if ((nb = __wcrtomb(dst, *s, ps)) == (size_t)-1) {
76 if ((nb = (int)__wcrtomb(dst, *s, ps)) < 0) {
77 *src = s;
78 return ((size_t)-1);
79 }
80 } else {
81 /*
82 * May not be enough space; use temp. buffer.
83 *
84 * We need to save a copy of the conversion state
85 * here so we can restore it if the multibyte
86 * character is too long for the buffer.
87 */
88 mbsbak = *ps;
77 *src = s;
78 return ((size_t)-1);
79 }
80 } else {
81 /*
82 * May not be enough space; use temp. buffer.
83 *
84 * We need to save a copy of the conversion state
85 * here so we can restore it if the multibyte
86 * character is too long for the buffer.
87 */
88 mbsbak = *ps;
89 if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1) {
89 if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) {
90 *src = s;
91 return ((size_t)-1);
92 }
93 if (nb > (int)len) {
94 /* MB sequence for character won't fit. */
95 *ps = mbsbak;
96 break;
97 }

--- 14 unchanged lines hidden ---
90 *src = s;
91 return ((size_t)-1);
92 }
93 if (nb > (int)len) {
94 /* MB sequence for character won't fit. */
95 *ps = mbsbak;
96 break;
97 }

--- 14 unchanged lines hidden ---