File: compat.c

package info (click to toggle)
uxplay 1.73.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,392 kB
  • sloc: ansic: 24,133; cpp: 2,956; python: 705; makefile: 10
file content (36 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/*
 * Copyright (c) 2024 F. Duncanh, All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 *==================================================================
 */

#ifdef _WIN32
#include <stdlib.h>
#include <string.h>
#include "compat.h"

#define MAX_SOCKET_ERROR_MESSAGE_LENGTH 256

/* Windows (winsock2) socket error message text */
char *wsa_strerror(int errnum) {
    static char message[MAX_SOCKET_ERROR_MESSAGE_LENGTH] = { 0 };
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
                  0, errnum, 0, message, sizeof(message), 0);
    char *nl = strchr(message, '\n');
    if (nl) {
        *nl = 0;  /* remove any trailing newline, or truncate to one line */
    }
    return message;
}
#endif