libc: minimal: rename private macro

As it turns out Xtensa SDK headers also define _Restrict, causing
havoc. As this was intended to be a private macro, rename it to something
less likely to cause a collision.

Change-Id: I0a7501a1af8cf87efb096872a91a7b44bd2bbdca
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-02-02 12:01:59 -08:00 committed by Anas Nashif
commit c2a91b1b2e
7 changed files with 54 additions and 39 deletions

View file

@ -6,20 +6,20 @@
/** /**
* @file * @file
* @brief _Restrict definition * @brief _MLIBC_RESTRICT definition
* *
* The macro "_Restrict" is intended to be private to the minimal libc library. * The macro "_MLIBC_RESTRICT" is intended to be private to the minimal libc
* It evaluates to the "restrict" keyword when a C99 compiler is used, and * library. It evaluates to the "restrict" keyword when a C99 compiler is
* to "__restrict__" when a C++ compiler is used. * used, and to "__restrict__" when a C++ compiler is used.
*/ */
#if !defined(_Restrict_defined) #if !defined(_MLIBC_RESTRICT_defined)
#define _Restrict_defined #define _MLIBC_RESTRICT_defined
#ifdef __cplusplus #ifdef __cplusplus
#define _Restrict __restrict__ #define _MLIBC_RESTRICT __restrict__
#else #else
#define _Restrict restrict #define _MLIBC_RESTRICT restrict
#endif #endif
#endif #endif

View file

