Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a definition of ssize_t when compiling with MSVC [more robust alternative to #1375] #1377

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions htslib/bgzf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_DEFINED && !defined ssize_t
#define HTSLIB_SSIZE_T
#define ssize_t intptr_t
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -450,4 +457,9 @@ typedef struct BGZF BGZF;
}
#endif

#ifdef HTSLIB_SSIZE_T
#undef HTSLIB_SSIZE_T
#undef ssize_t
#endif

#endif
12 changes: 12 additions & 0 deletions htslib/hfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_DEFINED && !defined ssize_t
#define HTSLIB_SSIZE_T
#define ssize_t intptr_t
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions htslib/hts_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ extern int is_cygpty(int fd);
#define random rand
#endif

/* MSVC does not provide ssize_t in its <sys/types.h>. This ensures the type
is available (unless suppressed by defining HTS_NO_SSIZE_T first). */
#if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined _SSIZE_T_DEFINED && !defined HTS_NO_SSIZE_T && !defined ssize_t
#define ssize_t intptr_t
#endif

#endif // HTSLIB_HTS_OS_H
12 changes: 12 additions & 0 deletions htslib/knetfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down Expand Up @@ -102,4 +109,9 @@ extern "C" {
}
#endif

#ifdef HTSLIB_SSIZE_T
#undef HTSLIB_SSIZE_T
#undef ssize_t
#endif

#endif
12 changes: 12 additions & 0 deletions htslib/kstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions htslib/sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_DEFINED && !defined ssize_t
#define HTSLIB_SSIZE_T
#define ssize_t intptr_t
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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