if (slp->com != INVALID) return ctl_reply_int(get_baud(slp), rbuf, rsize);
} if (slp->com != INVALID) { int baud = get_baud(slp);  return ctl_reply_int(baud, rbuf, rsize); }
static int sl_ctl(ErlDrvData data, unsigned int cmd, char* buf, int len, 	      char** rbuf, int rsize){    sl_t* slp = (sl_t*) data;        switch(cmd) {    case SL_SET_DEV: /* set device name */	if (slp->dev != NULL)	    driver_free(slp->dev);	slp->dev = NULL;	if (len > 0) {	    if ((slp->dev = driver_alloc(len + 1)) == NULL)		return ctl_error(SL_ERR_NOMEM, rbuf, rsize);	    memcpy(slp->dev, buf, len);	    slp->dev[len] = '\0';	}	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_DEV: /* get device name */	if (slp->dev == NULL)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	return ctl_reply_string(slp->dev, rbuf, rsize);	    case SL_SET_BAUD: /* set baud rate */	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->baud = get_int32(buf);	slp->flags |= FL_BAUD;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_BAUD: /* get baud rate */	if (slp->flags & FL_BAUD) /* pending */	    return ctl_reply_int(slp->baud, rbuf, rsize);	if (slp->com != INVALID)	    return ctl_reply_int(get_baud(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_CSIZE:	if (len != 4) /* set number of data bits */	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->csize = get_int32(buf);	slp->flags |= FL_CSIZE;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_CSIZE:	if (slp->flags & FL_CSIZE) /* pending */	    return ctl_reply_int(slp->csize, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_csize(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_BUFSZ:	if (len != 4) /* set number of bytes to buffer */	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	if ((slp->bufsz = get_int32(buf)) < 1)	    slp->bufsz = 1;	slp->flags |= FL_BUFSZ;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_BUFSZ:	if (slp->flags & FL_BUFSZ)	    return ctl_reply_int(slp->bufsz, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_bufsz(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_BUFTM:	if (len != 4) /* set buffer timeout */	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->buftm = get_int32(buf);	slp->flags |= FL_BUFTM;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_BUFTM:	if (slp->flags & FL_BUFTM)	    return ctl_reply_int(slp->buftm, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_buftm(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_STOPB:	if (len != 4) /* set buffer timeout */	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->stopb = get_int32(buf);	slp->flags |= FL_STOPB;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);	    case SL_GET_STOPB:	if (slp->flags & FL_STOPB)	    return ctl_reply_int(slp->stopb, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_stopb(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_PARITY:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->parity = get_int32(buf);	slp->flags |= FL_PARITY;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_PARITY:	if (slp->flags & FL_PARITY)	    return ctl_reply_int(slp->parity, rbuf, rsize);	else if (slp->com != INVALID) 	    return ctl_reply_int(get_parity(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_HWFLOW:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->hwflow = get_int32(buf);		slp->flags |= FL_HWFLOW;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_HWFLOW:	if (slp->flags & FL_HWFLOW)	    return ctl_reply_bool(slp->hwflow, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_bool(get_hwflow(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_SWFLOW:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->swflow = get_int32(buf);		slp->flags |= FL_SWFLOW;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_SWFLOW:	if (slp->flags & FL_SWFLOW)	    return ctl_reply_bool(slp->swflow, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_bool(get_swflow(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_XONCHAR:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->xonchar = get_int32(buf);		slp->flags |= FL_XONCHAR;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_XONCHAR:	if (slp->flags & FL_XONCHAR)	    return ctl_reply_int(slp->xonchar, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_xonchar(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_XOFFCHAR:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->xoffchar = get_int32(buf);		slp->flags |= FL_XOFFCHAR;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_XOFFCHAR:	if (slp->flags & FL_XOFFCHAR)	    return ctl_reply_int(slp->xoffchar, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_int(get_xoffchar(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_SET_ECHO:	if (len != 4)	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	slp->echo = get_int32(buf);		slp->flags |= FL_ECHO;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_ECHO:	if (slp->flags & FL_ECHO)	    return ctl_reply_bool(slp->echo, rbuf, rsize);	else if (slp->com != INVALID)	    return ctl_reply_bool(get_echo(slp), rbuf, rsize);	else	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);    case SL_CONNECT:    case SL_OPEN:	if (slp->dev == NULL) /* MUST set device first */	    return ctl_error(SL_ERR_BADARG, rbuf, rsize);	if (do_open(slp) < 0)	    return ctl_error(SL_ERR_ACCESS, rbuf, rsize);	/* For win32 we could? create a ComEvent handle */#ifdef __WIN32__	driver_select(slp->port,(ErlDrvEvent)slp->stat.hEvent,DO_READ,1);#else	driver_select(slp->port,(ErlDrvEvent)slp->com, DO_READ, 1);#endif	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_DISCONNECT:	do_hangup(slp);	/* fall through */    case SL_CLOSE:	do_close(slp);	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_XOFF:	do_send_xoff(slp);	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);	    case SL_XON:	/* send xon */	do_send_xon(slp);	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);	    case SL_BREAK:	/* send break */	do_send_break(slp);	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);	    case SL_UPDATE:	do_update(slp);	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_REVERT:	slp->flags = 0;	return ctl_reply(SL_OK, NULL, 0, rbuf, rsize);    case SL_GET_RATES: {	char rates[1+sizeof(int)*((sizeof(rtab)/sizeof(struct _rate))-1)];	char* ptr = rates+1;	int i = 0;		rates[0] = SL_INT;	while(rtab[i].baud != -1) {	    put_int32(rtab[i].baud, ptr);	    ptr += sizeof(int);	    i++;	}	return ctl_reply(SL_OK, rates, sizeof(rates), rbuf, rsize);    }    default:	return ctl_error(SL_ERR_BADARG, rbuf, rsize);    }}