Skip to content

Commit

Permalink
Get rid of Windows WSA startup code
Browse files Browse the repository at this point in the history
Reported-by: @vszakats (github.com)
  • Loading branch information
rockdaboot committed Mar 23, 2024
1 parent 356c073 commit 8b505b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
7 changes: 7 additions & 0 deletions src/psl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
#include <sys/types.h>
#include <sys/stat.h>

#if defined(_WIN32) && (defined(WITH_LIBIDN2) || defined(WITH_LIBIDN))
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> /* for GetACP() */
#endif

#if defined(_MSC_VER) && ! defined(ssize_t)
# include <basetsd.h>
typedef SSIZE_T ssize_t;
Expand Down
16 changes: 0 additions & 16 deletions tests/test-is-cookie-domain-acceptable.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
# include <config.h>
#endif

#ifdef _WIN32
# include <winsock2.h> // WSAStartup, WSACleanup
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -111,18 +107,6 @@ static void test_psl(void)

int main(int argc, const char * const *argv)
{
#ifdef _WIN32
WSADATA wsa_data;
int err;

if ((err = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
printf("WSAStartup failed with error: %d\n", err);
return 1;
}

atexit((void (__cdecl*)(void)) WSACleanup);
#endif

/* if VALGRIND testing is enabled, we have to call ourselves with valgrind checking */
if (argc == 1) {
const char *valgrind = getenv("TESTS_VALGRIND");
Expand Down
21 changes: 1 addition & 20 deletions tools/psl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#endif

#ifdef _WIN32
# include <winsock2.h> // WSAStartup, WSACleanup

// Windows does not have localtime_r but has localtime_s, which is more or less
// the same except that the arguments are reversed
# define LOCALTIME_R_SUCCESSFUL(t_sec, t_now) \
Expand All @@ -57,6 +55,7 @@ struct tm *localtime_r(const time_t *, struct tm *);
#include <string.h>
#include <ctype.h>
#include <locale.h>
#include <time.h>

#include <libpsl.h>

Expand All @@ -83,20 +82,6 @@ static void usage(int err, FILE* f)
exit(err);
}

static void init_windows(void) {
#ifdef _WIN32
WSADATA wsa_data;
int err;

if ((err = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
printf("WSAStartup failed with error: %d\n", err);
exit(EXIT_FAILURE);
}

atexit((void (__cdecl*)(void)) WSACleanup);
#endif
}

/* RFC 2822-compliant date format */
static const char *time2str(time_t t)
{
Expand Down Expand Up @@ -243,8 +228,6 @@ int main(int argc, const char *const *argv)
else if (mode == 4) {
char *cookie_domain_lower;

init_windows();

if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &cookie_domain_lower)) == PSL_SUCCESS) {
if (!batch_mode)
printf("%s: ", domain);
Expand Down Expand Up @@ -289,8 +272,6 @@ int main(int argc, const char *const *argv)
}
}
else if (mode == 4) {
init_windows();

for (; arg < argv + argc; arg++) {
if (!batch_mode)
printf("%s: ", *arg);
Expand Down

0 comments on commit 8b505b6

Please sign in to comment.