-#ifndef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
+/* Avoid confusing windows w/o cygwin w/ cygwin */
+#define LOSE32
+#endif
+
+#ifndef LOSE32
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#endif
#endif
-#ifdef _WIN32
+#ifdef LOSE32
#include <windows.h>
#include <stdint.h>
#endif
enum {
#ifndef __CYGWIN__
-#ifndef _WIN32
+#ifndef LOSE32
FALSE = 0,
TRUE = 1,
#endif
};
struct serial_source_t {
-#ifndef _WIN32
+#ifndef LOSE32
int fd;
#else
HANDLE hComm;
} send;
};
-#ifndef _WIN32
+#ifndef LOSE32
static tcflag_t parse_baudrate(int requested)
{
int baudrate;
static int serial_read(serial_source src, int non_blocking, void *buffer, int n)
{
-#ifndef _WIN32
+#ifndef LOSE32
fd_set fds;
int cnt;
if (cnt != 0)
return cnt;
}
-#else // _WIN32
+#else // LOSE32
int cnt;
if (non_blocking) {
NULL for failure (bad device or bad baud rate)
*/
{
-#ifndef _WIN32
+#ifndef LOSE32
struct termios newtio;
int fd;
tcflag_t baudflag = parse_baudrate(baud_rate);
close(fd);
return NULL;
-#else // _WIN32
+#else // LOSE32
LPCTSTR ComName = (LPCTSTR)device;
HANDLE hComm;
DCB dcb;
return src;
-#endif // _WIN32
+#endif // LOSE32
}
-#ifndef _WIN32
+#ifndef LOSE32
int serial_source_fd(serial_source src)
/* Returns: the file descriptor used by serial source src (useful when
non-blocking reads were requested)
}
#endif
-#ifdef _WIN32
+#ifdef LOSE32
HANDLE serial_source_handle(serial_source src)
/* Returns: the file descriptor used by serial source src (useful when
non-blocking reads were requested)
considered closed anyway)
*/
{
-#ifndef _WIN32
+#ifndef LOSE32
int ok = close(src->fd);
#else
int ok = CloseHandle(src->hComm);
Returns: 0 if data is available, -1 if the deadline expires
*/
{
-#ifndef _WIN32
+#ifndef LOSE32
struct timeval tv;
fd_set fds;
int cnt;
return -1;
return 0;
}
-#else // _WIN32
+#else // LOSE32
// FIXME: the deadline is ignored here
DWORD eventMask;
static int source_write(serial_source src, const void *buffer, int count)
{
-#ifndef _WIN32
+#ifndef LOSE32
int actual = 0;
if (fcntl(src->fd, F_SETFL, 0) < 0)
/* We're in trouble, but there's no obvious fix. */
}
return actual;
-#else // _WIN32
+#else // LOSE32
int actual = 0;
int n;
const unsigned char * b = buffer;
src->recv.bufused = n;
break;
}
-#ifndef _WIN32
+#ifndef LOSE32
if (errno == EAGAIN)
return -1;
if (errno != EINTR)
// FIXME: the WIN32 implementation of source_wait()
// disregards the deadline parameter anyway
-#ifndef _WIN32
+#ifndef LOSE32
gettimeofday(&deadline, NULL);
add_timeval(&deadline, ACK_TIMEOUT);
#endif