Skip to content

Commit

Permalink
Support for MSVC. Use _WIN32 instead of __MINGW32__
Browse files Browse the repository at this point in the history
This is not a search and replace of __MING32__ with _WIN32.
There are places where __MINGW32__ is still used and all changes are
tested with MSVC 2019 compiler. Although, this commit alone will not work
on MSVC because there are plenty of other things to be done which are
seperated into multiple PR. PR #289 is the one that "works" on MSVC and
unix as well. But that contains too many changes which shouldn't in a single
PR. Even though this PR alone won't compile GRASS GIS on MSVC, it sure will
not break existing compilers which I think is very important.

Complete support for MSVC will be ready after 2/3 PRs

#289
  • Loading branch information
rkanavath committed Feb 17, 2020
1 parent 7aed313 commit 87f6735
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 64 deletions.
2 changes: 1 addition & 1 deletion db/drivers/odbc/odbc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _ODBC_H_
#define _ODBC_H_

#ifdef __MINGW32__
#ifdef _WIN32
#include <windows.h>
#endif

Expand Down
6 changes: 3 additions & 3 deletions include/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static const char *GRASS_copyright __attribute__ ((unused))

/*! \brief Cross-platform Newline Character */
#define NEWLINE '\n'
#ifdef __MINGW32__
#ifdef _WIN32
# define HOST_NEWLINE "\r\n"
#else
# define HOST_NEWLINE "\n"
Expand Down Expand Up @@ -194,7 +194,7 @@ static const char *GRASS_copyright __attribute__ ((unused))

/* Cross-platform Directory Separator Character and null device stuff */
#define GRASS_DIRSEP '/'
#ifdef __MINGW32__
#ifdef _WIN32
# define HOST_DIRSEP '\\'
# define G_DEV_NULL "NUL:"
#else
Expand Down Expand Up @@ -593,7 +593,7 @@ typedef float FCELL;
#if HAVE_INT64_T
#include <sys/types.h>
typedef int64_t grass_int64;
#elif defined(__MINGW32__)
#elif defined(_WIN32)
typedef __int64 grass_int64;
#elif HAVE_LONG_LONG_INT
typedef long long int grass_int64;
Expand Down
5 changes: 3 additions & 2 deletions include/iostream/rtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
#ifndef RTIMER_H
#define RTIMER_H

#ifdef __MINGW32__
#ifdef _WIN32

#include <time.h>
#include <stdio.h>
#include <string.h>
#ifdef __MINGW32__
#include <strings.h>

#endif
typedef struct {
time_t tv1, tv2;
} Rtimer;
Expand Down
4 changes: 2 additions & 2 deletions lib/cairodriver/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#endif

#include <unistd.h>
#ifndef __MINGW32__
#ifndef _WIN32
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -390,7 +390,7 @@ static int ends_with(const char *string, const char *suffix)

