aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-13 04:49:15 +0200
committerMattias Andrée <maandree@operamail.com>2015-10-13 04:49:15 +0200
commitec1f0e33c90c4b99bb4dedbf226d48906fb5dba9 (patch)
treed1bb1b5ad780fdad13851e5d265816c838aae6c8
parentinfo typo (diff)
downloadslibc-ec1f0e33c90c4b99bb4dedbf226d48906fb5dba9.tar.gz
slibc-ec1f0e33c90c4b99bb4dedbf226d48906fb5dba9.tar.bz2
slibc-ec1f0e33c90c4b99bb4dedbf226d48906fb5dba9.tar.xz
CPP directive __func__ requires C99
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--include/assert.h21
-rw-r--r--src/assert.c17
2 files changed, 23 insertions, 15 deletions
diff --git a/include/assert.h b/include/assert.h
index 4e8bc2f..c4faa58 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -38,9 +38,12 @@
*/
#ifdef NDEBUG
# define assert(expression) ((void)0)
-#else
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define assert(expression) \
((void)((expression) ? 0 : (__assert_fail(#expression, 0, __FILE__, __LINE__, __func__), 0)))
+#else
+# define assert(expression) \
+ ((void)((expression) ? 0 : (__assert_fail(#expression, 0, __FILE__, __LINE__, NULL), 0)))
#endif
@@ -58,9 +61,12 @@
# endif
# ifdef NDEBUG
# define assert_perror(errnum) ((void)0)
-# else
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define assert_perror(errnum) \
((void)((errnum == 0) ? 0 : (__assert_fail(NULL, errnum, __FILE__, __LINE__, __func__), 0)))
+# else
+# define assert_perror(errnum) \
+ ((void)((errnum == 0) ? 0 : (__assert_fail(NULL, errnum, __FILE__, __LINE__, NULL), 0)))
# endif
#endif
@@ -86,11 +92,12 @@
/**
* The function that is called if an assertion fails.
*
- * @param expression The expression that failed, `NULL` if `assert_perror` failed
- * @param errnum The code of the fatal error, 0 if `assert` failed
- * @param file The filename of the source cose whence the assertion was made
- * @param line The line in the source code whence the assertion was made
- * @param func The function in the source code whence the assertion was made
+ * @param expression The expression that failed, `NULL` if `assert_perror` failed.
+ * @param errnum The code of the fatal error, 0 if `assert` failed.
+ * @param file The filename of the source cose whence the assertion was made.
+ * @param line The line in the source code whence the assertion was made.
+ * @param func The function in the source code whence the assertion was made,
+ * `NULL` if unknown (C99 is required.)
*/
__noreturn void __assert_fail(const char*, int, const char*, int, const char*)
__GCC_ONLY(__attribute__((nonnull(3, 5))));
diff --git a/src/assert.c b/src/assert.c
index ffd61a3..8e99052 100644
--- a/src/assert.c
+++ b/src/assert.c
@@ -28,11 +28,12 @@
/**
* The function that is called if an assertion fails.
*
- * @param expression The expression that failed, `NULL` if `assert_perror` failed
- * @param errnum The code of the fatal error, 0 if `assert` failed
- * @param file The filename of the source cose whence the assertion was made
- * @param line The line in the source code whence the assertion was made
- * @param func The function in the source code whence the assertion was made
+ * @param expression The expression that failed, `NULL` if `assert_perror` failed.
+ * @param errnum The code of the fatal error, 0 if `assert` failed.
+ * @param file The filename of the source cose whence the assertion was made.
+ * @param line The line in the source code whence the assertion was made.
+ * @param func The function in the source code whence the assertion was made,
+ * `NULL` if unknown (C99 is required.)
*/
void __assert_fail(const char* expression, int errnum, const char* file, int line, const char* func)
{
@@ -42,14 +43,14 @@ void __assert_fail(const char* expression, int errnum, const char* file, int lin
_("%(\033[00;01m%)%s%(\033[00m%): "
"%(\033[31m%)assertion error%(\033[00m%) "
"at line %(\033[33m%)%i%(\033[00m%) "
- "of file %(\033[35m%)%s%(\033[00m%), "
- "function %(\033[1;34m%)%s%(\033[00m%): "
+ "of file %(\033[35m%)%s%(\033[00m%)"
+ "%(, function %(\033[1;34m%)%s%(\033[00m%)%): "
"%(\033[31m%)%(exression failed: %)%s%(\033[00m%)\n"),
tty, program_invocation_name, tty,
tty, tty,
tty, line, tty,
tty, file, tty,
- tty, func, tty,
+ func != NULL, tty, func, tty,
tty, expression != NULL, (expression ? expression : strerror(errnum)), tty);
fflush(NULL); /* Flush all streams. */