From 98eca60d1111d07e06c7839e6330590f99f32bcf Mon Sep 17 00:00:00 2001 From: Anna Kornfeld Simpson Date: Thu, 26 Jul 2018 09:48:02 -0700 Subject: [PATCH] Add header guards (#295) * Add header guards. * Also add guarding to make sure this is not included in C++ compilation. If it is C++, still want to make sure the unchecked version of the header is included. --- include/fenv_checked.h | 7 +++++++ include/inttypes_checked.h | 7 +++++++ include/math_checked.h | 7 +++++++ include/signal_checked.h | 7 +++++++ include/stdio_checked.h | 7 +++++++ include/stdlib_checked.h | 10 ++++++++++ include/string_checked.h | 9 +++++++++ include/threads_checked.h | 9 +++++++++ include/time_checked.h | 7 +++++++ include/unistd_checked.h | 7 +++++++ 10 files changed, 77 insertions(+) diff --git a/include/fenv_checked.h b/include/fenv_checked.h index ab6220e..f76eaff 100644 --- a/include/fenv_checked.h +++ b/include/fenv_checked.h @@ -8,6 +8,10 @@ #include +#ifndef __cplusplus +#ifndef __FENV_CHECKED_H +#define __FENV_CHECKED_H + #pragma CHECKED_SCOPE ON int fesetexceptflag(const fexcept_t *flagp : itype(_Ptr), @@ -18,3 +22,6 @@ int fesetenv(const fenv_t *envp : itype(_Ptr)); int feupdateenv(const fenv_t *envp : itype(_Ptr)); #pragma CHECKED_SCOPE OFF + +#endif +#endif diff --git a/include/inttypes_checked.h b/include/inttypes_checked.h index 3bd9dfb..3406dee 100644 --- a/include/inttypes_checked.h +++ b/include/inttypes_checked.h @@ -9,6 +9,10 @@ #include // define wchar_t for wcstoimax and wcstoumax #include +#ifndef __cplusplus +#ifndef __INTTYPES_CHECKED_H +#define __INTTYPES_CHECKED_H + #pragma CHECKED_SCOPE ON _Unchecked @@ -39,3 +43,6 @@ uintmax_t wcstoumax(const wchar_t * restrict nptr : int base); #pragma CHECKED_SCOPE OFF + +#endif // guard +#endif // no c++ diff --git a/include/math_checked.h b/include/math_checked.h index 3689427..7f2bfea 100644 --- a/include/math_checked.h +++ b/include/math_checked.h @@ -8,6 +8,10 @@ #include +#ifndef __cplusplus +#ifndef __MATH_CHECKED_H +#define __MATH_CHECKED_H + #pragma CHECKED_SCOPE ON double frexp(double value, int *exp : itype(_Ptr)); @@ -28,3 +32,6 @@ float nanf(const char *t : itype(_Nt_array_ptr)); long double nanl(const char *t : itype(_Nt_array_ptr)); #pragma CHECKED_SCOPE OFF + +#endif //guard +#endif // no c++ diff --git a/include/signal_checked.h b/include/signal_checked.h index 0105b84..aa000af 100644 --- a/include/signal_checked.h +++ b/include/signal_checked.h @@ -5,6 +5,10 @@ #include +#ifndef __cplusplus +#ifndef __SIGNAL_CHECKED_H +#define __SIGNAL_CHECKED_H + #pragma CHECKED_SCOPE ON _Unchecked @@ -15,3 +19,6 @@ void (*signal(int sig, )(int); #pragma CHECKED_SCOPE OFF + +#endif +#endif diff --git a/include/stdio_checked.h b/include/stdio_checked.h index 7b02532..0ff5999 100644 --- a/include/stdio_checked.h +++ b/include/stdio_checked.h @@ -10,6 +10,10 @@ #include +#ifndef __cplusplus +#ifndef __STDIO_CHECKED_H +#define __STDIO_CHECKED_H + #pragma CHECKED_SCOPE ON #if defined(_WIN32) || defined(_WIN64) @@ -183,3 +187,6 @@ void perror(const char *s : itype(_Nt_array_ptr)); #include "_builtin_stdio_checked.h" #pragma CHECKED_SCOPE OFF + +#endif // guard +#endif // no C++ diff --git a/include/stdlib_checked.h b/include/stdlib_checked.h index 76429cd..d835024 100644 --- a/include/stdlib_checked.h +++ b/include/stdlib_checked.h @@ -5,8 +5,15 @@ // These are listed in the same order that they occur in the C11 // // specification. // ///////////////////////////////////////////////////////////////////////// + + #include +#ifndef __cplusplus +#ifndef __STDLIB_CHECKED_H +#define __STDLIB_CHECKED_H + + #pragma CHECKED_SCOPE ON double atof(const char *s : itype(_Nt_array_ptr)); @@ -113,3 +120,6 @@ size_t wcstombs(char * restrict output : count(n), size_t n); #pragma CHECKED_SCOPE OFF + +#endif // guard +#endif // no c++ diff --git a/include/string_checked.h b/include/string_checked.h index ec955e9..08fe778 100644 --- a/include/string_checked.h +++ b/include/string_checked.h @@ -11,8 +11,14 @@ // TODO: Better Support for _FORTIFY_SOURCE > 0 // ///////////////////////////////////////////////////////////////////////// + #include +#ifndef __cplusplus + +#ifndef __STRING_CHECKED_H +#define __STRING_CHECKED_H + #pragma CHECKED_SCOPE ON // GCC has macros that it uses as part of its string implementation to optimize cases @@ -153,3 +159,6 @@ size_t strlen(const char *s : itype(_Nt_array_ptr)); #include "_builtin_string_checked.h" #pragma CHECKED_SCOPE OFF + +#endif // guard +#endif // no C++ diff --git a/include/threads_checked.h b/include/threads_checked.h index 2965625..1bc15a0 100644 --- a/include/threads_checked.h +++ b/include/threads_checked.h @@ -6,6 +6,8 @@ // specification. // ///////////////////////////////////////////////////////////////////////// + + #ifdef _CHECKEDC_MOCKUP_THREADS // C implementations may not support the C11 threads package or even the // macro that says C11 threads are not supported. This mocks up @@ -23,6 +25,10 @@ struct timespec; #include #endif +#ifndef __cplusplus +#ifndef __THREADS_CHECKED_H +#define __THREADS_CHECKED_H + #pragma CHECKED_SCOPE ON void call_once(once_flag *flag : itype(_Ptr), @@ -64,3 +70,6 @@ void *tss_get(tss_t key) : itype(_Ptr); int tss_set(tss_t key, void *value : itype(_Ptr)); #pragma CHECKED_SCOPE OFF + +#endif // guard +#endif // no C++ diff --git a/include/time_checked.h b/include/time_checked.h index 75098f8..bf9dd2a 100644 --- a/include/time_checked.h +++ b/include/time_checked.h @@ -8,6 +8,10 @@ #include +#ifndef __cplusplus +#ifndef __TIME_CHECKED_H +#define __TIME_CHECKED_H + #pragma CHECKED_SCOPE ON time_t mktime(struct tm *timeptr : itype(_Ptr)); @@ -34,3 +38,6 @@ size_t strftime(char * restrict output : count(maxsize), itype(restrict _Ptr)); #pragma CHECKED_SCOPE OFF + +#endif +#endif diff --git a/include/unistd_checked.h b/include/unistd_checked.h index 7a4b572..06a1289 100644 --- a/include/unistd_checked.h +++ b/include/unistd_checked.h @@ -7,6 +7,10 @@ #include +#ifndef __cplusplus +#ifndef __UNISTD_CHECKED_H +#define __UNISTD_CHECKED_H + #pragma CHECKED_SCOPE ON #if _POSIX_VERSION >= 200112L @@ -16,3 +20,6 @@ extern char ** environ : itype(_Nt_array_ptr<_Nt_array_ptr>); #endif #pragma CHECKED_SCOPE OFF + +#endif +#endif