-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindef.h
78 lines (72 loc) · 2.4 KB
/
windef.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef WINDEF_H
#define WINDEF_H
#ifdef __MINGW32__
#include <winsock2.h>
#include <Ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
static u_long winsock_one = 1;
// #include <ws2def.h>
// #include <iphlpapi.h>
// #include <windows.h>
// #include <io.h>
#define close closesocket
#define exit(exit_arg) \
WSACleanup(); \
exit(exit_arg);
#define accept(sock, addr, len) \
accept(sock, (struct sockaddr*)addr, len)
#define setsockopt(sock, level, optname, optval, optlen) \
setsockopt(sock, level, optname, "1", 4)
#define fcntl(sock, op, flag) ioctlsocket(sock, FIONBIO, &winsock_one)
#define shutdown(res, whom) 0
#define drand48() ((double)rand())/RAND_MAX
#define srand48(seed) srand(seed)
#define _NTDDI_VERSION_FROM_WIN32_WINNT2(ver) ver##0000
#define _NTDDI_VERSION_FROM_WIN32_WINNT(ver) _NTDDI_VERSION_FROM_WIN32_WINNT2(ver)
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501
#endif // _WIN32_WINNT
#ifndef NTDDI_VERSION
# define NTDDI_VERSION _NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT)
#endif // NTDDI_VERSION
static inline ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) {
char *ptr, *eptr;
if (*buf == NULL || *bufsiz == 0) {
*bufsiz = BUFSIZ;
if ((*buf = malloc(*bufsiz)) == NULL)
return -1;
}
for (ptr = *buf, eptr = *buf + *bufsiz;;) {
int c = fgetc(fp);
if (c == -1) {
if (feof(fp)) {
ssize_t diff = (ssize_t)(ptr - *buf);
if (diff != 0) {
*ptr = '\0';
return diff;
}
}
return -1;
}
*ptr++ = c;
if (c == delimiter) {
*ptr = '\0';
return ptr - *buf;
}
if (ptr + 2 >= eptr) {
char *nbuf;
size_t nbufsiz = *bufsiz * 2;
ssize_t d = ptr - *buf;
if ((nbuf = realloc(*buf, nbufsiz)) == NULL)
return -1;
*buf = nbuf;
*bufsiz = nbufsiz;
eptr = nbuf + nbufsiz;
ptr = nbuf + d;
}
}
}
#define getline(buf, bufsiz, fp) \
getdelim(buf, bufsiz, '\n', fp);
#endif // __MINGW_32__
#endif // WINDEF_H