#include <fcntl.h>
#include <unistd.h>
#ifdef _WIN32
-#include <conio.h>
+#include <windows.h>
#else
#include <glob.h>
#include <termios.h>
#else
struct termios *term;
- term = malloc(sizeof(struct termios));
+ /* TODO: 'term' is never g_free()'d? */
+ if (!(term = g_try_malloc(sizeof(struct termios)))) {
+ sr_err("serial: %s: term malloc failed", __func__);
+ return NULL;
+ }
+
tcgetattr(fd, term);
return term;
if (!GetCommState(hdl, &dcb)) {
/* TODO: Error handling. */
- return SIGROK_ERR;
+ return SR_ERR;
}
/* TODO: Rename 'speed' to 'baudrate'. */
if (!SetCommState(hdl, &dcb)) {
/* TODO: Error handling. */
- return SIGROK_ERR;
+ return SR_ERR;
}
#else
struct termios term;
case 115200:
baud = B115200;
break;
-/* removed for 0.1 release
case 460800:
baud = B460800;
break;
-*/
default:
- return SIGROK_ERR;
+ return SR_ERR;
}
if (tcgetattr(fd, &term) < 0)
- return SIGROK_ERR;
+ return SR_ERR;
if (cfsetispeed(&term, baud) < 0)
- return SIGROK_ERR;
+ return SR_ERR;
term.c_cflag &= ~CSIZE;
switch (bits) {
term.c_cflag |= CS7;
break;
default:
- return SIGROK_ERR;
+ return SR_ERR;
}
term.c_cflag &= ~CSTOPB;
case 2:
term.c_cflag |= CSTOPB;
default:
- return SIGROK_ERR;
+ return SR_ERR;
}
term.c_cflag &= ~(IXON | IXOFF | CRTSCTS);
case 1:
term.c_cflag |= CRTSCTS;
default:
- return SIGROK_ERR;
+ return SR_ERR;
}
term.c_iflag &= ~IGNPAR;
term.c_cflag |= PARENB | PARODD;
break;
default:
- return SIGROK_ERR;
+ return SR_ERR;
}
if (tcsetattr(fd, TCSADRAIN, &term) < 0)
- return SIGROK_ERR;
+ return SR_ERR;
#endif
- return SIGROK_OK;
+ return SR_OK;
}