Use extern C guards in all headers

The project uses a mix of C and C++ requiring
extern "C" guards from C++ code both within the
project & from C++ apps that use libcper. That
won't be required with this change.

Change-Id: I835dd05166732ca213c72eae2904815a8769599b
Signed-off-by: Karthik Rajagopalan <krajagopalan@nvidia.com>
diff --git a/base64.h b/base64.h
index 171f535..5e91efb 100644
--- a/base64.h
+++ b/base64.h
@@ -1,3 +1,10 @@
+#ifndef CPER_BASE64_H
+#define CPER_BASE64_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "edk/BaseTypes.h"
 
 /**
@@ -11,3 +18,9 @@
  * Caller is responsible for freeing the returned buffer.
  */
 CHAR8 *base64_encode(const UINT8 *src, INT32 len, INT32 *out_len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cper-parse.h b/cper-parse.h
index 752036e..e50d0cc 100644
--- a/cper-parse.h
+++ b/cper-parse.h
@@ -1,5 +1,10 @@
 #ifndef CPER_PARSE_H
 #define CPER_PARSE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 
 #define CPER_HEADER_VALID_BITFIELD_NAMES                                       \
@@ -36,4 +41,8 @@
 void ir_to_cper(json_object *ir, FILE *out);
 void ir_single_section_to_cper(json_object *ir, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/cper-utils.h b/cper-utils.h
index 22280fe..e4c14a1 100644
--- a/cper-utils.h
+++ b/cper-utils.h
@@ -4,6 +4,10 @@
 #define GUID_STRING_LENGTH 48
 #define TIMESTAMP_LENGTH   24
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "common-utils.h"
 #include <json.h>
 
@@ -42,4 +46,8 @@
 //The available severity types for CPER.
 extern const char *CPER_SEVERITY_TYPES[4];
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/edk/BaseTypes.h b/edk/BaseTypes.h
index 9958889..93320e4 100644
--- a/edk/BaseTypes.h
+++ b/edk/BaseTypes.h
@@ -11,6 +11,10 @@
 #ifndef CPER_BASETYPES_H
 #define CPER_BASETYPES_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 ///
 /// 8-byte unsigned value
 ///
@@ -98,4 +102,8 @@
 #define SIGNATURE_32(A, B, C, D)                                               \
 	(SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16))
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/edk/Cper.h b/edk/Cper.h
index 5fd5b48..f1bbdb1 100644
--- a/edk/Cper.h
+++ b/edk/Cper.h
@@ -9,11 +9,16 @@
   GUIDs defined in UEFI 2.7 Specification.

 

 **/
-#include "BaseTypes.h"
 
 #ifndef __CPER_GUID_H__
 #define __CPER_GUID_H__
 
+#include "BaseTypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #pragma pack(push, 1)
 
 #define EFI_ERROR_RECORD_SIGNATURE_START SIGNATURE_32('C', 'P', 'E', 'R')
@@ -1400,4 +1405,8 @@
 extern EFI_GUID gEfiNvidiaErrorSectionGuid;
 #pragma pack(pop)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/generator/cper-generate.h b/generator/cper-generate.h
index edbac36..042431f 100644
--- a/generator/cper-generate.h
+++ b/generator/cper-generate.h
@@ -1,10 +1,18 @@
 #ifndef CPER_GENERATE_H
 #define CPER_GENERATE_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <stdio.h>
 #include "../edk/BaseTypes.h"
 
 void generate_cper_record(char **types, UINT16 num_sections, FILE *out);
 void generate_single_section_record(char *type, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/generator/gen-utils.h b/generator/gen-utils.h
index 0ed28c2..1228253 100644
--- a/generator/gen-utils.h
+++ b/generator/gen-utils.h
@@ -1,5 +1,9 @@
-#ifndef GEN_UTILS_H
-#define GEN_UTILS_H
+#ifndef CPER_GEN_UTILS_H
+#define CPER_GEN_UTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #include <stdlib.h>
 #include "../edk/BaseTypes.h"
@@ -18,4 +22,8 @@
 void create_valid_error_section(UINT8 *start);
 UINT8 int_to_bcd(int value);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/generator/sections/gen-section.h b/generator/sections/gen-section.h
index be00b5f..d1987b9 100644
--- a/generator/sections/gen-section.h
+++ b/generator/sections/gen-section.h
@@ -1,6 +1,10 @@
 #ifndef GEN_SECTIONS_H
 #define GEN_SECTIONS_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <stdlib.h>
 #include "../../edk/Cper.h"
 
@@ -32,4 +36,8 @@
 extern CPER_GENERATOR_DEFINITION generator_definitions[];
 extern const size_t generator_definitions_len;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/json-schema.h b/json-schema.h
index 59fb58b..7dbbe48 100644
--- a/json-schema.h
+++ b/json-schema.h
@@ -1,5 +1,9 @@
-#ifndef JSON_SCHEMA_H
-#define JSON_SCHEMA_H
+#ifndef CPER_JSON_SCHEMA_H
+#define CPER_JSON_SCHEMA_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #include <json.h>
 
@@ -13,4 +17,8 @@
 void validate_schema_debug_enable();
 void validate_schema_debug_disable();
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-arm.h b/sections/cper-section-arm.h
index e865434..fdefeae 100644
--- a/sections/cper-section-arm.h
+++ b/sections/cper-section-arm.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_ARM_H
 #define CPER_SECTION_ARM_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -459,4 +463,8 @@
 json_object *cper_section_arm_to_ir(void *section);
 void ir_section_arm_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-ccix-per.h b/sections/cper-section-ccix-per.h
index 86e277c..69dbea2 100644
--- a/sections/cper-section-ccix-per.h
+++ b/sections/cper-section-ccix-per.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_CCIX_PER_H
 #define CPER_SECTION_CCIX_PER_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -24,4 +28,8 @@
 json_object *cper_section_ccix_per_to_ir(void *section);
 void ir_section_ccix_per_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-cxl-component.h b/sections/cper-section-cxl-component.h
index 69b9066..f3b8ad1 100644
--- a/sections/cper-section-cxl-component.h
+++ b/sections/cper-section-cxl-component.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_CXL_COMPONENT_H
 #define CPER_SECTION_CXL_COMPONENT_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -36,4 +40,8 @@
 json_object *cper_section_cxl_component_to_ir(void *section);
 void ir_section_cxl_component_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-cxl-protocol.h b/sections/cper-section-cxl-protocol.h
index 9339f57..e4854a3 100644
--- a/sections/cper-section-cxl-protocol.h
+++ b/sections/cper-section-cxl-protocol.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_CXL_PROTOCOL_H
 #define CPER_SECTION_CXL_PROTOCOL_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -67,4 +71,8 @@
 json_object *cper_section_cxl_protocol_to_ir(void *section);
 void ir_section_cxl_protocol_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-dmar-generic.h b/sections/cper-section-dmar-generic.h
index 035b25d..8e96ecf 100644
--- a/sections/cper-section-dmar-generic.h
+++ b/sections/cper-section-dmar-generic.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_DMAR_GENERIC_H
 #define CPER_SECTION_DMAR_GENERIC_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -68,4 +72,8 @@
 json_object *cper_section_dmar_generic_to_ir(void *section);
 void ir_section_dmar_generic_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-dmar-iommu.h b/sections/cper-section-dmar-iommu.h
index d15a9d1..2f990ab 100644
--- a/sections/cper-section-dmar-iommu.h
+++ b/sections/cper-section-dmar-iommu.h
@@ -1,10 +1,18 @@
 #ifndef CPER_SECTION_DMAR_IOMMU_H
 #define CPER_SECTION_DMAR_IOMMU_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
 json_object *cper_section_dmar_iommu_to_ir(void *section);
 void ir_section_dmar_iommu_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-dmar-vtd.h b/sections/cper-section-dmar-vtd.h
index f78b2d1..3c3a134 100644
--- a/sections/cper-section-dmar-vtd.h
+++ b/sections/cper-section-dmar-vtd.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_DMAR_VTD_H
 #define CPER_SECTION_DMAR_VTD_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -33,4 +37,8 @@
 json_object *cper_section_dmar_vtd_to_ir(void *section);
 void ir_section_dmar_vtd_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-firmware.h b/sections/cper-section-firmware.h
index eab0e99..858ee5d 100644
--- a/sections/cper-section-firmware.h
+++ b/sections/cper-section-firmware.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_FIRMWARE_H
 #define CPER_SECTION_FIRMWARE_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -20,4 +24,8 @@
 json_object *cper_section_firmware_to_ir(void *section);
 void ir_section_firmware_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-generic.h b/sections/cper-section-generic.h
index 765794e..7148cfd 100644
--- a/sections/cper-section-generic.h
+++ b/sections/cper-section-generic.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_GENERIC_H
 #define CPER_SECTION_GENERIC_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -65,4 +69,8 @@
 json_object *cper_section_generic_to_ir(void *section);
 void ir_section_generic_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-ia32x64.h b/sections/cper-section-ia32x64.h
index c020ff4..4670d48 100644
--- a/sections/cper-section-ia32x64.h
+++ b/sections/cper-section-ia32x64.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_IA32X64_H
 #define CPER_SECTION_IA32X64_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -108,4 +112,8 @@
 json_object *cper_section_ia32x64_to_ir(void *section);
 void ir_section_ia32x64_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-ipf.h b/sections/cper-section-ipf.h
index cf346ef..9e265db 100644
--- a/sections/cper-section-ipf.h
+++ b/sections/cper-section-ipf.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_IPF_H
 #define CPER_SECTION_IPF_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -69,4 +73,8 @@
 
 json_object *cper_section_ipf_to_ir(void *section);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-memory.h b/sections/cper-section-memory.h
index 5134f6e..4d293d8 100644
--- a/sections/cper-section-memory.h
+++ b/sections/cper-section-memory.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_MEMORY_H
 #define CPER_SECTION_MEMORY_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -54,4 +58,8 @@
 void ir_section_memory_to_cper(json_object *section, FILE *out);
 void ir_section_memory2_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-nvidia.h b/sections/cper-section-nvidia.h
index 973c3af..b05fdde 100644
--- a/sections/cper-section-nvidia.h
+++ b/sections/cper-section-nvidia.h
@@ -1,10 +1,18 @@
 #ifndef CPER_SECTION_NVIDIA_H
 #define CPER_SECTION_NVIDIA_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
 json_object *cper_section_nvidia_to_ir(void *section);
 void ir_section_nvidia_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-pci-bus.h b/sections/cper-section-pci-bus.h
index 6a959e4..93f61be 100644
--- a/sections/cper-section-pci-bus.h
+++ b/sections/cper-section-pci-bus.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_PCI_BUS_H
 #define CPER_SECTION_PCI_BUS_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -30,4 +34,8 @@
 json_object *cper_section_pci_bus_to_ir(void *section);
 void ir_section_pci_bus_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-pci-dev.h b/sections/cper-section-pci-dev.h
index 5326a8c..9d161c9 100644
--- a/sections/cper-section-pci-dev.h
+++ b/sections/cper-section-pci-dev.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_PCI_DEV_H
 #define CPER_SECTION_PCI_DEV_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -36,4 +40,8 @@
 json_object *cper_section_pci_dev_to_ir(void *section);
 void ir_section_pci_dev_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section-pcie.h b/sections/cper-section-pcie.h
index b0042c5..b2581e5 100644
--- a/sections/cper-section-pcie.h
+++ b/sections/cper-section-pcie.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_PCIE_H
 #define CPER_SECTION_PCIE_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include "../edk/Cper.h"
 
@@ -32,4 +36,8 @@
 json_object *cper_section_pcie_to_ir(void *section);
 void ir_section_pcie_to_cper(json_object *section, FILE *out);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/sections/cper-section.h b/sections/cper-section.h
index 4ec8650..71cf4b1 100644
--- a/sections/cper-section.h
+++ b/sections/cper-section.h
@@ -1,6 +1,10 @@
 #ifndef CPER_SECTION_H
 #define CPER_SECTION_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <json.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -17,4 +21,8 @@
 extern CPER_SECTION_DEFINITION section_definitions[];
 extern const size_t section_definitions_len;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/tests/base64_test.cpp b/tests/base64_test.cpp
index b762b8e..3fcb3af 100644
--- a/tests/base64_test.cpp
+++ b/tests/base64_test.cpp
@@ -1,6 +1,4 @@
-extern "C" {
 #include "base64.h"
-}
 
 #include "gtest/gtest.h"
 #include "gmock/gmock.h"
diff --git a/tests/ir-tests.cpp b/tests/ir-tests.cpp
index e8db79f..061f0a8 100644
--- a/tests/ir-tests.cpp
+++ b/tests/ir-tests.cpp
@@ -7,14 +7,12 @@
 #include <cctype>
 #include "gtest/gtest.h"
 #include "test-utils.hpp"
-extern "C" {
 #include <json.h>
 #include "../cper-parse.h"
 #include "../json-schema.h"
 #include "../generator/cper-generate.h"
 #include "../sections/cper-section.h"
 #include "../generator/sections/gen-section.h"
-}
 
 /*
 * Test templates.
diff --git a/tests/test-utils.cpp b/tests/test-utils.cpp
index 3837030..53aecd3 100644
--- a/tests/test-utils.cpp
+++ b/tests/test-utils.cpp
@@ -7,10 +7,9 @@
 #include <cstdio>
 #include <cstdlib>
 #include "test-utils.hpp"
-extern "C" {
+
 #include "../edk/BaseTypes.h"
 #include "../generator/cper-generate.h"
-}
 
 //Returns a ready-for-use memory stream containing a CPER record with the given sections inside.
 FILE *generate_record_memstream(const char **types, UINT16 num_types,