From f27b1c064cce031591086617b72c704502a46782 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Thu, 15 Jan 2009 18:53:52 +0000 Subject: [PATCH] Introduce a local variable and use it instead of passed in parameter to get rid of restrict qualifier discarding. This lets libc compile cleanly in gnu99 mode. Suggested by: kib, christoph.mallon at gmx.de Approved by: kib (mentor) --- lib/libc/locale/mbstowcs.c | 4 +++- lib/libc/locale/wcsftime.c | 6 ++++-- lib/libc/locale/wcstombs.c | 4 +++- lib/libc/stdio/fputws.c | 4 +++- lib/libc/stdio/vswscanf.c | 4 +++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/libc/locale/mbstowcs.c b/lib/libc/locale/mbstowcs.c index ad259d84dab3..194ec2e03534 100644 --- a/lib/libc/locale/mbstowcs.c +++ b/lib/libc/locale/mbstowcs.c @@ -37,7 +37,9 @@ mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) { static const mbstate_t initial; mbstate_t mbs; + const char *sp; mbs = initial; - return (__mbsnrtowcs(pwcs, &s, SIZE_T_MAX, n, &mbs)); + sp = s; + return (__mbsnrtowcs(pwcs, &sp, SIZE_T_MAX, n, &mbs)); } diff --git a/lib/libc/locale/wcsftime.c b/lib/libc/locale/wcsftime.c index 7a54fc053c5a..22eb389e64ad 100644 --- a/lib/libc/locale/wcsftime.c +++ b/lib/libc/locale/wcsftime.c @@ -53,6 +53,7 @@ wcsftime(wchar_t * __restrict wcs, size_t maxsize, static const mbstate_t initial; mbstate_t mbs; char *dst, *dstp, *sformat; + const wchar_t *formatp; size_t n, sflen; int sverrno; @@ -63,13 +64,14 @@ wcsftime(wchar_t * __restrict wcs, size_t maxsize, * for strftime(), which only handles single-byte characters. */ mbs = initial; - sflen = wcsrtombs(NULL, &format, 0, &mbs); + formatp = format; + sflen = wcsrtombs(NULL, &formatp, 0, &mbs); if (sflen == (size_t)-1) goto error; if ((sformat = malloc(sflen + 1)) == NULL) goto error; mbs = initial; - wcsrtombs(sformat, &format, sflen + 1, &mbs); + wcsrtombs(sformat, &formatp, sflen + 1, &mbs); /* * Allocate memory for longest multibyte sequence that will fit diff --git a/lib/libc/locale/wcstombs.c b/lib/libc/locale/wcstombs.c index acd0051463b3..250d2b9b1047 100644 --- a/lib/libc/locale/wcstombs.c +++ b/lib/libc/locale/wcstombs.c @@ -37,7 +37,9 @@ wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) { static const mbstate_t initial; mbstate_t mbs; + const wchar_t *pwcsp; mbs = initial; - return (__wcsnrtombs(s, &pwcs, SIZE_T_MAX, n, &mbs)); + pwcsp = pwcs; + return (__wcsnrtombs(s, &pwcsp, SIZE_T_MAX, n, &mbs)); } diff --git a/lib/libc/stdio/fputws.c b/lib/libc/stdio/fputws.c index 73974113253a..b4462b744197 100644 --- a/lib/libc/stdio/fputws.c +++ b/lib/libc/stdio/fputws.c @@ -45,6 +45,7 @@ fputws(const wchar_t * __restrict ws, FILE * __restrict fp) char buf[BUFSIZ]; struct __suio uio; struct __siov iov; + const wchar_t *wsp; FLOCKFILE(fp); ORIENT(fp, 1); @@ -54,7 +55,8 @@ fputws(const wchar_t * __restrict ws, FILE * __restrict fp) uio.uio_iovcnt = 1; iov.iov_base = buf; do { - nbytes = __wcsnrtombs(buf, &ws, SIZE_T_MAX, sizeof(buf), + wsp = ws; + nbytes = __wcsnrtombs(buf, &wsp, SIZE_T_MAX, sizeof(buf), &fp->_mbstate); if (nbytes == (size_t)-1) goto error; diff --git a/lib/libc/stdio/vswscanf.c b/lib/libc/stdio/vswscanf.c index 67bfb47b68d4..8a70d446337b 100644 --- a/lib/libc/stdio/vswscanf.c +++ b/lib/libc/stdio/vswscanf.c @@ -66,6 +66,7 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, char *mbstr; size_t mlen; int r; + const wchar_t *strp; /* * XXX Convert the wide character string to multibyte, which @@ -74,7 +75,8 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL) return (EOF); mbs = initial; - if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) { + strp = str; + if ((mlen = wcsrtombs(mbstr, &strp, SIZE_T_MAX, &mbs)) == (size_t)-1) { free(mbstr); return (EOF); }