summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Mitsis <peter.mitsis@windriver.com>2015-12-17 11:04:31 -0500
committerAnas Nashif <anas.nashif@intel.com>2016-02-05 20:25:22 -0500
commitdf3c6b13abfc9be3b9d1446a99604133191ad9b2 (patch)
treeb5df05a508d30861aec793240f5e673daa1b7e8b /lib
parent497d0e53c49e15a156d70d812dd0185c8014808f (diff)
c++: Update minimal libc headers
Updates the minimal libc headers for differences between the C and C++ languages. This includes ... 1. Conditionally defining "bool", "true" and "false" as they are already keywords in C++. 2. Making the definition of NULL language dependent. 3. Using the _Restrict macro instead of the restrict keyword as restrict exists in C, but not in C++. 4. Changing the definition of size_t so that it is compatible with what the compiler expects when building the new operator stubs (as it varies by architecture). Change-Id: I37ff058a60b90a05f96e9dd6f61d454d143041ce Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/minimal/include/bits/null.h4
-rw-r--r--lib/libc/minimal/include/bits/restrict.h34
-rw-r--r--lib/libc/minimal/include/bits/size_t.h8
-rw-r--r--lib/libc/minimal/include/stdbool.h2
-rw-r--r--lib/libc/minimal/include/stdio.h21
-rw-r--r--lib/libc/minimal/include/string.h9
-rw-r--r--lib/libc/minimal/source/stdout/fprintf.c8
-rw-r--r--lib/libc/minimal/source/stdout/sprintf.c8
-rw-r--r--lib/libc/minimal/source/stdout/stdout_console.c6
-rw-r--r--lib/libc/minimal/source/string/string.c8
10 files changed, 79 insertions, 29 deletions
diff --git a/lib/libc/minimal/include/bits/null.h b/lib/libc/minimal/include/bits/null.h
index 1a15d7390..ee58ce0dc 100644
--- a/lib/libc/minimal/include/bits/null.h
+++ b/lib/libc/minimal/include/bits/null.h
@@ -19,5 +19,9 @@
*/
#if !defined(NULL)
+#ifdef __cplusplus
+ #define NULL 0
+#else
#define NULL (void *)0
#endif
+#endif
diff --git a/lib/libc/minimal/include/bits/restrict.h b/lib/libc/minimal/include/bits/restrict.h
new file mode 100644
index 000000000..9e357939d
--- /dev/null
+++ b/lib/libc/minimal/include/bits/restrict.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016 Wind River Systems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file _Restrict definition
+ *
+ * The macro "_Restrict" is intended to be private to the minimal libc library.
+ * It evaluates to the "restrict" keyword when a C99 compiler is used, and
+ * to "__restrict__" when a C++ compiler is used.
+ */
+
+#if !defined(_Restrict_defined)
+#define _Restrict_defined
+
+#ifdef __cplusplus
+ #define _Restrict __restrict__
+#else
+ #define _Restrict restrict
+#endif
+
+#endif
diff --git a/lib/libc/minimal/include/bits/size_t.h b/lib/libc/minimal/include/bits/size_t.h
index 29a5597f2..204df6bb2 100644
--- a/lib/libc/minimal/include/bits/size_t.h
+++ b/lib/libc/minimal/include/bits/size_t.h
@@ -21,6 +21,14 @@
#if !defined(__size_t_defined)
#define __size_t_defined
+#ifdef __i386
+typedef unsigned long int size_t;
+#elif defined(__ARM_ARCH)
typedef unsigned int size_t;
+#elif defined(__arc__)
+typedef unsigned int size_t;
+#else
+#error "The minimal libc library does not recognize the architecture!\n"
+#endif
#endif
diff --git a/lib/libc/minimal/include/stdbool.h b/lib/libc/minimal/include/stdbool.h
index 2e0fc1dab..2379a2537 100644
--- a/lib/libc/minimal/include/stdbool.h
+++ b/lib/libc/minimal/include/stdbool.h
@@ -19,9 +19,11 @@
#ifndef __INC_stdbool_h__
#define __INC_stdbool_h__
+#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
+#endif
#define __bool_true_false_are_defined 1
diff --git a/lib/libc/minimal/include/stdio.h b/lib/libc/minimal/include/stdio.h
index 5839fccb6..5cf10b698 100644
--- a/lib/libc/minimal/include/stdio.h
+++ b/lib/libc/minimal/include/stdio.h
@@ -22,6 +22,7 @@
#include <stdarg.h> /* Needed to get definition of va_list */
#include <bits/null.h>
#include <bits/size_t.h>
+#include <bits/restrict.h>
#ifdef __cplusplus
extern "C" {
@@ -45,22 +46,22 @@ typedef int FILE;
* declared below.
*/
-int printf(const char *restrict fmt, ...);
-int snprintf(char *restrict s, size_t len, const char *restrict fmt, ...);
-int sprintf(char *restrict s, const char *restrict fmt, ...);
-int fprintf(FILE *restrict stream, const char *restrict format, ...);
+int printf(const char *_Restrict fmt, ...);
+int snprintf(char *_Restrict s, size_t len, const char *_Restrict fmt, ...);
+int sprintf(char *_Restrict s, const char *_Restrict fmt, ...);
+int fprintf(FILE *_Restrict stream, const char *_Restrict format, ...);
-int vprintf(const char *restrict fmt, va_list list);
-int vsnprintf(char *restrict s, size_t len, const char *restrict fmt, va_list list);
-int vsprintf(char *restrict s, const char *restrict fmt, va_list list);
-int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap);
+int vprintf(const char *_Restrict fmt, va_list list);
+int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict fmt, va_list list);
+int vsprintf(char *_Restrict s, const char *_Restrict fmt, va_list list);
+int vfprintf(FILE *_Restrict stream, const char *_Restrict format, va_list ap);
int puts(const char *s);
int fputc(int c, FILE *stream);
-int fputs(const char *restrict s, FILE *restrict stream);
-size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
+int fputs(const char *_Restrict s, FILE *_Restrict stream);
+size_t fwrite(const void *_Restrict ptr, size_t size, size_t nitems, FILE *_Restrict stream);
#ifdef __cplusplus
}
diff --git a/lib/libc/minimal/include/string.h b/lib/libc/minimal/include/string.h
index 51456d8a2..a2845f23e 100644
--- a/lib/libc/minimal/include/string.h
+++ b/lib/libc/minimal/include/string.h
@@ -21,22 +21,23 @@
#include <bits/null.h>
#include <bits/size_t.h>
+#include <bits/restrict.h>
#ifdef __cplusplus
extern "C" {
#endif
-extern char *strcpy(char *restrict d, const char *restrict s);
-extern char *strncpy(char *restrict d, const char *restrict s, size_t n);
+extern char *strcpy(char *_Restrict d, const char *_Restrict s);
+extern char *strncpy(char *_Restrict d, const char *_Restrict s, size_t n);
extern char *strchr(const char *s, int c);
extern size_t strlen(const char *s);
extern int strcmp(const char *s1, const char *s2);
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 *_Restrict dest, const char *_Restrict src);
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 *memcpy(void *restrict d, const void *restrict s, size_t n);
+extern void *memcpy(void *_Restrict d, const void *_Restrict s, 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);
diff --git a/lib/libc/minimal/source/stdout/fprintf.c b/lib/libc/minimal/source/stdout/fprintf.c
index b59640ad6..9656f1678 100644
--- a/lib/libc/minimal/source/stdout/fprintf.c
+++ b/lib/libc/minimal/source/stdout/fprintf.c
@@ -24,7 +24,7 @@
extern int _prf(int (*func)(), void *dest,
const char *format, va_list vargs);
-int fprintf(FILE * restrict F, const char *restrict format, ...)
+int fprintf(FILE *_Restrict F, const char *_Restrict format, ...)
{
va_list vargs;
int r;
@@ -36,7 +36,7 @@ int fprintf(FILE * restrict F, const char *restrict format, ...)
return r;
}
-int vfprintf(FILE * restrict F, const char *restrict format, va_list vargs)
+int vfprintf(FILE *_Restrict F, const char *_Restrict format, va_list vargs)
{
int r;
@@ -45,7 +45,7 @@ int vfprintf(FILE * restrict F, const char *restrict format, va_list vargs)
return r;
}
-int printf(const char *restrict format, ...)
+int printf(const char *_Restrict format, ...)
{
va_list vargs;
int r;
@@ -57,7 +57,7 @@ int printf(const char *restrict format, ...)
return r;
}
-int vprintf(const char *restrict format, va_list vargs)
+int vprintf(const char *_Restrict format, va_list vargs)
{
int r;
diff --git a/lib/libc/minimal/source/stdout/sprintf.c b/lib/libc/minimal/source/stdout/sprintf.c
index f0b05cd46..98dcabf0e 100644
--- a/lib/libc/minimal/source/stdout/sprintf.c
+++ b/lib/libc/minimal/source/stdout/sprintf.c
@@ -37,7 +37,7 @@ static int sprintf_out(int c, struct emitter *p)
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 *_Restrict s, size_t len, const char *_Restrict format, ...)
{
va_list vargs;
@@ -64,7 +64,7 @@ int snprintf(char *restrict s, size_t len, const char *restrict format, ...)
return r;
}
-int sprintf(char *restrict s, const char *restrict format, ...)
+int sprintf(char *_Restrict s, const char *_Restrict format, ...)
{
va_list vargs;
@@ -82,7 +82,7 @@ int sprintf(char *restrict s, const char *restrict format, ...)
return r;
}
-int vsnprintf(char *restrict s, size_t len, const char *restrict format, va_list vargs)
+int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict format, va_list vargs)
{
struct emitter p;
int r;
@@ -105,7 +105,7 @@ int vsnprintf(char *restrict s, size_t len, const char *restrict format, va_list
return r;
}
-int vsprintf(char *restrict s, const char *restrict format, va_list vargs)
+int vsprintf(char *_Restrict s, const char *_Restrict format, va_list vargs)
{
struct emitter p;
int r;
diff --git a/lib/libc/minimal/source/stdout/stdout_console.c b/lib/libc/minimal/source/stdout/stdout_console.c
index 063fb7a73..648bd9e71 100644
--- a/lib/libc/minimal/source/stdout/stdout_console.c
+++ b/lib/libc/minimal/source/stdout/stdout_console.c
@@ -37,7 +37,7 @@ int fputc(int c, FILE *stream)
return (stdout == stream) ? _stdout_hook(c) : EOF;
}
-int fputs(const char *restrict string, FILE *restrict stream)
+int fputs(const char *_Restrict string, FILE *_Restrict stream)
{
if (stream != stdout) {
return EOF;
@@ -53,8 +53,8 @@ int fputs(const char *restrict string, FILE *restrict stream)
return 0;
}
-size_t fwrite(const void *restrict ptr, size_t size, size_t nitems,
- FILE *restrict stream)
+size_t fwrite(const void *_Restrict ptr, size_t size, size_t nitems,
+ FILE *_Restrict stream)
{
size_t i;
size_t j;
diff --git a/lib/libc/minimal/source/string/string.c b/lib/libc/minimal/source/string/string.c
index d888d9dd1..23c16dd4c 100644
--- a/lib/libc/minimal/source/string/string.c
+++ b/lib/libc/minimal/source/string/string.c
@@ -25,7 +25,7 @@
* @return pointer to destination buffer <d>
*/
-char *strcpy(char *restrict d, const char *restrict s)
+char *strcpy(char *_Restrict d, const char *_Restrict s)
{
char *dest = d;
@@ -47,7 +47,7 @@ char *strcpy(char *restrict d, const char *restrict s)
* @return pointer to destination buffer <d>
*/
-char *strncpy(char *restrict d, const char *restrict s, size_t n)
+char *strncpy(char *_Restrict d, const char *_Restrict s, size_t n)
{
char *dest = d;
@@ -138,7 +138,7 @@ int strncmp(const char *s1, const char *s2, size_t n)
return (n == 0) ? 0 : (*s1 - *s2);
}
-char *strcat(char *restrict dest, const char *restrict src)
+char *strcat(char *_Restrict dest, const char *_Restrict src)
{
strcpy(dest + strlen(dest), src);
return dest;
@@ -208,7 +208,7 @@ void *memmove(void *d, const void *s, size_t n)
* @return pointer to start of destination buffer
*/
-void *memcpy(void *restrict d, const void *restrict s, size_t n)
+void *memcpy(void *_Restrict d, const void *_Restrict s, size_t n)
{
/* attempt word-sized copying only if buffers have identical alignment */