@ -35,22 +35,28 @@ typedef int FILE;
* declared below. * declared below.
*/ */
int printf(const char *_Restrict fmt, ...); int printf(const char *_MLIBC_RESTRICT fmt, ...);
int snprintf(char *_Restrict s, size_t len, const char *_Restrict fmt, ...); int snprintf(char *_MLIBC_RESTRICT s, size_t len,
int sprintf(char *_Restrict s, const char *_Restrict fmt, ...); const char *_MLIBC_RESTRICT fmt, ...);
int fprintf(FILE *_Restrict stream, const char *_Restrict format, ...); int sprintf(char *_MLIBC_RESTRICT s, const char *_MLIBC_RESTRICT fmt, ...);
int fprintf(FILE *_MLIBC_RESTRICT stream,
const char *_MLIBC_RESTRICT format, ...);
int vprintf(const char *_Restrict fmt, va_list list); int vprintf(const char *_MLIBC_RESTRICT fmt, va_list list);
int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict fmt, va_list list); int vsnprintf(char *_MLIBC_RESTRICT s, size_t len,
int vsprintf(char *_Restrict s, const char *_Restrict fmt, va_list list); const char *_MLIBC_RESTRICT fmt, va_list list);
int vfprintf(FILE *_Restrict stream, const char *_Restrict format, va_list ap); int vsprintf(char *_MLIBC_RESTRICT s,
const char *_MLIBC_RESTRICT fmt, va_list list);
int vfprintf(FILE *_MLIBC_RESTRICT stream, const char *_MLIBC_RESTRICT format,
va_list ap);
int puts(const char *s); int puts(const char *s);
int fputc(int c, FILE *stream); int fputc(int c, FILE *stream);
int fputs(const char *_Restrict s, FILE *_Restrict stream); int fputs(const char *_MLIBC_RESTRICT s, FILE *_MLIBC_RESTRICT stream);
size_t fwrite(const void *_Restrict ptr, size_t size, size_t nitems, FILE *_Restrict stream); size_t fwrite(const void *_MLIBC_RESTRICT ptr, size_t size, size_t nitems,
FILE *_MLIBC_RESTRICT stream);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -16,20 +16,24 @@
extern "C" { extern "C" {
#endif #endif
extern char *strcpy(char *_Restrict d, const char *_Restrict s); extern char *strcpy(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s);
extern char *strncpy(char *_Restrict d, const char *_Restrict s, size_t n); extern char *strncpy(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s,
size_t n);
extern char *strchr(const char *s, int c); extern char *strchr(const char *s, int c);
extern char *strrchr(const char *s, int c); extern char *strrchr(const char *s, int c);
extern size_t strlen(const char *s); extern size_t strlen(const char *s);
extern int strcmp(const char *s1, const char *s2); extern int strcmp(const char *s1, const char *s2);
extern int strncmp(const char *s1, const char *s2, size_t n); extern int strncmp(const char *s1, const char *s2, size_t n);
extern char *strcat(char *_Restrict dest, const char *_Restrict src); extern char *strcat(char *_MLIBC_RESTRICT dest,
extern char *strncat(char *_Restrict d, const char *_Restrict s, size_t n); const char *_MLIBC_RESTRICT src);
extern char *strncat(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s,
size_t n);
extern char *strstr(const char *s, const char *find); extern char *strstr(const char *s, const char *find);
extern int memcmp(const void *m1, const void *m2, size_t n); extern int memcmp(const void *m1, const void *m2, size_t n);
extern void *memmove(void *d, const void *s, size_t n); extern void *memmove(void *d, const void *s, size_t n);
extern void *memcpy(void *_Restrict d, const void *_Restrict s, size_t n); extern void *memcpy(void *_MLIBC_RESTRICT d, const void *_MLIBC_RESTRICT s,
size_t n);
extern void *memset(void *buf, int c, size_t n); extern void *memset(void *buf, int c, size_t n);
extern void *memchr(const void *s, unsigned char c, size_t n); extern void *memchr(const void *s, unsigned char c, size_t n);

View file

@ -14,7 +14,7 @@
extern int _prf(int (*func)(), void *dest, extern int _prf(int (*func)(), void *dest,
const char *format, va_list vargs); const char *format, va_list vargs);
int fprintf(FILE *_Restrict F, const char *_Restrict format, ...) int fprintf(FILE *_MLIBC_RESTRICT F, const char *_MLIBC_RESTRICT format, ...)
{ {
va_list vargs; va_list vargs;
int r; int r;
@ -26,7 +26,8 @@ int fprintf(FILE *_Restrict F, const char *_Restrict format, ...)
return r; return r;
} }
int vfprintf(FILE *_Restrict F, const char *_Restrict format, va_list vargs) int vfprintf(FILE *_MLIBC_RESTRICT F, const char *_MLIBC_RESTRICT format,
va_list vargs)
{ {
int r; int r;
@ -35,7 +36,7 @@ int vfprintf(FILE *_Restrict F, const char *_Restrict format, va_list vargs)
return r; return r;
} }
int printf(const char *_Restrict format, ...) int printf(const char *_MLIBC_RESTRICT format, ...)
{ {
va_list vargs; va_list vargs;
int r; int r;
@ -47,7 +48,7 @@ int printf(const char *_Restrict format, ...)
return r; return r;
} }
int vprintf(const char *_Restrict format, va_list vargs) int vprintf(const char *_MLIBC_RESTRICT format, va_list vargs)
{ {
int r; int r;

View file

@ -27,7 +27,8 @@ static int sprintf_out(int c, struct emitter *p)
return 0; /* indicate keep going so we get the total count */ return 0; /* indicate keep going so we get the total count */
} }
int snprintf(char *_Restrict s, size_t len, const char *_Restrict format, ...) int snprintf(char *_MLIBC_RESTRICT s, size_t len,
const char *_MLIBC_RESTRICT format, ...)
{ {
va_list vargs; va_list vargs;
@ -50,7 +51,7 @@ int snprintf(char *_Restrict s, size_t len, const char *_Restrict format, ...)
return r; return r;
} }
int sprintf(char *_Restrict s, const char *_Restrict format, ...) int sprintf(char *_MLIBC_RESTRICT s, const char *_MLIBC_RESTRICT format, ...)
{ {
va_list vargs; va_list vargs;
@ -68,7 +69,8 @@ int sprintf(char *_Restrict s, const char *_Restrict format, ...)
return r; return r;
} }
int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict format, va_list vargs) int vsnprintf(char *_MLIBC_RESTRICT s, size_t len,
const char *_MLIBC_RESTRICT format, va_list vargs)
{ {
struct emitter p; struct emitter p;
int r; int r;
@ -87,7 +89,8 @@ int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict format, va_li
return r; return r;
} }
int vsprintf(char *_Restrict s, const char *_Restrict format, va_list vargs) int vsprintf(char *_MLIBC_RESTRICT s, const char *_MLIBC_RESTRICT format,
va_list vargs)
{ {
struct emitter p; struct emitter p;
int r; int r;

View file

@ -27,7 +27,7 @@ int fputc(int c, FILE *stream)
return (stdout == stream) ? _stdout_hook(c) : EOF; return (stdout == stream) ? _stdout_hook(c) : EOF;
} }
int fputs(const char *_Restrict string, FILE *_Restrict stream) int fputs(const char *_MLIBC_RESTRICT string, FILE *_MLIBC_RESTRICT stream)
{ {
if (stream != stdout) { if (stream != stdout) {
return EOF; return EOF;
@ -43,8 +43,8 @@ int fputs(const char *_Restrict string, FILE *_Restrict stream)
return 0; return 0;
} }
size_t fwrite(const void *_Restrict ptr, size_t size, size_t nitems, size_t fwrite(const void *_MLIBC_RESTRICT ptr, size_t size, size_t nitems,
FILE *_Restrict stream) FILE *_MLIBC_RESTRICT stream)
{ {
size_t i; size_t i;
size_t j; size_t j;

View file

@ -15,7 +15,7 @@
* @return pointer to destination buffer <d> * @return pointer to destination buffer <d>
*/ */
char *strcpy(char *_Restrict d, const char *_Restrict s) char *strcpy(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s)
{ {
char *dest = d; char *dest = d;
@ -37,7 +37,7 @@ char *strcpy(char *_Restrict d, const char *_Restrict s)
* @return pointer to destination buffer <d> * @return pointer to destination buffer <d>
*/ */
char *strncpy(char *_Restrict d, const char *_Restrict s, size_t n) char *strncpy(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s, size_t n)
{ {
char *dest = d; char *dest = d;
@ -148,13 +148,14 @@ int strncmp(const char *s1, const char *s2, size_t n)
return (n == 0) ? 0 : (*s1 - *s2); return (n == 0) ? 0 : (*s1 - *s2);
} }
char *strcat(char *_Restrict dest, const char *_Restrict src) char *strcat(char *_MLIBC_RESTRICT dest, const char *_MLIBC_RESTRICT src)
{ {
strcpy(dest + strlen(dest), src); strcpy(dest + strlen(dest), src);
return dest; return dest;
} }
char *strncat(char *_Restrict dest, const char *_Restrict src, size_t n) char *strncat(char *_MLIBC_RESTRICT dest, const char *_MLIBC_RESTRICT src,
size_t n)
{ {
char *orig_dest = dest; char *orig_dest = dest;
size_t len = strlen(dest); size_t len = strlen(dest);
@ -232,7 +233,7 @@ void *memmove(void *d, const void *s, size_t n)
* @return pointer to start of destination buffer * @return pointer to start of destination buffer
*/ */
void *memcpy(void *_Restrict d, const void *_Restrict s, size_t n) void *memcpy(void *_MLIBC_RESTRICT d, const void *_MLIBC_RESTRICT s, size_t n)
{ {
/* attempt word-sized copying only if buffers have identical alignment */ /* attempt word-sized copying only if buffers have identical alignment */