2004-01-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/mbrtowc.c (_mbrtowc_r): Fix case where s is null
        pointer to match C99 spec.
        * libc/stdlib/mbsrtowcs.c (_mbsrtowc_r): Fix to ignore len when
        dst is NULL.  Also fix to not alter src pointer when dst is NULL
        and call _mbrtowc_r instead of _mbtowc_r.
        * libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Call _wcrtomb_r instead
        of _wctomb_r.
			
			
This commit is contained in:
		| @@ -1,3 +1,13 @@ | |||||||
|  | 2004-01-21  Jeff Johnston  <jjohnstn@redhat.com> | ||||||
|  |  | ||||||
|  | 	* libc/stdlib/mbrtowc.c (_mbrtowc_r): Fix case where s is null | ||||||
|  | 	pointer to match C99 spec. | ||||||
|  | 	* libc/stdlib/mbsrtowcs.c (_mbsrtowc_r): Fix to ignore len when | ||||||
|  | 	dst is NULL.  Also fix to not alter src pointer when dst is NULL | ||||||
|  | 	and call _mbrtowc_r instead of _mbtowc_r. | ||||||
|  | 	* libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Call _wcrtomb_r instead | ||||||
|  | 	of _wctomb_r. | ||||||
|  |  | ||||||
| 2004-01-19  Thomas Pfaff  <tpfaff@gmx.net> | 2004-01-19  Thomas Pfaff  <tpfaff@gmx.net> | ||||||
|  |  | ||||||
| 	* libc/stdio/fclose.c (fclose): Release FILE as the last step. | 	* libc/stdio/fclose.c (fclose): Release FILE as the last step. | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ _DEFUN (_mbrtowc_r, (ptr, pwc, s, n, ps), | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
|   if (s == NULL) |   if (s == NULL) | ||||||
|     retval = _mbtowc_r (ptr, pwc, "", 1, ps); |     retval = _mbtowc_r (ptr, NULL, "", 1, ps); | ||||||
|   else |   else | ||||||
|     retval = _mbtowc_r (ptr, pwc, s, n, ps); |     retval = _mbtowc_r (ptr, pwc, s, n, ps); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,9 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), | |||||||
| 	mbstate_t *ps) | 	mbstate_t *ps) | ||||||
| { | { | ||||||
|   wchar_t *ptr = dst; |   wchar_t *ptr = dst; | ||||||
|   size_t max = n; |   const char *tmp_src; | ||||||
|  |   size_t max; | ||||||
|  |   size_t count = 0; | ||||||
|   int bytes; |   int bytes; | ||||||
|  |  | ||||||
| #ifdef MB_CAPABLE | #ifdef MB_CAPABLE | ||||||
| @@ -24,13 +26,24 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |   if (dst == NULL) | ||||||
|  |     { | ||||||
|  |       /* Ignore original n value and do not alter src pointer if the | ||||||
|  |          dst pointer is NULL.  */ | ||||||
|  |       n = (size_t)-1; | ||||||
|  |       tmp_src = *src; | ||||||
|  |       src = &tmp_src; | ||||||
|  |     }       | ||||||
|  |    | ||||||
|  |   max = n; | ||||||
|   while (n > 0) |   while (n > 0) | ||||||
|     { |     { | ||||||
|       bytes = _mbtowc_r (r, ptr, *src, MB_CUR_MAX, ps); |       bytes = _mbrtowc_r (r, ptr, *src, MB_CUR_MAX, ps); | ||||||
|       if (bytes > 0) |       if (bytes > 0) | ||||||
| 	{ | 	{ | ||||||
| 	  *src += bytes; | 	  *src += bytes; | ||||||
| 	  ++ptr; | 	  ++count; | ||||||
|  | 	  ptr = (dst == NULL) ? NULL : ptr + 1; | ||||||
| 	  --n; | 	  --n; | ||||||
| 	} | 	} | ||||||
|       else if (bytes == -2) |       else if (bytes == -2) | ||||||
| @@ -40,7 +53,7 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), | |||||||
|       else if (bytes == 0) |       else if (bytes == 0) | ||||||
| 	{ | 	{ | ||||||
| 	  *src = NULL; | 	  *src = NULL; | ||||||
| 	  return (size_t)(ptr - dst); | 	  return count; | ||||||
| 	} | 	} | ||||||
|       else |       else | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ _DEFUN (_wcsrtombs_r, (r, dst, src, len, ps), | |||||||
|     { |     { | ||||||
|       int count = ps->__count; |       int count = ps->__count; | ||||||
|       wint_t wch = ps->__value.__wch; |       wint_t wch = ps->__value.__wch; | ||||||
|       int bytes = _wctomb_r (r, buff, *pwcs, ps); |       int bytes = _wcrtomb_r (r, buff, *pwcs, ps); | ||||||
|       if (bytes == -1) |       if (bytes == -1) | ||||||
| 	{ | 	{ | ||||||
| 	  r->_errno = EILSEQ; | 	  r->_errno = EILSEQ; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user