Skip to content

Commit

Permalink
Possible fix for non-MSVC windows compilers
Browse files Browse the repository at this point in the history
`_MSC_VER` is specific to MSVC, but there can be other compilers targeting
windows. Hopefully they do define `_WIN32`, so let's use that.

Refs: xkbcommon#305
Signed-off-by: Ran Benita <[email protected]>
  • Loading branch information
bluetech committed Apr 11, 2023
1 parent 13d4b7f commit f492b8f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "bench.h"
#include "../src/utils.h"

#ifndef _MSC_VER
#ifndef _WIN32
#include <sys/time.h>
#else
#include <windows.h>
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# define F_OK 0 /* Test for existence. */
#endif

#ifdef _MSC_VER
#ifdef _WIN32
# include <direct.h>
# include <io.h>
# ifndef S_ISDIR
Expand Down
6 changes: 3 additions & 3 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _MSC_VER
#ifdef _WIN32
#include <io.h>
#include <windows.h>
#else
Expand Down Expand Up @@ -171,7 +171,7 @@ test_makedir(const char *parent, const char *path)

dirname = asprintf_safe("%s/%s", parent, path);
assert(dirname);
#ifdef _MSC_VER
#ifdef _WIN32
err = _mkdir(dirname);
#else
err = mkdir(dirname, 0777);
Expand All @@ -184,7 +184,7 @@ test_makedir(const char *parent, const char *path)
char *
test_maketempdir(const char *template)
{
#ifdef _MSC_VER
#ifdef _WIN32
const char *basetmp = getenv("TMP");
if (basetmp == NULL) {
basetmp = getenv("TEMP");
Expand Down
2 changes: 1 addition & 1 deletion test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_compile_rules(struct xkb_context *context, const char *rules,
const char *options);


#ifdef _MSC_VER
#ifdef _WIN32
#define setenv(varname, value, overwrite) _putenv_s((varname), (value))
#define unsetenv(varname) _putenv_s(varname, "")
#endif
4 changes: 2 additions & 2 deletions tools/tools-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _MSC_VER
#ifdef _WIN32
#include <io.h>
#include <windows.h>
#else
Expand Down Expand Up @@ -160,7 +160,7 @@ tools_print_state_changes(enum xkb_state_component changed)
printf("]\n");
}

#ifdef _MSC_VER
#ifdef _WIN32
void
tools_disable_stdin_echo(void)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/tools-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tools_enable_stdin_echo(void);
int
tools_exec_command(const char *prefix, int argc, char **argv);

#ifdef _MSC_VER
#ifdef _WIN32
#define setenv(varname, value, overwrite) _putenv_s((varname), (value))
#define unsetenv(varname) _putenv_s(varname, "")
#endif

0 comments on commit f492b8f

Please sign in to comment.