Skip to content

Commit 2a1c94b

Browse files
committed
MSVC compatible
1 parent 8770e9e commit 2a1c94b

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

GKlibSystem.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ endif(HAVE_GETLINE)
7171

7272
# Custom check for TLS.
7373
if(MSVC)
74-
list(APPEND GKlib_COPTIONS __thread=__declspec(thread))
75-
76-
# This if checks if that value is cached or not.
77-
if("${HAVE_THREADLOCALSTORAGE}" MATCHES "^${HAVE_THREADLOCALSTORAGE}$")
74+
if(NOT DEFINED HAVE_THREADLOCALSTORAGE)
7875
message(CHECK_START "checking for thread-local storage")
7976
try_compile(HAVE_THREADLOCALSTORAGE
8077
${CMAKE_BINARY_DIR}

io.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ This file contains various functions that perform I/O.
1616
#undef _GNU_SOURCE
1717
#endif
1818

19+
#ifdef _MSC_VER
20+
#include <io.h>
21+
#endif
22+
1923
#include <GKlib.h>
2024

2125
/*************************************************************************
@@ -48,7 +52,7 @@ void gk_fclose(FILE *fp)
4852

4953

5054
/*************************************************************************/
51-
/*! This function is a wrapper around the read() function that ensures
55+
/*! This function is a wrapper around the read() function that ensures
5256
that all data is been read, by issuing multiple read requests.
5357
The only time when not 'count' items are read is when the EOF has been
5458
reached.
@@ -71,7 +75,7 @@ ssize_t gk_read(int fd, void *vbuf, size_t count)
7175

7276

7377
/*************************************************************************/
74-
/*! This function is a wrapper around the write() function that ensures
78+
/*! This function is a wrapper around the write() function that ensures
7579
that all data is been written, by issueing multiple write requests.
7680
*/
7781
/*************************************************************************/
@@ -94,7 +98,7 @@ ssize_t gk_write(int fd, void *vbuf, size_t count)
9498
/*************************************************************************/
9599
/*! This function is the GKlib implementation of glibc's getline()
96100
function.
97-
\returns -1 if the EOF has been reached, otherwise it returns the
101+
\returns -1 if the EOF has been reached, otherwise it returns the
98102
number of bytes read.
99103
*/
100104
/*************************************************************************/
@@ -107,7 +111,7 @@ ssize_t gk_getline(char **lineptr, size_t *n, FILE *stream)
107111
int ch;
108112

109113
if (feof(stream))
110-
return -1;
114+
return -1;
111115

112116
/* Initial memory allocation if *lineptr is NULL */
113117
if (*lineptr == NULL || *n == 0) {
@@ -121,11 +125,11 @@ ssize_t gk_getline(char **lineptr, size_t *n, FILE *stream)
121125
(*lineptr)[i++] = (char)ch;
122126

123127
/* reallocate memory if reached at the end of the buffer. The +1 is for '\0' */
124-
if (i+1 == *n) {
128+
if (i+1 == *n) {
125129
*n = 2*(*n);
126130
*lineptr = gk_realloc(*lineptr, (*n)*sizeof(char), "gk_getline: lineptr");
127131
}
128-
132+
129133
if (ch == '\n')
130134
break;
131135
}
@@ -377,7 +381,7 @@ int32_t *gk_i32readfilebin(char *fname, size_t *r_nelmnts)
377381
array = gk_i32malloc(nelmnts, "gk_i32readfilebin: array");
378382

379383
fpin = gk_fopen(fname, "rb", "gk_i32readfilebin");
380-
384+
381385
if (fread(array, sizeof(int32_t), nelmnts, fpin) != nelmnts) {
382386
gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts);
383387
gk_free((void **)&array, LTERM);
@@ -444,7 +448,7 @@ int64_t *gk_i64readfilebin(char *fname, size_t *r_nelmnts)
444448
array = gk_i64malloc(nelmnts, "gk_i64readfilebin: array");
445449

446450
fpin = gk_fopen(fname, "rb", "gk_i64readfilebin");
447-
451+
448452
if (fread(array, sizeof(int64_t), nelmnts, fpin) != nelmnts) {
449453
gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts);
450454
gk_free((void **)&array, LTERM);
@@ -511,7 +515,7 @@ ssize_t *gk_zreadfilebin(char *fname, size_t *r_nelmnts)
511515
array = gk_zmalloc(nelmnts, "gk_zreadfilebin: array");
512516

513517
fpin = gk_fopen(fname, "rb", "gk_zreadfilebin");
514-
518+
515519
if (fread(array, sizeof(ssize_t), nelmnts, fpin) != nelmnts) {
516520
gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts);
517521
gk_free((void **)&array, LTERM);
@@ -578,7 +582,7 @@ float *gk_freadfilebin(char *fname, size_t *r_nelmnts)
578582
array = gk_fmalloc(nelmnts, "gk_freadfilebin: array");
579583

580584
fpin = gk_fopen(fname, "rb", "gk_freadfilebin");
581-
585+
582586
if (fread(array, sizeof(float), nelmnts, fpin) != nelmnts) {
583587
gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts);
584588
gk_free((void **)&array, LTERM);
@@ -645,7 +649,7 @@ double *gk_dreadfilebin(char *fname, size_t *r_nelmnts)
645649
array = gk_dmalloc(nelmnts, "gk_dreadfilebin: array");
646650

647651
fpin = gk_fopen(fname, "rb", "gk_dreadfilebin");
648-
652+
649653
if (fread(array, sizeof(double), nelmnts, fpin) != nelmnts) {
650654
gk_errexit(SIGERR, "Failed to read the number of words requested. %zd\n", nelmnts);
651655
gk_free((void **)&array, LTERM);
@@ -678,4 +682,3 @@ size_t gk_dwritefilebin(char *fname, size_t n, double *a)
678682

679683
return fsize;
680684
}
681-

0 commit comments

Comments
 (0)