commit 0f6e21860403a4051ee2748518d21f7c6769fab1
parent d7a8abb0333ea295235187d45538d0b18013b0dc
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 22 Jun 2026 11:27:00 +0200
Get rid of MS Windows compile flags
Solstice can no longer be compiled natively under MS Windows.
This step is just about cleaning up the code.
Diffstat:
5 files changed, 3 insertions(+), 265 deletions(-)
diff --git a/src/solstice.c b/src/solstice.c
@@ -30,18 +30,8 @@
#include <stdio.h>
#include <fcntl.h>
-#ifdef COMPILER_CL
- /* Wrap POSIX functions and constants */
- #include <io.h>
- #define open _open
- #define close _close
- #define fdopen _fdopen
- #define S_IRUSR S_IREAD
- #define S_IWUSR S_IWRITE
-#else
- /* open/close functions */
- #include <unistd.h>
-#endif
+/* open/close functions */
+#include <unistd.h>
#include <solstice/ssol.h>
@@ -53,11 +43,7 @@ log_err(const char* msg, void* ctx)
{
ASSERT(msg);
(void)ctx;
-#ifdef OS_WINDOWS
- fprintf(stderr, "error: %s", msg);
-#else
fprintf(stderr, "\x1b[31merror:\x1b[0m %s", msg);
-#endif
}
static void
@@ -65,11 +51,7 @@ log_warn(const char* msg, void* ctx)
{
ASSERT(msg);
(void)ctx;
-#ifdef OS_WINDOWS
- fprintf(stderr,"warning: %s", msg);
-#else
fprintf(stderr, "\x1b[33mwarning:\x1b[0m %s", msg);
-#endif
}
static void
@@ -402,13 +384,8 @@ load_data(struct solstice* solstice, const struct solstice_args* args)
}
name = args->input_filename;
} else if(!args->quiet) {
-#ifndef OS_WINDOWS
- fprintf(stderr,
- "Enter the solar facility data. Type ^D (i.e. CTRL+d) to stop:\n");
-#else
fprintf(stderr,
"Enter the solar facility data. Type ^Z (i.e. CTRL+z) to stop:\n");
-#endif
}
res = solparser_setup(solstice->parser, name, file);
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -25,12 +25,7 @@
#include <rsys/double3.h>
#include <rsys/stretchy_array.h>
-#ifdef COMPILER_CL
- #include <getopt.h>
- #define strtok_r strtok_s
-#else
- #include <unistd.h>
-#endif
+#include <unistd.h>
#include <string.h>
#include <time.h>
diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c
@@ -17,7 +17,6 @@
#define _XOPEN_SOURCE /* strptime support */
#include "solstice_args.h"
-#include "test_solstice_utils.h"
#include <rsys/double3.h>
#include <rsys/stretchy_array.h>
@@ -27,11 +26,6 @@
#include <limits.h>
#include <time.h>
-#ifdef COMPILER_CL
- #pragma warning(push)
- #pragma warning(disable:4706) /* Assignment within a condition */
-#endif
-
static char**
cmd_create(int dummy, ...)
{
@@ -58,10 +52,6 @@ cmd_create(int dummy, ...)
return cmd;
}
-#ifdef COMPILER_CL
- #pragma warning(pop)
-#endif
-
static void
cmd_delete(char** cmd)
{
diff --git a/src/test_solstice_simulation.c b/src/test_solstice_simulation.c
@@ -20,20 +20,10 @@
#include <rsys/math.h>
#include <rsys/double2.h>
-#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef COMPILER_CL
- /* Wrap POSIX functions and constants */
- #include <io.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #define fdopen _fdopen
- #define open _open
-#endif
-
enum side {
FRONT,
BACK
@@ -93,108 +83,6 @@ sundir_header [] = "#--- Sun direction:";
#define IS_NEW_BLOCK(Line, Header) (!strncmp((Line), (Header), strlen(Header)))
-
-#ifdef COMPILER_CL
-/* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright
- * (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc.
- *
- * The GNU C Library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version. */
-
-static const char letters [] =
-"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
-/* Generate a temporary file name based on TMPL. TMPL must match the
- * rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed
- * does not exist at the time of the call to mkstemp. TMPL is
- * overwritten with the result. */
-int
-mkstemp(char *tmpl)
-{
- size_t len;
- char *XXXXXX;
- static unsigned long long value;
- unsigned long long random_time_bits;
- unsigned int count;
- int fd = -1;
- int save_errno = errno;
-
- /* A lower bound on the number of temporary files to attempt to
- * generate. The maximum total number of temporary file names that
- * can exist for a given template is 62**6. It should never be
- * necessary to try all these combinations. Instead if a reasonable
- * number of names is tried (we define reasonable as 62**3) fail to
- * give the system administrator the chance to remove the problems. */
- #define ATTEMPTS_MIN (62 * 62 * 62)
-
- /* The number of times to attempt to generate a temporary file. To
- * conform to POSIX, this must be no smaller than TMP_MAX. */
- #if ATTEMPTS_MIN < TMP_MAX
- unsigned int attempts = TMP_MAX;
- #else
- unsigned int attempts = ATTEMPTS_MIN;
- #endif
-
- len = strlen(tmpl);
- if (len < 6 || strcmp(&tmpl[len - 6], "XXXXXX")) {
- errno = EINVAL;
- return -1;
- }
-
- /* This is where the Xs start. */
- XXXXXX = &tmpl[len - 6];
-
- /* Get some more or less random data. */
- {
- SYSTEMTIME stNow;
- FILETIME ftNow;
-
- /* get system time */
- GetSystemTime(&stNow);
- stNow.wMilliseconds = 500;
- if (!SystemTimeToFileTime(&stNow, &ftNow)) {
- errno = -1;
- return -1;
- }
-
- random_time_bits = (((unsigned long long)ftNow.dwHighDateTime << 32)
- | (unsigned long long)ftNow.dwLowDateTime);
- }
- value += random_time_bits ^ (unsigned long long)GetCurrentThreadId();
-
- for(count = 0; count < attempts; value += 7777, ++count) {
- unsigned long long v = value;
-
- /* Fill in the random bits. */
- XXXXXX[0] = letters[v % 62];
- v /= 62;
- XXXXXX[1] = letters[v % 62];
- v /= 62;
- XXXXXX[2] = letters[v % 62];
- v /= 62;
- XXXXXX[3] = letters[v % 62];
- v /= 62;
- XXXXXX[4] = letters[v % 62];
- v /= 62;
- XXXXXX[5] = letters[v % 62];
-
- fd = open(tmpl, O_RDWR|O_CREAT|O_EXCL, S_IREAD|S_IWRITE);
- if (fd >= 0) {
- errno = save_errno;
- return fd;
- }
- else if (errno != EEXIST)
- return -1;
- }
-
- /* We got out of the loop because we ran out of combinations to try. */
- errno = EEXIST;
- return -1;
-}
-#endif
-
static int
read_line(char* line, size_t max_line_len, FILE* stream)
{
diff --git a/src/test_solstice_simulation_time.c b/src/test_solstice_simulation_time.c
@@ -28,15 +28,6 @@
#include <stdlib.h>
#include <string.h>
-#ifdef COMPILER_CL
- /* Wrap POSIX functions and constants */
- #include <io.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #define fdopen _fdopen
- #define open _open
-#endif
-
enum side {
FRONT,
BACK
@@ -96,111 +87,8 @@ sundir_header [] = "#--- Sun direction:";
static const char
suntime_header [] = "#--- Sun location and time:";
-
#define IS_NEW_BLOCK(Line, Header) (!strncmp((Line), (Header), strlen(Header)))
-
-#ifdef COMPILER_CL
-/* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright
- * (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc.
- *
- * The GNU C Library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version. */
-
-static const char letters [] =
-"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
-/* Generate a temporary file name based on TMPL. TMPL must match the
- * rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed
- * does not exist at the time of the call to mkstemp. TMPL is
- * overwritten with the result. */
-int
-mkstemp(char *tmpl)
-{
- size_t len;
- char *XXXXXX;
- static unsigned long long value;
- unsigned long long random_time_bits;
- unsigned int count;
- int fd = -1;
- int save_errno = errno;
-
- /* A lower bound on the number of temporary files to attempt to
- * generate. The maximum total number of temporary file names that
- * can exist for a given template is 62**6. It should never be
- * necessary to try all these combinations. Instead if a reasonable
- * number of names is tried (we define reasonable as 62**3) fail to
- * give the system administrator the chance to remove the problems. */
- #define ATTEMPTS_MIN (62 * 62 * 62)
-
- /* The number of times to attempt to generate a temporary file. To
- * conform to POSIX, this must be no smaller than TMP_MAX. */
- #if ATTEMPTS_MIN < TMP_MAX
- unsigned int attempts = TMP_MAX;
- #else
- unsigned int attempts = ATTEMPTS_MIN;
- #endif
-
- len = strlen(tmpl);
- if (len < 6 || strcmp(&tmpl[len - 6], "XXXXXX")) {
- errno = EINVAL;
- return -1;
- }
-
- /* This is where the Xs start. */
- XXXXXX = &tmpl[len - 6];
-
- /* Get some more or less random data. */
- {
- SYSTEMTIME stNow;
- FILETIME ftNow;
-
- /* get system time */
- GetSystemTime(&stNow);
- stNow.wMilliseconds = 500;
- if (!SystemTimeToFileTime(&stNow, &ftNow)) {
- errno = -1;
- return -1;
- }
-
- random_time_bits = (((unsigned long long)ftNow.dwHighDateTime << 32)
- | (unsigned long long)ftNow.dwLowDateTime);
- }
- value += random_time_bits ^ (unsigned long long)GetCurrentThreadId();
-
- for(count = 0; count < attempts; value += 7777, ++count) {
- unsigned long long v = value;
-
- /* Fill in the random bits. */
- XXXXXX[0] = letters[v % 62];
- v /= 62;
- XXXXXX[1] = letters[v % 62];
- v /= 62;
- XXXXXX[2] = letters[v % 62];
- v /= 62;
- XXXXXX[3] = letters[v % 62];
- v /= 62;
- XXXXXX[4] = letters[v % 62];
- v /= 62;
- XXXXXX[5] = letters[v % 62];
-
- fd = open(tmpl, O_RDWR|O_CREAT|O_EXCL, S_IREAD|S_IWRITE);
- if (fd >= 0) {
- errno = save_errno;
- return fd;
- }
- else if (errno != EEXIST)
- return -1;
- }
-
- /* We got out of the loop because we ran out of combinations to try. */
- errno = EEXIST;
- return -1;
-}
-#endif
-
static int
read_line(char* line, size_t max_line_len, FILE* stream)
{