Skip to content

Commit

Permalink
Fix for build non-Mingw builds
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
eraserhd committed Nov 16, 2023
1 parent 64817b7 commit 3d499be
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change Log
https://github.com/eraserhd/rep/compare/v0.2.2...HEAD[Unreleased]
-----------------------------------------------------------------

* Support for Mingw
* Test on aarch64-darwin and aarch64-linux
https://github.com/eraserhd/rep/compare/v0.2.1...v0.2.2[v0.2.2]
---------------------------------------------------------------

Expand Down
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
};
});

checkSystems = ["x86_64-darwin" "x86_64-linux"];
checkSystems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
checkOutputs = flake-utils.lib.eachSystem checkSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
Expand Down
30 changes: 15 additions & 15 deletions rep.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __unix__
#if defined(_WIN32) || defined(WIN32)
#include <malloc.h>
#include <winsock2.h>
#include <winsock.h>
#include <ws2tcpip.h>
#else
#include <alloca.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#elif defined(_WIN32) || defined(WIN32)
#include <malloc.h>
#include <winsock2.h>
#include <winsock.h>
#include <ws2tcpip.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -636,17 +636,17 @@ struct sockaddr_in options_address_from_relative_file(struct options* options, c
char *directory = strdup(directory_in);
for (;;)
{
#ifdef __unix__
struct stat statb;
#elif defined(_WIN32) || defined(WIN32)
#if defined(_WIN32) || defined(WIN32)
struct _stat statb;
#else
struct stat statb;
#endif
char* path_to_check = (char*)malloc(strlen(directory) + strlen(filename) + 2);
sprintf(path_to_check, "%s/%s", directory, filename);
#ifdef __unix__
if (0 == stat(path_to_check, &statb))
#elif defined(_WIN32) || defined(WIN32)
#if defined(_WIN32) || defined(WIN32)
if (0 == _stat(path_to_check, &statb))
#else
if (0 == stat(path_to_check, &statb))
#endif
{
struct sockaddr_in result = options_address_from_file(options, path_to_check);
Expand Down Expand Up @@ -706,14 +706,14 @@ struct sockaddr_in options_address(struct options* options, const char* port)
if (strchr(port, ':'))
{
char *host_part = strdup_up_to(port, ':');
#ifdef __unix__
if (!inet_aton(host_part, &address.sin_addr))
#elif defined(_WIN32) || defined(WIN32)
#if defined(_WIN32) || defined(WIN32)
size_t hostl = strlen(host_part) + 1;
wchar_t *whost = calloc(sizeof(wchar_t), hostl);
mbstowcs(whost, host_part, hostl);
LPCWSTR whost_part = whost;
if (!InetPtonW(AF_INET, whost_part, &address.sin_addr))
#else
if (!inet_aton(host_part, &address.sin_addr))
#endif
{
struct hostent *ent = gethostbyname(host_part);
Expand Down

0 comments on commit 3d499be

Please sign in to comment.