static void map_file(void)
{
#ifndef __MINGW32__
#ifndef _WIN32
size_t size = HEADER_SIZE + ca.width * ca.height * sizeof(unsigned int);
void *ptr;
int fd;
Expand Down
4 changes: 2 additions & 2 deletions lib/calc/calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static RETSIGTYPE handle_fpe(int n)

void pre_exec(void)
{
#ifndef __MINGW32__
#ifndef _WIN32
#ifdef SIGFPE
struct sigaction act;

Expand All @@ -38,7 +38,7 @@ void pre_exec(void)

void post_exec(void)
{
#ifndef __MINGW32__
#ifndef _WIN32
#ifdef SIGFPE
struct sigaction act;

Expand Down
6 changes: 3 additions & 3 deletions lib/db/dbmi_base/dbmscap.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ dbDbmscap *db_read_dbmscap(void)
/* START OF NEW CODE FOR SEARCH IN $(GISBASE)/driver/db/ */

/* opend db drivers directory */
#ifdef __MINGW32__
#ifdef _WIN32
dirpath = G_malloc(strlen("\\driver\\db\\") + strlen(G_gisbase()) + 1);
sprintf(dirpath, "%s\\driver\\db\\", G_gisbase());
G_convert_dirseps_to_host(dirpath);
Expand All @@ -182,7 +182,7 @@ dbDbmscap *db_read_dbmscap(void)
|| (strcmp(ent->d_name, "..") == 0))
continue;

#ifdef __MINGW32__
#ifdef _WIN32
/* skip manifest files on Windows */
if (strstr(ent->d_name, ".manifest"))
continue;
Expand All @@ -191,7 +191,7 @@ dbDbmscap *db_read_dbmscap(void)
/* Remove '.exe' from name (windows extension) */
name = G_str_replace(ent->d_name, ".exe", "");

#ifdef __MINGW32__
#ifdef _WIN32
dirpath = G_malloc(strlen("\\driver\\db\\")
+ strlen(G_gisbase()) + strlen(ent->d_name) + 1);
sprintf(dirpath, "%s\\driver\\db\\%s", G_gisbase(), ent->d_name);
Expand Down
6 changes: 3 additions & 3 deletions lib/db/dbmi_client/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdlib.h>
#include <unistd.h>

#ifdef __MINGW32__
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#include <fcntl.h>
Expand All @@ -30,7 +30,7 @@

static void close_on_exec(int fd)
{
#ifndef __MINGW32__
#ifndef _WIN32
int flags = fcntl(fd, F_GETFD);
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
#endif
Expand Down Expand Up @@ -129,7 +129,7 @@ dbDriver *db_start_driver(const char *name)

/* run the driver as a child process and create pipes to its stdin, stdout */

#ifdef __MINGW32__
#ifdef _WIN32
#define pipe(fds) _pipe(fds, 250000, _O_BINARY | _O_NOINHERIT)
#endif

Expand Down
2 changes: 1 addition & 1 deletion lib/gis/mapset_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int G__make_mapset_element_misc(const char *dir, const char *name)

static int check_owner(const struct stat *info)
{
#if defined(__MINGW32__) || defined(SKIP_MAPSET_OWN_CHK)
#if defined(_WIN32) || defined(SKIP_MAPSET_OWN_CHK)
return 1;
#else
const char *check = getenv("GRASS_SKIP_MAPSET_OWNER_CHECK");
Expand Down
10 changes: 5 additions & 5 deletions lib/gis/paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sys/stat.h>
#include <unistd.h>

#ifndef __MINGW32__
#ifndef _WIN32
#include <pwd.h>
#else
#include <windows.h>
Expand All @@ -26,7 +26,7 @@

int G_mkdir(const char *path)
{
#ifdef __MINGW32__
#ifdef _WIN32
return mkdir(path);
#else
return mkdir(path, 0777);
Expand Down Expand Up @@ -62,7 +62,7 @@ int G_is_dirsep(char c)
int G_is_absolute_path(const char *path)
{
if (G_is_dirsep(path[0])
#ifdef __MINGW32__
#ifdef _WIN32
|| (isalpha(path[0]) && (path[1] == ':') && G_is_dirsep(path[2]))
#endif
)
Expand Down Expand Up @@ -144,7 +144,7 @@ int G_stat(const char *file_name, struct stat *buf)

int G_lstat(const char *file_name, struct stat *buf)
{
#ifdef __MINGW32__
#ifdef _WIN32
return stat(file_name, buf);
#else
return lstat(file_name, buf);
Expand All @@ -164,7 +164,7 @@ int G_lstat(const char *file_name, struct stat *buf)
int G_owner(const char *path)
{

#ifndef __MINGW32__
#ifndef _WIN32
struct stat info;

G_stat(path, &info);
Expand Down
2 changes: 1 addition & 1 deletion lib/gis/popen.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <grass/gis.h>
#include <grass/spawn.h>

#ifdef __MINGW32__
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#define pipe(fds) _pipe(fds, 4096, O_BINARY|O_NOINHERIT)
Expand Down
6 changes: 3 additions & 3 deletions lib/gis/sleep.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include <grass/config.h>
#ifndef __MINGW32__
#ifndef _WIN32
#include <unistd.h>
#endif
#ifdef __MINGW32__
#ifdef _WIN32
#include <windows.h>
#endif
#include <grass/gis.h>

/* Sleep */
void G_sleep(unsigned int seconds)
{
#ifdef __MINGW32__
#ifdef _WIN32
/* note: Sleep() cannot be interrupted */
Sleep((seconds) * 1000);
#else
Expand Down
10 changes: 5 additions & 5 deletions lib/gis/spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <errno.h>
#include <sys/types.h>

#ifndef __MINGW32__
#ifndef _WIN32
#include <sys/wait.h>
#else
#include <windows.h>
Expand Down Expand Up @@ -72,7 +72,7 @@ struct signal
int action;
int signum;
int valid;
#ifndef __MINGW32__
#ifndef _WIN32
struct sigaction old_act;
sigset_t old_mask;
#endif
Expand Down Expand Up @@ -101,7 +101,7 @@ struct spawn
static void parse_arglist(struct spawn *sp, va_list va);
static void parse_argvec(struct spawn *sp, const char **va);

#ifdef __MINGW32__
#ifdef _WIN32

struct buffer {
char *str;
Expand Down Expand Up @@ -941,7 +941,7 @@ int G_spawn(const char *command, ...)

status = G_spawn_ex(
command,
#ifndef __MINGW32__
#ifndef _WIN32
SF_SIGNAL, SST_PRE, SSA_IGNORE, SIGINT,
SF_SIGNAL, SST_PRE, SSA_IGNORE, SIGQUIT,
SF_SIGNAL, SST_PRE, SSA_BLOCK, SIGCHLD,
Expand All @@ -954,7 +954,7 @@ int G_spawn(const char *command, ...)

int G_wait(int i_pid)
{
#ifdef __MINGW32__
#ifdef _WIN32
DWORD rights = PROCESS_QUERY_INFORMATION | SYNCHRONIZE;
HANDLE hProcess = OpenProcess(rights, FALSE, (DWORD) i_pid);
DWORD exitcode;
Expand Down
4 changes: 2 additions & 2 deletions lib/gis/user_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <assert.h>
#include <unistd.h>
#include <string.h>
#ifndef __MINGW32__
#ifndef _WIN32
#include <pwd.h>
#endif
#include <sys/types.h>
Expand All @@ -46,7 +46,7 @@
* path [caller must G_free ()] on success, or NULL on failure
*************************************************************************/

#ifndef __MINGW32__ /* TODO */
#ifndef _WIN32 /* TODO */
static char *_make_toplevel(void)
{
size_t len;
Expand Down
7 changes: 3 additions & 4 deletions lib/gis/whoami.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
*
* \author Original author CERL
*/

#include <unistd.h>
#include <stdlib.h>

#ifndef __MINGW32__
#ifndef _WIN32
#include <pwd.h>
#endif

Expand All @@ -40,7 +39,7 @@ const char *G_whoami(void)
if (G_is_initialized(&initialized))
return name;

#ifdef __MINGW32__
#ifdef _WIN32
name = getenv("USERNAME");
#endif
if (!name || !*name)
Expand All @@ -49,7 +48,7 @@ const char *G_whoami(void)
if (!name || !*name)
name = getenv("USER");

#ifndef __MINGW32__
#ifndef _WIN32
if (!name || !*name) {
struct passwd *p = getpwuid(getuid());
if (p && p->pw_name && *p->pw_name)
Expand Down
5 changes: 2 additions & 3 deletions lib/init/clean_temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#define SLEEP 30 /* 30 seconds */

/* Recursively scan the directory pathname, removing directory and files */

void clean_dir(const char *pathname, uid_t uid, pid_t pid, time_t now,
int max_age)
{
Expand Down Expand Up @@ -138,7 +137,7 @@ int main(int argc, char *argv[])
G_file_name(tmppath, element, "", mapset = G_mapset());

/* get user id and current time in seconds */
#ifdef __MINGW32__
#ifdef _WIN32
/* TODO */
uid = -1;
#else
Expand Down Expand Up @@ -170,7 +169,7 @@ int main(int argc, char *argv[])

int find_process(int pid)
{
#ifdef __MINGW32__
#ifdef _WIN32
/* TODO */
return -1;
#else
Expand Down
4 changes: 2 additions & 2 deletions lib/init/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char *argv[])
G_fatal_error(_("Usage: %s file pid"), argv[0]);
#define file argv[1]

#ifdef __MINGW32__
#ifdef _WIN32
G_warning(_("Concurrent mapset locking is not supported on Windows"));
exit(0);
#else
Expand Down Expand Up @@ -71,7 +71,7 @@ int find_process(int pid)
kill failed because no such process, or because user is
not owner of process
*/
#ifdef __MINGW32__
#ifdef _WIN32
return 0;
#else
if (kill(pid, 0) == 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/init/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the user's shell to re-activate interrupts in shell-ese.
int main(int argc, char *argv[])
{
signal(SIGINT, SIG_DFL);
#ifndef __MINGW32__
#ifndef _WIN32
signal(SIGQUIT, SIG_DFL);
#endif

Expand Down
2 changes: 1 addition & 1 deletion lib/manage/sighold.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int M__hold_signals(int hold)

signal(SIGINT, sig);

#ifndef __MINGW32__
#ifndef _WIN32
signal(SIGQUIT, sig);
#endif

Expand Down
4 changes: 2 additions & 2 deletions lib/pngdriver/graph_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __MINGW32__
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h>
Expand All @@ -33,7 +33,7 @@ static void unmap_file(void)
if (!png.mapped)
return;

#ifdef __MINGW32__
#ifdef _WIN32
UnmapViewOfFile(ptr);
CloseHandle(png.handle);
#else
Expand Down
Loading

0 comments on commit 87f6735

Please sign in to comment.