X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fserial.c;h=b98d3c95e82f76d5bb573ef3bc1a58e98ab2b1f8;hb=f36cbf60cbd43be46ede083265549068db21f4b6;hp=2c28510aa8330164028d7fce3752eee58c26132d;hpb=576790ff7b7e888eeefa79239ffed6d8550c1160;p=libsigrok.git diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 2c28510a..b98d3c95 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -23,7 +23,7 @@ #include #include #ifdef _WIN32 -#include +#include #else #include #include @@ -163,7 +163,12 @@ void *serial_backup_params(int fd) #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; @@ -193,7 +198,7 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, if (!GetCommState(hdl, &dcb)) { /* TODO: Error handling. */ - return SIGROK_ERR; + return SR_ERR; } /* TODO: Rename 'speed' to 'baudrate'. */ @@ -224,7 +229,7 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, if (!SetCommState(hdl, &dcb)) { /* TODO: Error handling. */ - return SIGROK_ERR; + return SR_ERR; } #else struct termios term; @@ -243,19 +248,17 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, 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) { @@ -266,7 +269,7 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, term.c_cflag |= CS7; break; default: - return SIGROK_ERR; + return SR_ERR; } term.c_cflag &= ~CSTOPB; @@ -276,7 +279,7 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, case 2: term.c_cflag |= CSTOPB; default: - return SIGROK_ERR; + return SR_ERR; } term.c_cflag &= ~(IXON | IXOFF | CRTSCTS); @@ -287,7 +290,7 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, case 1: term.c_cflag |= CRTSCTS; default: - return SIGROK_ERR; + return SR_ERR; } term.c_iflag &= ~IGNPAR; @@ -303,12 +306,12 @@ int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, 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; }