1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2014
3 // David Freese, W1HKJ
4 //
5 // This file is part of fldigi
6 //
7 // fldigi is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // fldigi is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // ----------------------------------------------------------------------------
20
21 #ifndef MINGW_H_
22 #define MINGW_H_
23
24 #include <sys/types.h>
25 #include <pthread.h>
26
27 #undef _WINSOCKAPI_
28 #include <winsock2.h>
29
30 #undef EADDRINUSE
31 #define EADDRINUSE WSAEADDRINUSE
32
33 #undef EISCONN
34 #define EISCONN WSAEISCONN
35
36 #undef EWOULDBLOCK
37 #define EWOULDBLOCK WSAEWOULDBLOCK
38
39 #undef EINPROGRESS
40 #define EINPROGRESS WSAEINPROGRESS
41
42 #undef EALREADY
43 #define EALREADY WSAEALREADY
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 typedef int pid_t;
50 typedef long suseconds_t;
51 #define hstrerror strerror
52
53 #ifndef SIGUSR2
54 # define SIGUSR2 100
55 #endif
56
57 extern void was_init(void);
58 extern int was_init_state(void);
59 extern WSADATA * was_data(void);
60
61 /*
62 * simple adaptors
63 */
64
mingw_mkdir(const char * path,int mode)65 static inline int mingw_mkdir(const char *path, int mode)
66 {
67 return mkdir(path);
68 }
69 #define mkdir mingw_mkdir
70
mingw_unlink(const char * pathname)71 static inline int mingw_unlink(const char *pathname)
72 {
73 /* read-only files cannot be removed */
74 chmod(pathname, 0666);
75 return unlink(pathname);
76 }
77 #define unlink mingw_unlink
78
79 /*
80 * implementations of missing functions
81 */
82
83 unsigned int sleep (unsigned int seconds);
84 char *mingw_getcwd(char *pointer, int len);
85 #define getcwd mingw_getcwd
86 char *mingw_getenv(const char *name);
87 #define getenv mingw_getenv
88 int mingw_rename(const char*, const char*);
89 #define rename mingw_rename
90
91 #ifndef SHUT_WR
92 # define SHUT_WR SD_SEND
93 #endif
94 #ifndef SHUT_RD
95 # define SHUT_RD SD_RECEIVE
96 #endif
97 #ifndef SHUT_RDWR
98 # define SHUT_RDWR SD_BOTH
99 #endif
100 #ifndef EADDRINUSE
101 # define EADDRINUSE WSAEADDRINUSE
102 #endif
103
104 int nanosleep (const struct timespec *req, struct timespec *rem);
105 int socketpair(int family, int type, int protocol, int *sv);
106
107 /* uname */
108 #define UTSNAME_MAX_ 257
109 struct utsname
110 {
111 char sysname[UTSNAME_MAX_];
112 char nodename[UTSNAME_MAX_];
113 char release[UTSNAME_MAX_];
114 char version[UTSNAME_MAX_];
115 char machine[UTSNAME_MAX_];
116 };
117 int uname(struct utsname *name);
118
119 /* getrusage */
120 #define RUSAGE_SELF 0
121 #define RUSAGE_CHILDREN (-1)
122 struct rusage
123 {
124 struct timeval ru_utime;
125 struct timeval ru_stime;
126 };
127 int getrusage(int who, struct rusage *usage);
128
129 /* fsync, fdatasync */
130 #include <io.h>
131 #define fsync _commit
132 #define fdatasync fsync
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif
139