mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add platform-specific fixes file
Create a new file, platform.h, for platform-specific hacks for MSVC, this includes defining strncasecmp to _stricmp and strdup to _strdup, among other things like defining missing stat macros Change some things not supported in MSVC, like _Static_assert, to their counterparts (in this case, static_assert) Replace usage of VLAs with malloc and free Update getopt_long and use the getopt implementation from musl on Windows. Use comments to show which functions from platform.h are being used
This commit is contained in:
6
include/extern/getopt.h
vendored
6
include/extern/getopt.h
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2005-2019 Rich Felker, et al.
|
||||
* Copyright © 2005-2020 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
/* This implementation was taken from musl and modified for RGBDS */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H
|
||||
#ifndef RGBDS_EXTERN_GETOPT_H
|
||||
#define RGBDS_EXTERN_GETOPT_H
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt, optreset;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#define HASH_NB_BITS 32
|
||||
#define HALF_HASH_NB_BITS 16
|
||||
_Static_assert(HALF_HASH_NB_BITS * 2 == HASH_NB_BITS, "");
|
||||
static_assert(HALF_HASH_NB_BITS * 2 == HASH_NB_BITS, "");
|
||||
#define HASHMAP_NB_BUCKETS (1 << HALF_HASH_NB_BITS)
|
||||
|
||||
/* HashMapEntry is internal, please do not attempt to use it */
|
||||
|
||||
35
include/platform.h
Normal file
35
include/platform.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of RGBDS.
|
||||
*
|
||||
* Copyright (c) 2020 RGBDS contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* platform-specific hacks */
|
||||
|
||||
#ifndef RGBDS_PLATFORM_H
|
||||
#define RGBDS_PLATFORM_H
|
||||
|
||||
/* MSVC doesn't have strncasecmp, use a suitable replacement */
|
||||
#ifdef _MSC_VER
|
||||
# include <string.h>
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
/* MSVC has deprecated strdup in favor of _strdup */
|
||||
#ifdef _MSC_VER
|
||||
# define strdup _strdup
|
||||
#endif
|
||||
|
||||
/* MSVC prefixes the names of S_* macros with underscores,
|
||||
and doesn't define any S_IS* macros. Define them ourselves */
|
||||
#ifdef _MSC_VER
|
||||
# define S_IFMT _S_IFMT
|
||||
# define S_IFDIR _S_IFDIR
|
||||
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
#endif /* RGBDS_PLATFORM_H */
|
||||
Reference in New Issue
Block a user