Implementations for MacOS support.

This commit is contained in:
Nemirtingas 2020-10-14 06:44:44 +02:00
parent 0a4fdf1f69
commit bf012e6390
4 changed files with 61 additions and 112 deletions

View File

@ -150,44 +150,18 @@ bool check_timedout(std::chrono::high_resolution_clock::time_point old, double t
return false; return false;
} }
#ifdef __LINUX__ #if defined(__LINUX__) || defined(__APPLE__)
std::string get_lib_path() { std::string get_lib_path()
std::string dir = "/proc/self/map_files";
DIR *dp;
int i = 0;
struct dirent *ep;
dp = opendir (dir.c_str());
uintptr_t p = (uintptr_t)&get_lib_path;
if (dp != NULL)
{ {
while ((ep = readdir (dp))) { std::string library_path = "./";
if (memcmp(ep->d_name, ".", 2) != 0 && memcmp(ep->d_name, "..", 3) != 0) {
char *upper = NULL; Dl_info infos;
uintptr_t lower_bound = strtoull(ep->d_name, &upper, 16); dladdr((void*)&get_lib_path, &infos);
if (lower_bound) { library_path = infos.dli_fname;
++upper;
uintptr_t upper_bound = strtoull(upper, &upper, 16); return library_path;
if (upper_bound && (lower_bound < p && p < upper_bound)) {
std::string path = dir + PATH_SEPARATOR + ep->d_name;
char link[PATH_MAX] = {};
if (readlink(path.c_str(), link, sizeof(link)) > 0) {
std::string lib_path = link;
(void) closedir (dp);
return link;
}
}
} }
i++;
}
}
(void) closedir (dp);
}
return ".";
}
#endif #endif
std::string get_full_lib_path() std::string get_full_lib_path()
@ -222,10 +196,10 @@ std::string get_full_program_path()
std::string get_current_path() std::string get_current_path()
{ {
std::string path; std::string path;
#if defined(STEAM_WIN32) #if defined(__WINDOWS__)
char *buffer = _getcwd( NULL, 0 ); char *buffer = _getcwd( NULL, 0 );
#else #elif defined(__LINUX__) || defined(__APPLE__)
char *buffer = get_current_dir_name(); char *buffer = getcwd( NULL, 0 );
#endif #endif
if (buffer) { if (buffer) {
path = buffer; path = buffer;
@ -239,10 +213,10 @@ std::string get_current_path()
std::string canonical_path(std::string path) std::string canonical_path(std::string path)
{ {
std::string output; std::string output;
#if defined(STEAM_WIN32) #if defined(__WINDOWS__)
char *buffer = _fullpath(NULL, path.c_str(), 0); char *buffer = _fullpath(NULL, path.c_str(), 0);
#else #elif defined(__LINUX__) || defined(__APPLE__)
char *buffer = canonicalize_file_name(path.c_str()); char *buffer = realpath(path.c_str(), NULL);
#endif #endif
if (buffer) { if (buffer) {

View File

@ -69,8 +69,6 @@
#include <iphlpapi.h> // Include winsock2 before this, or winsock2 iphlpapi will be unavailable #include <iphlpapi.h> // Include winsock2 before this, or winsock2 iphlpapi will be unavailable
#include <shlobj.h> #include <shlobj.h>
#define MSG_NOSIGNAL 0
#define SystemFunction036 NTAPI SystemFunction036 #define SystemFunction036 NTAPI SystemFunction036
#include <ntsecapi.h> #include <ntsecapi.h>
#undef SystemFunction036 #undef SystemFunction036
@ -96,7 +94,15 @@
#endif #endif
#endif #endif
#elif defined(__LINUX__) #elif defined(__LINUX__) || defined(__APPLE__)
#if defined(__LINUX__)
// Insert here Linux specific headers
#else
// Insert here MacOS specific headers
#include <sys/sysctl.h>
#include <mach-o/dyld_images.h>
#endif
#include <ifaddrs.h>// getifaddrs
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/types.h> #include <sys/types.h>
@ -109,7 +115,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <linux/netdevice.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -124,7 +129,13 @@
#define PRINT_DEBUG(...) {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, __VA_ARGS__); fclose(t);} #define PRINT_DEBUG(...) {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, __VA_ARGS__); fclose(t);}
#endif #endif
#define PATH_SEPARATOR "/" #define PATH_SEPARATOR "/"
#endif #endif
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
//#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__) //#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__)
#ifdef EMU_RELEASE_BUILD #ifdef EMU_RELEASE_BUILD
#define PRINT_DEBUG(...) #define PRINT_DEBUG(...)

View File

@ -120,68 +120,39 @@ static void get_broadcast_info(uint16 port)
} }
} }
#elif defined(__linux__) #elif defined(__LINUX__) || defined(__APPLE__)
static void get_broadcast_info(uint16 port) static void get_broadcast_info(uint16 port)
{ {
/* Not sure how many platforms this will run on, ifaddrs* ifaces_list;
* so it's wrapped in __linux for now.
* Definitely won't work like this on Windows...
*/
number_broadcasts = 0; number_broadcasts = 0;
sock_t sock = 0; if (getifaddrs(&ifaces_list) == 0)
{
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) const sockaddr_in* sock_addr;
return; for (ifaddrs* pIface = ifaces_list; pIface != nullptr; pIface = pIface->ifa_next)
{
/* Configure ifconf for the ioctl call. */ if (pIface->ifa_addr->sa_family == AF_INET)
struct ifreq i_faces[MAX_BROADCASTS]; {
memset(i_faces, 0, sizeof(struct ifreq) * MAX_BROADCASTS); sock_addr = reinterpret_cast<const sockaddr_in*>(pIface->ifa_addr);
if (sock_addr->sin_addr.s_addr != 0 && pIface->ifa_netmask != nullptr)
struct ifconf ifconf; {
ifconf.ifc_buf = (char *)i_faces; uint32_t ip = reinterpret_cast<const sockaddr_in*>(pIface->ifa_addr)->sin_addr.s_addr;
ifconf.ifc_len = sizeof(i_faces); uint32_t mask = reinterpret_cast<const sockaddr_in*>(pIface->ifa_netmask)->sin_addr.s_addr;
if (ioctl(sock, SIOCGIFCONF, &ifconf) < 0) {
close(sock);
return;
}
/* ifconf.ifc_len is set by the ioctl() to the actual length used;
* on usage of the complete array the call should be repeated with
* a larger array, not done (640kB and 16 interfaces shall be
* enough, for everybody!)
*/
int i, count = ifconf.ifc_len / sizeof(struct ifreq);
for (i = 0; i < count; i++) {
/* there are interfaces with are incapable of broadcast */
if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0)
continue;
/* moot check: only AF_INET returned (backwards compat.) */
if (i_faces[i].ifr_broadaddr.sa_family != AF_INET)
continue;
struct sockaddr_in *sock4 = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
if (number_broadcasts >= MAX_BROADCASTS) {
close(sock);
return;
}
IP_PORT *ip_port = &broadcasts[number_broadcasts];
ip_port->ip = sock4->sin_addr.s_addr;
if (ip_port->ip == 0) {
continue;
}
IP_PORT *ip_port = &broadcasts[number_broadcasts++];
ip_port->ip = ip | ~mask;
ip_port->port = port; ip_port->port = port;
number_broadcasts++;
} }
}
close(sock); // IPV6
//else if (pIface->ifa_addr->sa_family == AF_INET6)
//{
// const sockaddr_in6* addr = reinterpret_cast<const sockaddr_in6*>(pIface->ifa_addr);));
//}
}
freeifaddrs(ifaces_list);
}
} }
#endif #endif

View File

@ -15,19 +15,12 @@
License along with the Goldberg Emulator; if not, see License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */ <http://www.gnu.org/licenses/>. */
#if defined(WIN64) || defined(_WIN64) || defined(__MINGW64__)
#define __WINDOWS_64__
#elif defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
#define __WINDOWS_32__
#endif
#if defined(__WINDOWS_32__) || defined(__WINDOWS_64__)
// Nothing to be done here
#else
#define STEAM_API_FUNCTIONS_IMPL
#include "base.h" #include "base.h"
#include "dll.h" #include "dll.h"
#if defined(__LINUX__)
#define STEAM_API_FUNCTIONS_IMPL
#define PATH_SEPARATOR_CHAR '/' #define PATH_SEPARATOR_CHAR '/'
#define STEAM_PATH_CACHE_SIZE 4096 #define STEAM_PATH_CACHE_SIZE 4096