Implementations for MacOS support.
parent
0a4fdf1f69
commit
bf012e6390
56
dll/base.cpp
56
dll/base.cpp
|
@ -150,44 +150,18 @@ bool check_timedout(std::chrono::high_resolution_clock::time_point old, double t
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef __LINUX__
|
||||
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)
|
||||
#if defined(__LINUX__) || defined(__APPLE__)
|
||||
std::string get_lib_path()
|
||||
{
|
||||
while ((ep = readdir (dp))) {
|
||||
if (memcmp(ep->d_name, ".", 2) != 0 && memcmp(ep->d_name, "..", 3) != 0) {
|
||||
char *upper = NULL;
|
||||
uintptr_t lower_bound = strtoull(ep->d_name, &upper, 16);
|
||||
if (lower_bound) {
|
||||
++upper;
|
||||
uintptr_t upper_bound = strtoull(upper, &upper, 16);
|
||||
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;
|
||||
}
|
||||
}
|
||||
std::string library_path = "./";
|
||||
|
||||
Dl_info infos;
|
||||
dladdr((void*)&get_lib_path, &infos);
|
||||
library_path = infos.dli_fname;
|
||||
|
||||
return library_path;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
(void) closedir (dp);
|
||||
}
|
||||
|
||||
return ".";
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string get_full_lib_path()
|
||||
|
@ -222,10 +196,10 @@ std::string get_full_program_path()
|
|||
std::string get_current_path()
|
||||
{
|
||||
std::string path;
|
||||
#if defined(STEAM_WIN32)
|
||||
#if defined(__WINDOWS__)
|
||||
char *buffer = _getcwd( NULL, 0 );
|
||||
#else
|
||||
char *buffer = get_current_dir_name();
|
||||
#elif defined(__LINUX__) || defined(__APPLE__)
|
||||
char *buffer = getcwd( NULL, 0 );
|
||||
#endif
|
||||
if (buffer) {
|
||||
path = buffer;
|
||||
|
@ -239,10 +213,10 @@ std::string get_current_path()
|
|||
std::string canonical_path(std::string path)
|
||||
{
|
||||
std::string output;
|
||||
#if defined(STEAM_WIN32)
|
||||
#if defined(__WINDOWS__)
|
||||
char *buffer = _fullpath(NULL, path.c_str(), 0);
|
||||
#else
|
||||
char *buffer = canonicalize_file_name(path.c_str());
|
||||
#elif defined(__LINUX__) || defined(__APPLE__)
|
||||
char *buffer = realpath(path.c_str(), NULL);
|
||||
#endif
|
||||
|
||||
if (buffer) {
|
||||
|
|
|
@ -69,8 +69,6 @@
|
|||
#include <iphlpapi.h> // Include winsock2 before this, or winsock2 iphlpapi will be unavailable
|
||||
#include <shlobj.h>
|
||||
|
||||
#define MSG_NOSIGNAL 0
|
||||
|
||||
#define SystemFunction036 NTAPI SystemFunction036
|
||||
#include <ntsecapi.h>
|
||||
#undef SystemFunction036
|
||||
|
@ -96,7 +94,15 @@
|
|||
#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 <sys/types.h>
|
||||
|
@ -109,7 +115,6 @@
|
|||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <linux/netdevice.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -124,7 +129,13 @@
|
|||
#define PRINT_DEBUG(...) {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, __VA_ARGS__); fclose(t);}
|
||||
#endif
|
||||
#define PATH_SEPARATOR "/"
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
//#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__)
|
||||
#ifdef EMU_RELEASE_BUILD
|
||||
#define PRINT_DEBUG(...)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
/* Not sure how many platforms this will run on,
|
||||
* so it's wrapped in __linux for now.
|
||||
* Definitely won't work like this on Windows...
|
||||
*/
|
||||
ifaddrs* ifaces_list;
|
||||
|
||||
number_broadcasts = 0;
|
||||
sock_t sock = 0;
|
||||
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
return;
|
||||
|
||||
/* Configure ifconf for the ioctl call. */
|
||||
struct ifreq i_faces[MAX_BROADCASTS];
|
||||
memset(i_faces, 0, sizeof(struct ifreq) * MAX_BROADCASTS);
|
||||
|
||||
struct ifconf ifconf;
|
||||
ifconf.ifc_buf = (char *)i_faces;
|
||||
ifconf.ifc_len = sizeof(i_faces);
|
||||
|
||||
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;
|
||||
}
|
||||
if (getifaddrs(&ifaces_list) == 0)
|
||||
{
|
||||
const sockaddr_in* sock_addr;
|
||||
for (ifaddrs* pIface = ifaces_list; pIface != nullptr; pIface = pIface->ifa_next)
|
||||
{
|
||||
if (pIface->ifa_addr->sa_family == AF_INET)
|
||||
{
|
||||
sock_addr = reinterpret_cast<const sockaddr_in*>(pIface->ifa_addr);
|
||||
if (sock_addr->sin_addr.s_addr != 0 && pIface->ifa_netmask != nullptr)
|
||||
{
|
||||
uint32_t ip = reinterpret_cast<const sockaddr_in*>(pIface->ifa_addr)->sin_addr.s_addr;
|
||||
uint32_t mask = reinterpret_cast<const sockaddr_in*>(pIface->ifa_netmask)->sin_addr.s_addr;
|
||||
|
||||
IP_PORT *ip_port = &broadcasts[number_broadcasts++];
|
||||
ip_port->ip = ip | ~mask;
|
||||
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
|
||||
|
||||
|
|
13
dll/wrap.cpp
13
dll/wrap.cpp
|
@ -15,19 +15,12 @@
|
|||
License along with the Goldberg Emulator; if not, see
|
||||
<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 "dll.h"
|
||||
|
||||
#if defined(__LINUX__)
|
||||
#define STEAM_API_FUNCTIONS_IMPL
|
||||
|
||||
#define PATH_SEPARATOR_CHAR '/'
|
||||
#define STEAM_PATH_CACHE_SIZE 4096
|
||||
|
||||
|
|
Loading…
Reference in New Issue