--- ray/src/util/rmatrix.c 2015/07/22 04:29:56 2.16 +++ ray/src/util/rmatrix.c 2016/03/06 01:13:18 2.20 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rmatrix.c,v 2.16 2015/07/22 04:29:56 greg Exp $"; +static const char RCSid[] = "$Id: rmatrix.c,v 2.20 2016/03/06 01:13:18 schorsch Exp $"; #endif /* * General matrix operations. @@ -9,8 +9,9 @@ static const char RCSid[] = "$Id: rmatrix.c,v 2.16 201 #include #include #include +#include "platform.h" #include "resolu.h" -#include "rtprocess.h" +#include "paths.h" #include "rmatrix.h" static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; @@ -111,9 +112,7 @@ static int rmx_load_ascii(RMATRIX *rm, FILE *fp) { int i, j, k; -#ifdef _WIN32 - _setmode(fileno(fp), _O_TEXT); -#endif + for (i = 0; i < rm->nrows; i++) for (j = 0; j < rm->ncols; j++) for (k = 0; k < rm->ncomp; k++) @@ -195,13 +194,13 @@ rmx_load(const char *inspec) if (inspec == NULL) { /* reading from stdin? */ inspec = ""; -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) _setmode(fileno(stdin), _O_BINARY); #endif } else if (inspec[0] == '!') { if ((fp = popen(inspec+1, "r")) == NULL) return(NULL); -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) _setmode(fileno(fp), _O_BINARY); #endif } else { @@ -216,6 +215,7 @@ rmx_load(const char *inspec) return(NULL); dnew = rmx_from_cmatrix(cm); cm_free(cm); + dnew->dtype = DTascii; return(dnew); } /* else open it ourselves */ @@ -253,6 +253,9 @@ rmx_load(const char *inspec) dnew->info = dinfo.info; switch (dinfo.dtype) { case DTascii: +#if defined(_WIN32) || defined(_WIN64) + _setmode(fileno(fp), _O_TEXT); +#endif if (!rmx_load_ascii(dnew, fp)) goto loaderr; dnew->dtype = DTascii; /* should leave double? */ @@ -300,9 +303,7 @@ static int rmx_write_ascii(const RMATRIX *rm, FILE *fp) { int i, j, k; -#ifdef _WIN32 - _setmode(fileno(fp), _O_TEXT); -#endif + for (i = 0; i < rm->nrows; i++) { for (j = 0; j < rm->ncols; j++) { for (k = 0; k < rm->ncomp; k++) @@ -385,6 +386,9 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp) if ((rm == NULL) | (fp == NULL)) return(0); +#ifdef getc_unlocked + flockfile(fp); +#endif /* complete header */ if (rm->info) fputs(rm->info, fp); @@ -429,6 +433,9 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp) return(0); } ok &= (fflush(fp) == 0); +#ifdef getc_unlocked + funlockfile(fp); +#endif rmx_free(mydm); return(ok); }