diff --git a/htslib/bgzf.h b/htslib/bgzf.h index 8e6b9b17ed..b3318af9ad 100644 --- a/htslib/bgzf.h +++ b/htslib/bgzf.h @@ -35,6 +35,13 @@ #include "hts_defs.h" +// Ensure ssize_t exists within this header. All #includes must precede this, +// and ssize_t must be undefined again at the end of this header. +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined ssize_t +#define HTSLIB_SSIZE_T +#define ssize_t intptr_t +#endif + #ifdef __cplusplus extern "C" { #endif @@ -450,4 +457,9 @@ typedef struct BGZF BGZF; } #endif +#ifdef HTSLIB_SSIZE_T +#undef HTSLIB_SSIZE_T +#undef ssize_t +#endif + #endif diff --git a/htslib/hfile.h b/htslib/hfile.h index 987acb7c8f..5624ba6d9e 100644 --- a/htslib/hfile.h +++ b/htslib/hfile.h @@ -32,6 +32,13 @@ DEALINGS IN THE SOFTWARE. */ #include "hts_defs.h" +// Ensure ssize_t exists within this header. All #includes must precede this, +// and ssize_t must be undefined again at the end of this header. +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined ssize_t +#define HTSLIB_SSIZE_T +#define ssize_t intptr_t +#endif + #ifdef __cplusplus extern "C" { #endif @@ -368,4 +375,9 @@ int hfile_has_plugin(const char *name); } #endif +#ifdef HTSLIB_SSIZE_T +#undef HTSLIB_SSIZE_T +#undef ssize_t +#endif + #endif diff --git a/htslib/hts_os.h b/htslib/hts_os.h index b71cb89e77..66a8d0571e 100644 --- a/htslib/hts_os.h +++ b/htslib/hts_os.h @@ -77,4 +77,10 @@ extern int is_cygpty(int fd); #define random rand #endif +/* MSVC does not provide ssize_t in its . This ensures the type + is available (unless suppressed by defining HTS_NO_SSIZE_T first). */ +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined HTS_NO_SSIZE_T && !defined ssize_t +#define ssize_t intptr_t +#endif + #endif // HTSLIB_HTS_OS_H diff --git a/htslib/knetfile.h b/htslib/knetfile.h index da9cdc5e8e..57a0113a31 100644 --- a/htslib/knetfile.h +++ b/htslib/knetfile.h @@ -44,6 +44,13 @@ #define netclose(fd) closesocket(fd) #endif +// Ensure ssize_t exists within this header. All #includes must precede this, +// and ssize_t must be undefined again at the end of this header. +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined ssize_t +#define HTSLIB_SSIZE_T +#define ssize_t intptr_t +#endif + // FIXME: currently I/O is unbuffered #define KNF_TYPE_LOCAL 1 @@ -102,4 +109,9 @@ extern "C" { } #endif +#ifdef HTSLIB_SSIZE_T +#undef HTSLIB_SSIZE_T +#undef ssize_t +#endif + #endif diff --git a/htslib/kstring.h b/htslib/kstring.h index 150757ca68..7bc7e414e5 100644 --- a/htslib/kstring.h +++ b/htslib/kstring.h @@ -55,6 +55,13 @@ #endif #endif +// Ensure ssize_t exists within this header. All #includes must precede this, +// and ssize_t must be undefined again at the end of this header. +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined ssize_t +#define HTSLIB_SSIZE_T +#define ssize_t intptr_t +#endif + /* kstring_t is a simple non-opaque type whose fields are likely to be * used directly by user code (but see also ks_str() and ks_len() below). * A kstring_t object is initialised by either of @@ -396,4 +403,9 @@ static inline int *ksplit(kstring_t *s, int delimiter, int *n) return offsets; } +#ifdef HTSLIB_SSIZE_T +#undef HTSLIB_SSIZE_T +#undef ssize_t +#endif + #endif diff --git a/htslib/sam.h b/htslib/sam.h index 79ac26e4b5..65cd123e2d 100644 --- a/htslib/sam.h +++ b/htslib/sam.h @@ -33,6 +33,13 @@ DEALINGS IN THE SOFTWARE. */ #include "hts.h" #include "hts_endian.h" +// Ensure ssize_t exists within this header. All #includes must precede this, +// and ssize_t must be undefined again at the end of this header. +#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined ssize_t +#define HTSLIB_SSIZE_T +#define ssize_t intptr_t +#endif + #ifdef __cplusplus extern "C" { #endif @@ -2266,4 +2273,9 @@ int bam_mods_at_qpos(const bam1_t *b, int qpos, hts_base_mod_state *state, } #endif +#ifdef HTSLIB_SSIZE_T +#undef HTSLIB_SSIZE_T +#undef ssize_t +#endif + #endif