From: Michal MalĂ˝ Date: Fri, 1 Aug 2014 17:01:32 +0000 (+0200) Subject: Fix build on VC11 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=3485667bea79c26df2e106d60b52ce484006e129;p=libHPCS.git Fix build on VC11 --- diff --git a/libhpcs.c b/libhpcs.c index 034294f..a06ac4e 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -1,6 +1,10 @@ #include "libhpcs.h" #include "libhpcs_p.h" -#include + +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -71,7 +75,7 @@ void hpcs_free(struct HPCS_MeasuredData* const mdata) enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* mdata) { - FILE* datafile; + FILE* datafile; enum HPCS_ParseCode pret; enum HPCS_RetCode ret; @@ -459,7 +463,7 @@ static enum HPCS_ParseCode read_date(FILE* datafile, struct HPCS_Date* date) return PARSE_OK; } -static uint8_t month_to_number(const char* const month) +static uint8_t month_to_number(const char* month) { if (strcmp(MON_JAN_STR, month) == 0) return 1; @@ -493,7 +497,7 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair const HPCS_step step, const double sampling_rate) { const double time_step = 1 / (60 * sampling_rate); - size_t alloc_size = 60 * sampling_rate; + size_t alloc_size = (size_t)((60 * sampling_rate) + 0.5); bool read_file = true; double value = 0; double time = 0; @@ -549,7 +553,7 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair /* Expand storage if there is more data than we can store */ if (alloc_size == data_segments_read) { struct HPCS_TVPair* nptr; - alloc_size += 60 * sampling_rate; + alloc_size += (size_t)((60 * sampling_rate) + 0.5); nptr = realloc(*pairs, sizeof(struct HPCS_TVPair) * alloc_size); if (nptr == NULL) { @@ -657,3 +661,7 @@ static enum HPCS_ParseCode read_string_at_offset(FILE* datafile, const HPCS_offs *result = string; return PARSE_OK; } + +#ifdef __cplusplus +} +#endif diff --git a/libhpcs.h b/libhpcs.h index 04e9042..c54fde9 100644 --- a/libhpcs.h +++ b/libhpcs.h @@ -71,7 +71,7 @@ struct HPCS_MeasuredData { LIBHPCS_API struct HPCS_MeasuredData* LIBHPCS_CC hpcs_alloc(); LIBHPCS_API void LIBHPCS_CC hpcs_free(struct HPCS_MeasuredData* const mdata); LIBHPCS_API char* LIBHPCS_CC hpcs_error_to_string(const enum HPCS_RetCode); -LIBHPCS_API enum HPCS_RetCode LIBHPCS_CC hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata); +LIBHPCS_API enum HPCS_RetCode LIBHPCS_CC hpcs_read_file(const char* filename, struct HPCS_MeasuredData* mdata); #ifdef __cplusplus } diff --git a/libhpcs_p.h b/libhpcs_p.h index 638f13a..f9e6d4c 100644 --- a/libhpcs_p.h +++ b/libhpcs_p.h @@ -1,11 +1,14 @@ -#ifdef _MSC_VER -typedef int uint8_t +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_MSC_VER) +typedef int bool; #define true 1 #define false 0 #else #include #endif - #include enum HPCS_DataCheckCode { @@ -105,14 +108,14 @@ const char* HPCS_E_UNKNOWN_TYPE_STR = "The specified file contains an unknown ty const char* HPCS_E__UNKNOWN_EC_STR = "Unknown error code."; static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_FileType* file_type, const bool p_means_pressure); -static enum HPCS_DataCheckCode check_for_marker(const char* const segment, size_t* const next_marker_idx); +static enum HPCS_DataCheckCode check_for_marker(const char* segment, size_t* const next_marker_idx); static HPCS_step guess_current_step(const struct HPCS_MeasuredData* mdata); static HPCS_step guess_elec_sigstep(const struct HPCS_MeasuredData *mdata); static bool guess_p_meaning(const struct HPCS_MeasuredData* mdata); static void guess_sampling_rate(struct HPCS_MeasuredData* mdata); static enum HPCS_ParseCode read_dad_wavelength(FILE* datafile, struct HPCS_Wavelength* const measured, struct HPCS_Wavelength* const reference); -static uint8_t month_to_number(const char* const month); -static enum HPCS_ParseCode read_date(FILE* datafile, struct HPCS_Date* const date); +static uint8_t month_to_number(const char* month); +static enum HPCS_ParseCode read_date(FILE* datafile, struct HPCS_Date* date); static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pairs, size_t* pairs_count, const HPCS_step step, const double sampling_rate); static enum HPCS_ParseCode read_sampling_rate(FILE* datafile, double* sampling_rate); @@ -148,3 +151,7 @@ void reverse_endianness(char* bytes, size_t sz) { #define PR_DEBUGF(fmt, msg) ((void)0) #define PR_DEBUG(msg) ((void)0) #endif + +#ifdef __cplusplus +} +#endif