+#else // !_WIN32
+
+ if (config->baudrate >= 0)
+ {
+ for (i = 0; i < NUM_STD_BAUDRATES; i++) {
+ if (config->baudrate == std_baudrates[i].value) {
+ if (cfsetospeed(&data->term, std_baudrates[i].index) < 0)
+ return SP_ERR_FAIL;
+
+ if (cfsetispeed(&data->term, std_baudrates[i].index) < 0)
+ return SP_ERR_FAIL;
+ break;
+ }
+ }
+
+ if (i == NUM_STD_BAUDRATES)
+ return SP_ERR_ARG;
+ }
+
+ if (config->bits >= 0) {
+ data->term.c_cflag &= ~CSIZE;
+ switch (config->bits) {
+ case 8:
+ data->term.c_cflag |= CS8;
+ break;
+ case 7:
+ data->term.c_cflag |= CS7;
+ break;
+ case 6:
+ data->term.c_cflag |= CS6;
+ break;
+ case 5:
+ data->term.c_cflag |= CS5;
+ break;
+ default:
+ return SP_ERR_ARG;
+ }
+ }
+
+ if (config->parity >= 0) {
+ data->term.c_iflag &= ~IGNPAR;
+ data->term.c_cflag &= ~(PARENB | PARODD);
+ switch (config->parity) {
+ case SP_PARITY_NONE:
+ data->term.c_iflag |= IGNPAR;
+ break;
+ case SP_PARITY_EVEN:
+ data->term.c_cflag |= PARENB;
+ break;
+ case SP_PARITY_ODD:
+ data->term.c_cflag |= PARENB | PARODD;
+ break;
+ default:
+ return SP_ERR_ARG;
+ }
+ }
+
+ if (config->stopbits >= 0) {
+ data->term.c_cflag &= ~CSTOPB;
+ switch (config->stopbits) {
+ case 1:
+ data->term.c_cflag &= ~CSTOPB;
+ break;
+ case 2:
+ data->term.c_cflag |= CSTOPB;
+ break;
+ default:
+ return SP_ERR_ARG;
+ }
+ }
+
+ if (config->rts >= 0 || config->cts >= 0)
+ {
+ /* Asymmetric use of RTS/CTS not supported yet. */
+
+ if (data->term.c_iflag & CRTSCTS) {
+ /* Flow control can only be disabled for both RTS & CTS together. */
+ if (config->rts >= 0 && config->rts != SP_RTS_FLOW_CONTROL) {
+ if (config->cts != SP_CTS_IGNORE)
+ return SP_ERR_ARG;
+ }
+ if (config->cts >= 0 && config->cts != SP_CTS_FLOW_CONTROL) {
+ if (config->rts <= 0 || config->rts == SP_RTS_FLOW_CONTROL)
+ return SP_ERR_ARG;
+ }
+ } else {
+ /* Flow control can only be enabled for both RTS & CTS together. */
+ if (((config->rts == SP_RTS_FLOW_CONTROL) && (config->cts != SP_CTS_FLOW_CONTROL)) ||
+ ((config->cts == SP_CTS_FLOW_CONTROL) && (config->rts != SP_RTS_FLOW_CONTROL)))
+ return SP_ERR_ARG;
+ }
+
+ if (config->rts >= 0) {
+ if (config->rts == SP_RTS_FLOW_CONTROL) {
+ data->term.c_iflag |= CRTSCTS;
+ } else {
+ int controlbits = TIOCM_RTS;
+ if (ioctl(port->fd, config->rts == SP_RTS_ON ? TIOCMBIS : TIOCMBIC,
+ &controlbits) < 0)
+ return SP_ERR_FAIL;
+ }
+ }
+ }
+
+ if (config->dtr >= 0 || config->dsr >= 0)
+ {
+ /* DTR/DSR flow control not supported yet. */
+ if (config->dtr == SP_DTR_FLOW_CONTROL || config->dsr == SP_DSR_FLOW_CONTROL)
+ return SP_ERR_ARG;
+
+ if (config->dtr >= 0) {
+ int controlbits = TIOCM_DTR;
+ if (ioctl(port->fd, config->dtr == SP_DTR_ON ? TIOCMBIS : TIOCMBIC,
+ &controlbits) < 0)
+ return SP_ERR_FAIL;
+ }