commit 4c90efffccc66b478237a89962c41bf90e58190d
parent 7a1c347d2f6ee615d1b5f2856152ff32b4e69cff
Author: vaplv <vaplv@free.fr>
Date: Fri, 1 Jul 2016 11:26:03 +0200
Add and test the FUNC_NAME macro
Hold the name of the current function as a string.
Diffstat:
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/src/rsys.h b/src/rsys.h
@@ -358,6 +358,8 @@ typedef int res_T;
#define OFFSET_PTR(Ptr, Offset) (void*)((uintptr_t)(Ptr) + (Offset))
+#define FUNC_NAME __FUNCTION__
+
#define MEM_AREA_OVERLAP(A, SzA, B, SzB) \
((uintptr_t)(A) < (uintptr_t)(B) \
? (uintptr_t)(B) < ((uintptr_t)(A) + (SzA)) \
diff --git a/src/test_func_name.c b/src/test_func_name.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSys library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSys library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "rsys.h"
+#include <string.h>
+
+static void foo(void) { CHECK(strcmp(FUNC_NAME, "foo"), 0); }
+static void bar(void) { CHECK(strcmp(FUNC_NAME, "bar"), 0); }
+static void foo_bar(int i)
+{
+ (void)i;
+ CHECK(strcmp(FUNC_NAME, "foo_bar"), 0);
+}
+
+int
+main(int argc, char** argv)
+{
+ (void)argc, (void)argv;
+ CHECK(strcmp(FUNC_NAME, "main"), 0);
+ foo();
+ bar();
+ foo_bar(0);
+ return 0;
+}
+