mirror of
https://github.com/fluencelabs/musl
synced 2025-06-12 22:41:37 +00:00
use restrict everywhere it's required by c99 and/or posix 2008
to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
#define HIGHS (ONES * (UCHAR_MAX/2+1))
|
||||
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
|
||||
|
||||
void *memccpy(void *dest, const void *src, int c, size_t n)
|
||||
void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
|
||||
{
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#define ALIGN (sizeof(size_t)-1)
|
||||
#define ONES ((size_t)-1/UCHAR_MAX)
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
void *memcpy(void *restrict dest, const void *restrict src, size_t n)
|
||||
{
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define HIGHS (ONES * (UCHAR_MAX/2+1))
|
||||
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
|
||||
|
||||
char *__stpcpy(char *d, const char *s)
|
||||
char *__stpcpy(char *restrict d, const char *restrict s)
|
||||
{
|
||||
size_t *wd;
|
||||
const size_t *ws;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define HIGHS (ONES * (UCHAR_MAX/2+1))
|
||||
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
|
||||
|
||||
char *__stpncpy(char *d, const char *s, size_t n)
|
||||
char *__stpncpy(char *restrict d, const char *restrict s, size_t n)
|
||||
{
|
||||
size_t *wd;
|
||||
const size_t *ws;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
char *strcat(char *dest, const char *src)
|
||||
char *strcat(char *restrict dest, const char *restrict src)
|
||||
{
|
||||
strcpy(dest + strlen(dest), src);
|
||||
return dest;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
char *__stpcpy(char *, const char *);
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
char *strcpy(char *restrict dest, const char *restrict src)
|
||||
{
|
||||
#if 1
|
||||
__stpcpy(dest, src);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
char *strncat(char *d, const char *s, size_t n)
|
||||
char *strncat(char *restrict d, const char *restrict s, size_t n)
|
||||
{
|
||||
char *a = d;
|
||||
d += strlen(d);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
char *__stpncpy(char *, const char *, size_t);
|
||||
|
||||
char *strncpy(char *d, const char *s, size_t n)
|
||||
char *strncpy(char *restrict d, const char *restrict s, size_t n)
|
||||
{
|
||||
__stpncpy(d, s, n);
|
||||
return d;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
char *strtok(char *s, const char *sep)
|
||||
char *strtok(char *restrict s, const char *restrict sep)
|
||||
{
|
||||
static char *p;
|
||||
if (!s && !(s = p)) return NULL;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
char *strtok_r(char *s, const char *sep, char **p)
|
||||
char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p)
|
||||
{
|
||||
if (!s && !(s = *p)) return NULL;
|
||||
s += strspn(s, sep);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
void swab(const void *_src, void *_dest, ssize_t n)
|
||||
void swab(const void *restrict _src, void *restrict _dest, ssize_t n)
|
||||
{
|
||||
const char *src = _src;
|
||||
char *dest = _dest;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcpcpy(wchar_t *d, const wchar_t *s)
|
||||
wchar_t *wcpcpy(wchar_t *restrict d, const wchar_t *restrict s)
|
||||
{
|
||||
return wcscpy(d, s) + wcslen(s);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcpncpy(wchar_t *d, const wchar_t *s, size_t n)
|
||||
wchar_t *wcpncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n)
|
||||
{
|
||||
return wcsncpy(d, s, n) + wcsnlen(s, n);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcscat(wchar_t *dest, const wchar_t *src)
|
||||
wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src)
|
||||
{
|
||||
wcscpy(dest + wcslen(dest), src);
|
||||
return dest;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcscpy(wchar_t *d, const wchar_t *s)
|
||||
wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s)
|
||||
{
|
||||
wchar_t *a = d;
|
||||
while ((*d++ = *s++));
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
|
||||
wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n)
|
||||
{
|
||||
wchar_t *a = d;
|
||||
d += wcslen(d);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n)
|
||||
wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n)
|
||||
{
|
||||
wchar_t *a = d;
|
||||
while (n && *s) n--, *d++ = *s++;
|
||||
|
@ -93,7 +93,7 @@ static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n)
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t *wcsstr(const wchar_t *h, const wchar_t *n)
|
||||
wchar_t *wcsstr(const wchar_t *restrict h, const wchar_t *restrict n)
|
||||
{
|
||||
/* Return immediately on empty needle or haystack */
|
||||
if (!n[0]) return (wchar_t *)h;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcstok(wchar_t *s, const wchar_t *sep, wchar_t **p)
|
||||
wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep, wchar_t **restrict p)
|
||||
{
|
||||
if (!s && !(s = *p)) return NULL;
|
||||
s += wcsspn(s, sep);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
|
||||
wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n)
|
||||
{
|
||||
wchar_t *a = d;
|
||||
while (n--) *d++ = *s++;
|
||||
|
Reference in New Issue
Block a user