Align loader to 32-bit boundary
[fw/stlink] / mingw / mingw.h
1 #ifdef __MINGW32__
2
3 #include <io.h>
4
5 #define _USE_W32_SOCKETS 1
6 #include <windows.h>
7
8 #define ENOTCONN        WSAENOTCONN
9 #define EWOULDBLOCK     WSAEWOULDBLOCK
10 #define ENOBUFS         WSAENOBUFS
11 #define ECONNRESET      WSAECONNRESET
12 #define ESHUTDOWN       WSAESHUTDOWN
13 #define EAFNOSUPPORT    WSAEAFNOSUPPORT
14 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
15 #define EINPROGRESS     WSAEINPROGRESS
16 #define EISCONN         WSAEISCONN
17
18 /* winsock doesn't feature poll(), so there is a version implemented
19  * in terms of select() in mingw.c. The following definitions
20  * are copied from linux man pages. A poll() macro is defined to
21  * call the version in mingw.c.
22  */
23 #define POLLIN      0x0001    /* There is data to read */
24 #define POLLPRI     0x0002    /* There is urgent data to read */
25 #define POLLOUT     0x0004    /* Writing now will not block */
26 #define POLLERR     0x0008    /* Error condition */
27 #define POLLHUP     0x0010    /* Hung up */
28 #define POLLNVAL    0x0020    /* Invalid request: fd not open */
29 struct pollfd {
30     SOCKET fd;        /* file descriptor */
31     short events;     /* requested events */
32     short revents;    /* returned events */
33 };
34 #define poll(x, y, z)        win32_poll(x, y, z)
35
36 /* These wrappers do nothing special except set the global errno variable if
37  * an error occurs (winsock doesn't do this by default). They set errno
38  * to unix-like values (i.e. WSAEWOULDBLOCK is mapped to EAGAIN), so code
39  * outside of this file "shouldn't" have to worry about winsock specific error
40  * handling.
41  */
42 #define socket(x, y, z)         win32_socket(x, y, z)
43 #define connect(x, y, z)        win32_connect(x, y, z)
44 #define accept(x, y, z)         win32_accept(x, y, z)
45 #define shutdown(x, y)          win32_shutdown(x, y)
46 #define read(x, y, z)                   win32_read_socket(x, y, z)
47 #define write(x, y, z)                  win32_write_socket(x, y, z)
48
49 /* Winsock uses int instead of the usual socklen_t */
50 typedef int socklen_t;
51
52 int     win32_poll(struct pollfd *, unsigned int, int);
53 SOCKET  win32_socket(int, int, int);
54 int     win32_connect(SOCKET, struct sockaddr*, socklen_t);
55 SOCKET  win32_accept(SOCKET, struct sockaddr*, socklen_t *);
56 int     win32_shutdown(SOCKET, int);
57 int     win32_close_socket(SOCKET fd);
58
59 #define strtok_r(x, y, z)      win32_strtok_r(x, y, z)
60 #define strsep(x,y) win32_strsep(x,y)
61
62 char *win32_strtok_r(char *s, const char *delim, char **lasts);
63 char *win32_strsep(char **stringp, const char *delim);
64
65 ssize_t win32_read_socket(SOCKET fd, void *buf, int n);
66 ssize_t win32_write_socket(SOCKET fd, void *buf, int n);
67
68 static inline void sleep(unsigned ms) { Sleep(ms); }
69
70 #endif