本文整理汇总了C++中cfgetospeed函数的典型用法代码示例。如果您正苦于以下问题:C++ cfgetospeed函数的具体用法?C++ cfgetospeed怎么用?C++ cfgetospeed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cfgetospeed函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: putpad
static void
putpad(char *s)
{
int pad = 0;
speed_t ospeed = cfgetospeed(&tmode);
if (isdigit(*s)) {
while (isdigit(*s)) {
pad *= 10;
pad += *s++ - '0';
}
pad *= 10;
if (*s == '.' && isdigit(s[1])) {
pad += s[1] - '0';
s += 2;
}
}
xputs(s);
/*
* If no delay needed, or output speed is
* not comprehensible, then don't try to delay.
*/
if (pad == 0 || ospeed <= 0)
return;
/*
* Round up by a half a character frame, and then do the delay.
* Too bad there are no user program accessible programmed delays.
* Transmitting pad characters slows many terminals down and also
* loads the system.
*/
pad = (pad * ospeed + 50000) / 100000;
while (pad--)
putchr(*PC);
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:36,代码来源:main.c
示例2: speed
static void
speed(void)
{
printf("%s\n", baudrate(cfgetospeed(&ts)));
}
开发者ID:Sunshine-OS,项目名称:svr4-userland,代码行数:5,代码来源:stty.c
示例3: OpenSerialPort
// Given the path to a serial device, open the device and configure it.
// Return the file descriptor associated with the device.
static int OpenSerialPort(const char *bsdPath)
{
int handshake;
struct termios options;
// Check exsitance of joypad dev-node
// If not exists, make it
// if(mknod("/dev/tty.joypad", S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, const char *path, mode_t mode, dev_t dev)!=0)
// Check exsitance of iap dev-nodes (tty.iap, cu.iap, uart.iap)
// If exist, remove all of them
// Open the serial port read/write, with no controlling terminal, and don't wait for a connection.
// The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking.
// See open(2) ("man 2 open") for details.
fileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY | O_NONBLOCK |O_NDELAY);
if (fileDescriptor == -1)
{
printf("Error opening serial port %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
#if 1
// Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed
// unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned
// processes.
// See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
if (ioctl(fileDescriptor, TIOCEXCL) == -1)
{
printf("Error setting TIOCEXCL on %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
// Now that the device is open, set the O_NONBLOCK flag so subsequent I/O will be okay.
// See fcntl(2) ("man 2 fcntl") for details.
if (fcntl(fileDescriptor, F_SETFL, O_NONBLOCK) == -1)
{
printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
// Get the current options and save them so we can restore the default settings later.
if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1)
{
printf("Error getting tty attributes %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
// The serial port attributes such as timeouts and baud rate are set by modifying the termios
// structure and then calling tcsetattr() to cause the changes to take effect. Note that the
// changes will not become effective without the tcsetattr() call.
// See tcsetattr(4) ("man 4 tcsetattr") for details.
options = gOriginalTTYAttrs;
// Print the current input and output baud rates.
// See tcsetattr(4) ("man 4 tcsetattr") for details.
printf("Current input baud rate is %d\n", (int) cfgetispeed(&options));
printf("Current output baud rate is %d\n", (int) cfgetospeed(&options));
// Set raw input (non-canonical) mode, with reads blocking until either a single character
// has been received or a one second timeout expires.
// See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details.
cfmakeraw(&options);
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 10;
// The baud rate, word length, and handshake options can be set as follows:
cfsetspeed(&options, B9600); // Set 19200 baud
options.c_cflag |= (CS8); // Use 8 bit words
/* |
PARENB | // Parity enable (even parity if PARODD not also set)
CCTS_OFLOW | // CTS flow control of output
CRTS_IFLOW); // RTS flow control of input
*/
#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
// Starting with Tiger, the IOSSIOSPEED ioctl can be used to set arbitrary baud rates
// other than those specified by POSIX. The driver for the underlying serial hardware
// ultimately determines which baud rates can be used. This ioctl sets both the input
// and output speed.
speed_t speed = 9600; // Set 19200 baud
if (ioctl(fileDescriptor, IOSSIOSPEED, &speed) == -1)
{
printf("Error calling ioctl(..., IOSSIOSPEED, ...) %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
}
#endif
//.........这里部分代码省略.........
开发者ID:Garrant3,项目名称:gameboy4iphone,代码行数:101,代码来源:JoyPad.c
示例4: sh4uart_set_attributes
/*
* sh4uart_set_attributes --
* This function parse the termios attributes structure and perform
* the appropriate settings in hardware.
*
* PARAMETERS:
* uart - pointer to the UART descriptor structure
* t - pointer to termios parameters
*
* RETURNS:
* RTEMS_SUCCESSFUL
*/
rtems_status_code
sh4uart_set_attributes(sh4uart *uart, const struct termios *t)
{
int level;
speed_t baud;
uint16_t smr;
smr = (uint16_t)(*(uint8_t*)SH7750_SCSMR(uart->chn));
baud = cfgetospeed(t);
/* Set flow control XXX*/
if ((t->c_cflag & CRTSCTS) != 0) {
}
/* Set character size -- only 7 or 8 bit */
switch (t->c_cflag & CSIZE) {
case CS5:
case CS6:
case CS7: smr |= SH7750_SCSMR_CHR_7; break;
case CS8: smr &= ~SH7750_SCSMR_CHR_7; break;
}
/* Set number of stop bits */
if ((t->c_cflag & CSTOPB) != 0)
smr |= SH7750_SCSMR_STOP_2;
else
smr &= ~SH7750_SCSMR_STOP_2;
/* Set parity mode */
if ((t->c_cflag & PARENB) != 0) {
smr |= SH7750_SCSMR_PE;
if ((t->c_cflag & PARODD) != 0)
smr |= SH7750_SCSMR_PM_ODD;
else
smr &= ~SH7750_SCSMR_PM_ODD;
} else
smr &= ~SH7750_SCSMR_PE;
rtems_interrupt_disable(level);
/* wait untill all data is transmitted */
/* XXX JOEL says this is broken -- interrupts are OFF so NO ticks */
rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100));
if ( uart->chn == 1 ) {
volatile uint8_t *scrP = (volatile uint8_t *)SH7750_SCSCR1;
volatile uint8_t *smrP = (volatile uint8_t *)SH7750_SCSMR1;
*scrP &= ~(SH7750_SCSCR_TE | SH7750_SCSCR_RE); /* disable operations */
sh4uart_set_baudrate(uart, baud);
*smrP = (uint8_t)smr;
*scrP |= SH7750_SCSCR_TE | SH7750_SCSCR_RE; /* enable operations */
} else {
volatile uint16_t *scrP = (volatile uint16_t *)SH7750_SCSCR2;
volatile uint16_t *smrP = (volatile uint16_t *)SH7750_SCSMR2;
*scrP &= ~(SH7750_SCSCR_TE | SH7750_SCSCR_RE); /* disable operations */
sh4uart_set_baudrate(uart, baud);
*smrP = (uint8_t)smr;
*scrP |= SH7750_SCSCR_TE | SH7750_SCSCR_RE; /* enable operations */
}
rtems_interrupt_enable(level);
return RTEMS_SUCCESSFUL;
}
开发者ID:rtemss,项目名称:rtems,代码行数:78,代码来源:sh4uart.c
示例5: getname
static int
getname(void)
{
int c;
char *np;
unsigned char cs;
int ppp_state = 0;
int ppp_connection = 0;
/*
* Interrupt may happen if we use CBREAK mode
*/
if (setjmp(intrupt)) {
signal(SIGINT, SIG_IGN);
return (0);
}
signal(SIGINT, interrupt);
set_flags(1);
prompt();
oflush();
if (PF > 0) {
sleep(PF);
PF = 0;
}
if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
exit(1);
}
crmod = digit = lower = upper = 0;
np = name;
for (;;) {
oflush();
if (read(STDIN_FILENO, &cs, 1) <= 0)
exit(0);
if ((c = cs&0177) == 0)
return (0);
/* PPP detection state machine..
Look for sequences:
PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED or
PPP_FRAME, PPP_STATION, PPP_CONTROL (deviant from RFC)
See RFC1662.
Derived from code from Michael Hancock, <[email protected]>
and Erik 'PPP' Olson, <[email protected]>
*/
if (PP && (cs == PPP_FRAME)) {
ppp_state = 1;
} else if (ppp_state == 1 && cs == PPP_STATION) {
ppp_state = 2;
} else if (ppp_state == 2 && cs == PPP_ESCAPE) {
ppp_state = 3;
} else if ((ppp_state == 2 && cs == PPP_CONTROL)
|| (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
ppp_state = 4;
} else if (ppp_state == 4 && cs == PPP_LCP_HI) {
ppp_state = 5;
} else if (ppp_state == 5 && cs == PPP_LCP_LOW) {
ppp_connection = 1;
break;
} else {
ppp_state = 0;
}
if (c == EOT || c == CTRL('d'))
exit(0);
if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) {
putf("\r\n");
break;
}
if (islower(c))
lower = 1;
else if (isupper(c))
upper = 1;
else if (c == ERASE || c == '\b' || c == 0177) {
if (np > name) {
np--;
if (cfgetospeed(&tmode) >= 1200)
puts("\b \b");
else
putchr(cs);
}
continue;
} else if (c == KILL || c == CTRL('u')) {
putchr('\r');
if (cfgetospeed(&tmode) < 1200)
putchr('\n');
/* this is the way they do it down under ... */
else if (np > name)
puts(" \r");
prompt();
digit = lower = upper = 0;
np = name;
continue;
} else if (isdigit(c))
digit = 1;
if (IG && (c <= ' ' || c > 0176))
continue;
*np++ = c;
putchr(cs);
//.........这里部分代码省略.........
开发者ID:AhmadTux,项目名称:freebsd,代码行数:101,代码来源:main.c
示例6: wwinit
wwinit()
{
register i, j;
char *kp;
int s;
wwdtablesize = getdtablesize();
wwhead.ww_forw = &wwhead;
wwhead.ww_back = &wwhead;
s = sigblock(sigmask(SIGIO));
if (signal(SIGIO, wwrint) == BADSIG ||
signal(SIGCHLD, wwchild) == BADSIG ||
signal(SIGPIPE, SIG_IGN) == BADSIG) {
wwerrno = WWE_SYS;
return -1;
}
if (wwgettty(0, &wwoldtty) < 0)
return -1;
wwwintty = wwoldtty;
#ifdef OLD_TTY
wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
wwnewtty.ww_sgttyb.sg_erase = -1;
wwnewtty.ww_sgttyb.sg_kill = -1;
wwnewtty.ww_sgttyb.sg_flags |= CBREAK;
wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD);
wwnewtty.ww_tchars.t_intrc = -1;
wwnewtty.ww_tchars.t_quitc = -1;
wwnewtty.ww_tchars.t_startc = -1;
wwnewtty.ww_tchars.t_stopc = -1;
wwnewtty.ww_tchars.t_eofc = -1;
wwnewtty.ww_tchars.t_brkc = -1;
wwnewtty.ww_ltchars.t_suspc = -1;
wwnewtty.ww_ltchars.t_dsuspc = -1;
wwnewtty.ww_ltchars.t_rprntc = -1;
wwnewtty.ww_ltchars.t_flushc = -1;
wwnewtty.ww_ltchars.t_werasc = -1;
wwnewtty.ww_ltchars.t_lnextc = -1;
wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
#else
#ifndef OXTABS
#define OXTABS XTABS
#endif
#ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE -1
#endif
wwwintty.ww_termios.c_oflag &= ~OXTABS;
wwnewtty.ww_termios = wwoldtty.ww_termios;
wwnewtty.ww_termios.c_iflag &=
~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
wwnewtty.ww_termios.c_iflag |= INPCK;
wwnewtty.ww_termios.c_oflag = 0;
wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
wwnewtty.ww_termios.c_cflag |= CS8;
wwnewtty.ww_termios.c_lflag = 0;
for (i = 0; i < NCCS; i++)
wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
#endif
wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
if (wwsettty(0, &wwnewtty) < 0)
goto bad;
if ((wwterm = getenv("TERM")) == 0) {
wwerrno = WWE_BADTERM;
goto bad;
}
if (tgetent(wwtermcap, wwterm) != 1) {
wwerrno = WWE_BADTERM;
goto bad;
}
#ifdef OLD_TTY
wwospeed = wwoldtty.ww_sgttyb.sg_ospeed;
#else
wwospeed = cfgetospeed(&wwoldtty.ww_termios);
#endif
switch (wwospeed) {
default:
case B0:
wwbaud = 0;
break;
case B50:
wwbaud = 50;
break;
case B75:
wwbaud = 75;
break;
case B110:
wwbaud = 110;
break;
case B134:
wwbaud = 134;
break;
case B150:
wwbaud = 150;
break;
case B200:
wwbaud = 200;
//.........这里部分代码省略.........
开发者ID:dank101,项目名称:386BSD,代码行数:101,代码来源:wwinit.c
示例7: set_custom_baud_rate
// Attempts to set the baud rate to the closest rate possible to
// the desired_baudrate argument using divisors.
// fport is the file descriptor for the port opened by a call to serial_connect() or open()
// Divisor method:
// it should be possible to do custom baud rates by using a divisor, like
// you would do when you call "setserial /dev/ttyS0 baud_base 115200 divisor 14 spd_cust"
// If the call to setserial wouldn't work for the device, the divisor method wont work here either.
// This is usually due to an unimplemented ioctl function in the device driver.
// Termios custom baud rate method:
// I think tty_ioctl.c has to be compiled into the kernel with BOTHER defined for this to work.
// set cbaud to BOTHER and c_ospeed to the desired setting.
// This is done through a call to set_custom_baud_rate_no_ioctl()
int set_custom_baud_rate(int fport, unsigned int desired_baudrate)
{
unsigned int new_baudrate;
struct termios port_attrib;
struct serial_struct serial_info;
int divisor = 1;
if (tcgetattr(fport, &port_attrib) < 0)
{
printf(" tcgetattr() failed to get port settings.\n");
return -1;
}
if (ioctl(fport, TIOCGSERIAL, &serial_info) !=0)
{
printf(" ioctl TIOCGSERIAL failed to get port settings: %s.\n",strerror(errno));
return set_custom_baud_rate_no_ioctl(fport, desired_baudrate);
}
// set the baudrate to B38400 (custom baud setting)
if (cfsetspeed(&port_attrib,B38400) < 0)
{ printf(" Call to cfsetspeed failed. Unable to set baud rate.\n");
return -1;
}
// clear the serial line
tcflush(fport, TCIOFLUSH);
// XXX should make this round to nearest integer instead of
// just using integer division with drops the fractional component
// set the base baud rate if it is less than 115200, to 115200
if (serial_info.baud_base < 115200)
serial_info.baud_base = 115200;
divisor = serial_info.baud_base / desired_baudrate;
// set the custom divisor
serial_info.custom_divisor = divisor;
// set the ASYNC_SPD_CUST flag
serial_info.flags |= (ASYNC_SPD_MASK & ASYNC_SPD_CUST);
// apply the port settings (divisor and baud base)
if (ioctl(fport,TIOCSSERIAL,&serial_info) !=0)
{
printf(" ioctl() TIOCSSERIAL failed to set custom baud rate: %s.\n",strerror(errno));
return set_custom_baud_rate_no_ioctl(fport, desired_baudrate);
}
// apply the port settings (baud rate)
if (tcsetattr(fport,TCSANOW,&port_attrib) < 0)
{
printf(" Failed to apply new port settings.\n");
return -1;
}
// try to get the new termios port settings
if (tcgetattr(fport, &port_attrib) < 0)
{
printf(" Failed to get new port settings.\n");
return -1;
}
// check the new baud rate
new_baudrate = cfgetospeed(&port_attrib);
if ((new_baudrate != B38400) && (new_baudrate != CBAUDEX))
{
printf(" Custom baud rate could not be set with tcsetattr.\n");
return -1;
}
// try to get the new ioctl port settings
if (ioctl(fport, TIOCGSERIAL, &serial_info) !=0)
{
printf(" ioctl TIOCGSERIAL failed to get new port settings.\n");
return set_custom_baud_rate_no_ioctl(fport, desired_baudrate);
}
// check the new baud rate and divisor
if (serial_info.custom_divisor!= divisor)
{
printf(" Custom baud rate could not be set by ioctl.\n");
return set_custom_baud_rate_no_ioctl(fport, desired_baudrate);
}
new_baudrate = serial_info.baud_base/serial_info.custom_divisor;
printf(" Baud rate set to: %d. (%d was requested)\n",new_baudrate, desired_baudrate);
//.........这里部分代码省略.........
开发者ID:DaElf,项目名称:linuxaldl,代码行数:101,代码来源:sts_serial.c
示例8: main
//.........这里部分代码省略.........
return (EXIT_FAILURE);
}
}
if (port_number == 0) {
if (krb5auth_flag) {
struct servent *sp;
/*
* If the krb5auth_flag is set (via -A, -f, -F, -k) &
* if there is an entry in /etc/services for Kerberos
* login, attempt to login with Kerberos. If we fail
* at any step, use the standard rlogin
*/
sp = getservbyname(encrypt_flag ?
"eklogin" : "klogin", "tcp");
if (sp == NULL) {
port_number = encrypt_flag ?
htons(2105) : htons(543);
} else {
port_number = sp->s_port;
}
} else {
port_number = htons(IPPORT_LOGINSERVER);
}
}
cp = getenv("TERM");
if (cp) {
(void) strncpy(term, cp, sizeof (term));
term[sizeof (term) - 1] = '\0';
}
if (getattr_ret == 0) {
speed = cfgetospeed(&savetty);
/*
* "Be conservative in what we send" -- Only send baud rates
* which at least all 4.x BSD derivatives are known to handle
* correctly.
* NOTE: This code assumes new termios speed values will
* be "higher" speeds.
*/
if (speed > B38400)
speed = B38400;
}
/*
* Only put the terminal speed info in if we have room
* so we don't overflow the buffer, and only if we have
* a speed we recognize.
*/
if (speed > 0 && speed < sizeof (speeds)/sizeof (char *) &&
strlen(term) + strlen("/") + strlen(speeds[speed]) + 1 <
sizeof (term)) {
(void) strcat(term, "/");
(void) strcat(term, speeds[speed]);
}
(void) sigset(SIGPIPE, (sigdisp_t)lostpeer);
/* will use SIGUSR1 for window size hack, so hold it off */
oldmask = sigblock(sigmask(SIGURG) | sigmask(SIGUSR1));
/*
* Determine if v4 literal address and if so store it to one
* side. This is to correct the undesired behaviour of rcmd_af
* which converts a passed in v4 literal address to a v4 mapped
* v6 literal address. If it was a v4 literal we then re-assign
* it to host.
开发者ID:alhazred,项目名称:onarm,代码行数:67,代码来源:rlogin.c
示例9: f_speed
void
f_speed(struct info *ip)
{
(void)printf("%d\n", cfgetospeed(&ip->t));
}
开发者ID:UNGLinux,项目名称:Obase,代码行数:6,代码来源:key.c
示例10: get_com_state
static int get_com_state(int fd, uart_com_state_t* com)
{
struct termios tio;
if (tcgetattr(fd, &tio) < 0)
return -1;
// input baud reate
com->ibaud = from_speed(cfgetispeed(&tio));
com->obaud = from_speed(cfgetospeed(&tio));
// parity
if (tio.c_cflag & PARENB) {
if (tio.c_iflag & PARMRK)
com->parity = UART_PARITY_MARK;
else if (tio.c_cflag & PARODD)
com->parity = UART_PARITY_ODD;
else
com->parity = UART_PARITY_EVEN;
}
else
com->parity = UART_PARITY_NONE;
// stop bits
if (tio.c_cflag & CSTOPB)
com->stopb = 2;
else
com->stopb = 1;
// csize
switch(tio.c_cflag & CSIZE) {
case CS5: com->csize = 5; break;
case CS6: com->csize = 6; break;
case CS7: com->csize = 7; break;
case CS8: com->csize = 8; break;
default: break;
}
// may be used for {packet, {size,N}} and also when
// in {packet,N} (N!=0) when waiting for a certain amount of data
com->bufsz = tio.c_cc[VMIN]; // min number of bytes buffered
com->buftm = tio.c_cc[VTIME]*100;
com->xonchar = tio.c_cc[VSTART];
com->xoffchar = tio.c_cc[VSTOP];
com->iflow = 0;
if (tio.c_iflag & IXOFF) com->iflow |= UART_SW;
#if defined(CRTS_IFLOW)
if (tio.c_cflag & CRTS_IFLOW) com->iflow |= UART_RTS;
#endif
#if defined(CDTR_IFLOW)
if (tio.c_cflag & CDTR_IFLOW) com->iflow |= UART_DTR;
#endif
com->oflow = 0;
if (tio.c_iflag & IXON) com->oflow |= UART_SW;
#if defined(CCTS_OFLOW)
if (tio.c_cflag & CCTS_OFLOW) com->oflow |= UART_CTS;
#endif
#if defined(CDSR_OFLOW)
if (tio.c_cflag & CDSR_OFLOW) com->oflow |= UART_DSR;
#endif
#if defined(CCAR_OFLOW)
if (tio.c_cflag & CCAR_OFLOW) com->oflow |= UART_CD;
#endif
#if defined(CRTSCTS)
if ((tio.c_cflag & CRTSCTS) == CRTSCTS) {
com->oflow |= UART_CTS; //com->oflow |= UART_CD;
com->iflow |= UART_RTS;
}
#endif
return 0;
}
开发者ID:GENIVI,项目名称:rvi_core,代码行数:73,代码来源:uart_unix.c
示例11: main
int main(int argc,char *argv[]) {
int i;
for (i=0; i<1024; ++i) {
printf("%08x%c",arc4random(),(i&15)==15 ? '\n' : ' ');
}
perror("write");
#if 0
int n;
struct ucontext uc;
n=0;
getcontext(&uc);
puts("getcontext returned");
if (n==0) {
++n;
setcontext(&uc);
puts("should not get here");
exit(1);
}
puts("all ok");
return 0;
#endif
#if 0
char* a=malloc(-3);
char* b=malloc(0xffffffffull+1);
printf("%p %p\n",a,b);
#endif
#if 0
printf("%u\n",getpagesize());
#endif
#if 0
struct stat s;
time_t t=time(0);
struct tm* T;
stat("/tmp/nyt.html",&s);
T=gmtime(&s.st_mtime);
#endif
#if 0
static struct mq_attr x;
mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x);
mqd_t b=mq_open("fnord",O_RDONLY);
#endif
#if 0
struct statfs s;
if (statfs("/tmp",&s)!=-1) {
printf("%llu blocks, %llu free\n",(unsigned long long)s.f_blocks,(unsigned long long)s.f_bfree);
}
#endif
#if 0
char* c=strndupa("fnord",3);
puts(c);
#endif
#if 0
char buf[100];
__write2("foo!\n");
memset(buf,0,200);
#endif
#if 0
printf("%+05d\n",500);
#endif
#if 0
char* c;
printf("%d\n",asprintf(&c,"foo %d",23));
puts(c);
#endif
#if 0
struct winsize ws;
if (!ioctl(0, TIOCGWINSZ, &ws)) {
printf("%dx%d\n",ws.ws_col,ws.ws_row);
}
#endif
#if 0
struct termios t;
if (tcgetattr(1,&t)) {
puts("tcgetattr failed!");
return 1;
}
printf("%d\n",cfgetospeed(&t));
#endif
#if 0
printf("%p\n",malloc(0));
#endif
#if 0
char* argv[]= {"sh","-i",0};
char buf[PATH_MAX+100];
int i;
for (i=0; i<PATH_MAX+20; ++i) buf[i]='a';
memmove(buf,"PATH=/",6);
strcpy(buf+i,"/bin:/bin");
putenv(buf);
execvp("sh",argv);
printf("%d\n",islower(0xfc));
#endif
#if 0
char buf[101];
__dtostr(-123456789.456,buf,100,6,2);
puts(buf);
return 0;
#endif
#if 0
time_t t=1009921588;
//.........这里部分代码省略.........
开发者ID:ensc,项目名称:dietlibc,代码行数:101,代码来源:t.c
示例12: set_baud_rate
//.........这里部分代码省略.........
case 110:
case CBR_110: cfsetospeed( &port, B110 ); break;
case 134: cfsetospeed( &port, B134 ); break;
case 150: cfsetospeed( &port, B150 ); break;
case 200: cfsetospeed( &port, B200 ); break;
case 300:
case CBR_300: cfsetospeed( &port, B300 ); break;
case 600:
case CBR_600: cfsetospeed( &port, B600 ); break;
case 1200:
case CBR_1200: cfsetospeed( &port, B1200 ); break;
case 1800: cfsetospeed( &port, B1800 ); break;
case 2400:
case CBR_2400: cfsetospeed( &port, B2400 ); break;
case 4800:
case CBR_4800: cfsetospeed( &port, B4800 ); break;
case 9600:
case CBR_9600: cfsetospeed( &port, B9600 ); break;
case 19200:
case CBR_19200: cfsetospeed( &port, B19200 ); break;
case 38400:
case CBR_38400: cfsetospeed( &port, B38400 ); break;
#ifdef B57600
case 57600: cfsetospeed( &port, B57600 ); break;
#endif
#ifdef B115200
case 115200: cfsetospeed( &port, B115200 ); break;
#endif
#ifdef B230400
case 230400: cfsetospeed( &port, B230400 ); break;
#endif
#ifdef B460800
case 460800: cfsetospeed( &port, B460800 ); break;
#endif
#ifdef B500000
case 500000: cfsetospeed( &port, B500000 ); break;
#endif
#ifdef B921600
case 921600: cfsetospeed( &port, B921600 ); break;
#endif
#ifdef B1000000
case 1000000: cfsetospeed( &port, B1000000 ); break;
#endif
#ifdef B1152000
case 1152000: cfsetospeed( &port, B1152000 ); break;
#endif
#ifdef B1500000
case 1500000: cfsetospeed( &port, B1500000 ); break;
#endif
#ifdef B2000000
case 2000000: cfsetospeed( &port, B2000000 ); break;
#endif
#ifdef B2500000
case 2500000: cfsetospeed( &port, B2500000 ); break;
#endif
#ifdef B3000000
case 3000000: cfsetospeed( &port, B3000000 ); break;
#endif
#ifdef B3500000
case 3500000: cfsetospeed( &port, B3500000 ); break;
#endif
#ifdef B4000000
case 4000000: cfsetospeed( &port, B4000000 ); break;
#endif
default:
#if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
{
struct serial_struct nuts;
int arby;
ioctl(fd, TIOCGSERIAL, &nuts);
nuts.custom_divisor = nuts.baud_base / sbr->BaudRate;
if (!(nuts.custom_divisor)) nuts.custom_divisor = 1;
arby = nuts.baud_base / nuts.custom_divisor;
nuts.flags &= ~ASYNC_SPD_MASK;
nuts.flags |= ASYNC_SPD_CUST;
WARN("You (or a program acting at your behest) have specified\n"
"a non-standard baud rate %d. Wine will set the rate to %d,\n"
"which is as close as we can get by our present understanding of your\n"
"hardware. I hope you know what you are doing. Any disruption Wine\n"
"has caused to your linux system can be undone with setserial\n"
"(see man setserial). If you have incapacitated a Hayes type modem,\n"
"reset it and it will probably recover.\n", sbr->BaudRate, arby);
ioctl(fd, TIOCSSERIAL, &nuts);
cfsetospeed( &port, B38400 );
}
break;
#else /* Don't have linux/serial.h or lack TIOCSSERIAL */
ERR("baudrate %d\n", sbr->BaudRate);
return STATUS_NOT_SUPPORTED;
#endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
}
cfsetispeed( &port, cfgetospeed(&port) );
if (tcsetattr(fd, TCSANOW, &port) == -1)
{
ERR("tcsetattr error '%s'\n", strerror(errno));
return FILE_GetNtStatus();
}
return STATUS_SUCCESS;
}
开发者ID:AlexSteel,项目名称:wine,代码行数:101,代码来源:serial.c
示例13: get_baud_rate
static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr)
{
struct termios port;
int speed;
if (tcgetattr(fd, &port) == -1)
{
ERR("tcgetattr error '%s'\n", strerror(errno));
return FILE_GetNtStatus();
}
speed = cfgetospeed(&port);
switch (speed)
{
case B0: sbr->BaudRate = 0; break;
case B50: sbr->BaudRate = 50; break;
case B75: sbr->BaudRate = 75; break;
case B110: sbr->BaudRate = 110; break;
case B134: sbr->BaudRate = 134; break;
case B150: sbr->BaudRate = 150; break;
case B200: sbr->BaudRate = 200; break;
case B300: sbr->BaudRate = 300; break;
case B600: sbr->BaudRate = 600; break;
case B1200: sbr->BaudRate = 1200; break;
case B1800: sbr->BaudRate = 1800; break;
case B2400: sbr->BaudRate = 2400; break;
case B4800: sbr->BaudRate = 4800; break;
case B9600: sbr->BaudRate = 9600; break;
case B19200: sbr->BaudRate = 19200; break;
case B38400: sbr->BaudRate = 38400; break;
#ifdef B57600
case B57600: sbr->BaudRate = 57600; break;
#endif
#ifdef B115200
case B115200: sbr->BaudRate = 115200; break;
#endif
#ifdef B230400
case B230400: sbr->BaudRate = 230400; break;
#endif
#ifdef B460800
case B460800: sbr->BaudRate = 460800; break;
#endif
#ifdef B500000
case B500000: sbr->BaudRate = 500000; break;
#endif
#ifdef B921600
case B921600: sbr->BaudRate = 921600; break;
#endif
#ifdef B1000000
case B1000000: sbr->BaudRate = 1000000; break;
#endif
#ifdef B1152000
case B1152000: sbr->BaudRate = 1152000; break;
#endif
#ifdef B1500000
case B1500000: sbr->BaudRate = 1500000; break;
#endif
#ifdef B2000000
case B2000000: sbr->BaudRate = 2000000; break;
#endif
#ifdef B2500000
case B2500000: sbr->BaudRate = 2500000; break;
#endif
#ifdef B3000000
case B3000000: sbr->BaudRate = 3000000; break;
#endif
#ifdef B3500000
case B3500000: sbr->BaudRate = 3500000; break;
#endif
#ifdef B4000000
case B4000000: sbr->BaudRate = 4000000; break;
#endif
default:
ERR("unknown speed %x\n", speed);
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
开发者ID:AlexSteel,项目名称:wine,代码行数:77,代码来源:serial.c
示例14: set
static void
set(void)
{
int i, gotcha, not, sspeed = 0;
speed_t ispeed0, ospeed0, ispeed1, ospeed1;
const char *ap;
struct termios tc;
ispeed0 = ispeed1 = cfgetispeed(&ts);
ospeed0 = ospeed1 = cfgetospeed(&ts);
while (*args) {
for (i = 0; speeds[i].s_str; i++)
if (strcmp(speeds[i].s_str, *args) == 0) {
ispeed1 = ospeed1 = speeds[i].s_val;
sspeed |= 3;
goto next;
}
gotcha = 0;
if (**args == '-') {
not = 1;
ap = &args[0][1];
} else {
not = 0;
ap = *args;
}
for (i = 0; modes[i].m_name; i++) {
if (modes[i].m_type == M_SEPAR || modes[i].m_flg&0100)
continue;
if (strcmp(modes[i].m_name, ap) == 0) {
gotcha++;
switch (modes[i].m_type) {
case M_IFLAG:
setmod(&ts.c_iflag, modes[i], not);
break;
case M_OFLAG:
setmod(&ts.c_oflag, modes[i], not);
break;
case M_CFLAG:
case M_PCFLAG:
setmod(&ts.c_cflag, modes[i], not);
break;
case M_LFLAG:
setmod(&ts.c_lflag, modes[i], not);
break;
case M_CC:
if (not)
inval();
setchr(ts.c_cc, modes[i]);
break;
case M_FUNCT:
modes[i].m_func(not);
break;
}
}
}
if (gotcha)
goto next;
if (strcmp(*args, "ispeed") == 0) {
if (*++args == NULL)
break;
if (atol(*args) == 0) {
ispeed1 = ospeed1;
sspeed |= 1;
goto next;
} else for (i = 0; speeds[i].s_str; i++)
if (strcmp(speeds[i].s_str, *args) == 0) {
ispeed1 = speeds[i].s_val;
sspeed |= 1;
goto next;
}
inval();
}
if (strcmp(*args, "ospeed") == 0) {
if (*++args == NULL)
break;
for (i = 0; speeds[i].s_str; i++)
if (strcmp(speeds[i].s_str, *args) == 0) {
ospeed1 = speeds[i].s_val;
sspeed |= 2;
goto next;
}
inval();
}
gset();
next: args++;
}
if (sspeed) {
if (sspeed == 3 && ispeed1 != ospeed1 && ospeed1 != B0) {
tc = ts;
cfsetispeed(&tc, ispeed1);
if (cfgetospeed(&tc) == cfgetospeed(&ts)) {
tc = ts;
cfsetospeed(&tc, ospeed1);
if (cfgetispeed(&tc) == cfgetispeed(&ts)) {
cfsetispeed(&ts, ispeed1);
cfsetospeed(&ts, ospeed1);
}
}
} else {
if (ispeed0 != ispeed1)
//.........这里部分代码省略.........
开发者ID:Sunshine-OS,项目名称:svr4-userland,代码行数:101,代码来源:stty.c
示例15: list
static void
list(int aflag, int hflag)
{
int i, d = 0;
speed_t is, os;
is = cfgetispeed(&ts);
os = cfgetospeed(&ts);
if (is == os)
printf("speed %s baud;", baudrate(is));
else
printf("ispeed %s baud; ospeed %s baud;",
baudrate(is), baudrate(os));
if (aflag == 0) {
for (i = 0; modes[i].m_name; i++) {
if (modes[i].m_type == M_PCFLAG)
d += listmode(ts.c_cflag, modes[i], aflag, 1);
}
d = 0;
}
if (sysv3 && aflag == 0) {
putchar('\n');
} else {
putchar(sysv3 ? ' ' : '\n');
printf("rows = %d%s columns = %d; "
"ypixels = %d%s xpixels = %d%s\n",
(int)ws.ws_row,
aflag&&hflag ? "" : ";",
(int)ws.ws_col,
(int)ws.ws_ypixel,
aflag&&hflag ? "" : ";",
(int)ws.ws_xpixel,
aflag&&hflag ? "" : ";");
}
if ((ts.c_lflag&ICANON) == 0)
printf("min = %d; time = %d;\n",
(int)ts.c_cc[VMIN], (int)ts.c_cc[VTIME]);
for (i = 0; modes[i].m_name; i++) {
if (modes[i].m_flg&040)
continue;
switch (modes[i].m_type) {
case M_NSEPAR:
if (sysv3)
break;
case M_SEPAR:
if (d && (modes[i].m_flg&8 ||
(modes[i].m_flg&(aflag?2:4)) == 0)) {
fputs(modes[i].m_name, stdout);
d = 0;
}
break;
case M_IFLAG:
d += listmode(ts.c_iflag, modes[i], aflag, d);
break;
case M_OFLAG:
d += listmode(ts.c_oflag, modes[i], aflag, d);
break;
case M_CFLAG:
d += listmode(ts.c_cflag, modes[i], aflag, d);
break;
case M_LFLAG:
d += listmode(ts.c_lflag, modes[i], aflag, d);
break;
case M_CC:
if (hflag == 0)
d += listchar(ts.c_cc, modes[i], aflag, d);
break;
}
if (d >= 72 && aflag == 0) {
putchar('\n');
d = 0;
}
}
if (d && aflag == 0)
putchar('\n');
}
开发者ID:Sunshine-OS,项目名称:svr4-userland,代码行数:76,代码来源:stty.c
示例16: cfgetispeed
QPortSettings::BaudRate TermiosHelper::baudRate() const
{
speed_t ibaud = cfgetispeed(currentAttrs_);
speed_t obaud = cfgetospeed(currentAttrs_);
(obaud == ibaud);
Q_ASSERT(ibaud == obaud);
switch ( ibaud ) {
case B50:
return QPortSettings::BAUDR_50;
case B75:
return QPortSettings::BAUDR_75;
case B110:
return QPortSettings::BAUDR_110;
case B134:
return QPortSettings::BAUDR_134;
case B150:
return QPortSettings::BAUDR_150;
case B200:
return QPortSettings::BAUDR_200;
case B300:
return QPortSettings::BAUDR_300;
case B600:
return QPortSettings::BAUDR_600;
case B1200:
return QPortSettings::BAUDR_1200;
case B1800:
return QPortSettings::BAUDR_1800;
case B2400:
return QPortSettings::BAUDR_2400;
case B4800:
return QPortSettings::BAUDR_4800;
case B9600:
return QPortSettings::BAUDR_9600;
case B19200:
return QPortSettings::BAUDR_19200;
case B38400:
return QPortSettings::BAUDR_38400;
case B57600:
return QPortSettings::BAUDR_57600;
//case B76800:
// return QPortSettings::BAUDR_76800;
case B115200:
return QPortSettings::BAUDR_115200;
#ifdef B230400
case B230400:
return QPortSettings::BAUDR_230400;
#else
case 230400:
return QPortSettings::BAUDR_230400;
#endif
#ifdef B460800
case B460800:
return QPortSettings::BAUDR_460800;
#else
case 460800:
return QPortSettings::BAUDR_460800;
#endif
#ifdef B500000
case B500000:
return QPortSettings::BAUDR_500000;
#else
case 500000:
return QPortSettings::BAUDR_500000;
#endif
#ifdef B576000:
case B576000:
return QPortSettings::BAUDR_576000;
#else
case 576000:
return QPortSettings::BAUDR_576000;
#endif
#ifdef B921600
case B921600:
return QPortSettings::BAUDR_921600;
#else
case 921600:
return QPortSettings::BAUDR_921600;
#endif
default:
qWarning() << "TermiosHelper::baudRate(): Unknown baud rate";
}
return QPortSettings::BAUDR_UNKNOWN;
}
开发者ID:benachtal,项目名称:qgroundcontrol,代码行数:87,代码来源:termioshelper.cpp
示例17: print
void
print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
{
struct cchar *p;
long tmp;
u_char *cc;
int cnt, ispeed, ospeed;
char buf1[100], buf2[100];
cnt = 0;
/* Line discipline. */
if (ldisc != TTYDISC) {
switch(ldisc) {
case SLIPDISC:
cnt += printf("slip disc; ");
break;
case PPPDISC:
cnt += printf("ppp disc; ");
break;
default:
cnt += printf("#%d disc; ", ldisc);
break;
}
}
/* Line speed. */
ispeed = cfgetispeed(tp);
ospeed = cfgetospeed(tp);
if (ispeed != ospeed)
cnt +=
printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
else
cnt += printf("speed %d baud;", ispeed);
if (fmt >= BSD)
cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
if (cnt)
(void)printf("\n");
#define on(f) ((tmp & (f)) != 0)
#define put(n, f, d) \
if (fmt >= BSD || on(f) != (d)) \
bput((n) + on(f));
/* "local" flags */
tmp = tp->c_lflag;
binit("lflags");
put("-icanon", ICANON, 1);
put("-isig", ISIG, 1);
put("-iexten", IEXTEN, 1);
put("-echo", ECHO, 1);
put("-echoe", ECHOE, 0);
put("-echok", ECHOK, 0);
put("-echoke", ECHOKE, 0);
put("-echonl", ECHONL, 0);
put("-echoctl", ECHOCTL, 0);
put("-echoprt", ECHOPRT, 0);
put("-altwerase", ALTWERASE, 0);
put("-noflsh", NOFLSH, 0);
put("-tostop", TOSTOP, 0);
put("-flusho", FLUSHO, 0);
put("-pendin", PENDIN, 0);
put("-nokerninfo", NOKERNINFO, 0);
put("-extproc", EXTPROC, 0);
/* input flags */
tmp = tp->c_iflag;
binit("iflags");
put("-istrip", ISTRIP, 0);
put("-icrnl", ICRNL, 1);
put("-inlcr", INLCR, 0);
put("-igncr", IGNCR, 0);
put("-ixon", IXON, 1);
put("-ixoff", IXOFF, 0);
put("-ixany", IXANY, 1);
put("-imaxbel", IMAXBEL, 1);
put("-ignbrk", IGNBRK, 0);
put("-brkint", BRKINT, 1);
put("-inpck", INPCK, 0);
put("-ignpar", IGNPAR, 0);
put("-parmrk", PARMRK, 0);
/* output flags */
tmp = tp->c_oflag;
binit("oflags");
put("-opost", OPOST, 1);
put("-onlcr", ONLCR, 1);
put("-ocrnl", OCRNL, 0);
switch(tmp&TABDLY) {
case TAB0:
bput("tab0");
break;
case TAB3:
bput("tab3");
break;
}
put("-onocr", ONOCR, 0);
put("-onlret", ONLRET, 0);
/* control flags (hardware state) */
//.........这里部分代码省略.........
开发者ID:jhbsz,项目名称:JabirOS-source,代码行数:101,代码来源:print.c
示例18: get_termios
//.........这里部分代码省略.........
info->baud_rate = 1800;
break;
#endif
#ifdef B2400
case B2400:
info->baud_rate = 2400;
break;
#endif
#ifdef B4800
case B4800:
info->baud_rate = 4800;
break;
#endif
#ifdef B9600
case B9600:
info->baud_rate = 9600;
break;
#endif
#ifdef B19200
case B19200:
info->baud_rate = 19200;
break;
#endif
#ifdef B38400
case B38400:
info->baud_rate = 38400;
break;
#endif
#ifdef B57600
case B57600:
info->baud_rate = 57600;
break;
#endif
#ifdef B115200
case B115200:
info->baud_rate = 115200;
break;
#endif
#ifdef B230400
case B230400:
info->baud_rate = 230400;
break;
#endif
#ifdef B460800
case B460800:
info->baud_rate = 460800;
break;
#endif
default:
info->baud_rate = 9600;
break;
}
speed = cfgetospeed(ptermios);
info->dtr = (speed == B0) ? 0 : 1;
info->stop_bits = (ptermios->c_cflag & CSTOPB) ? STOP_BITS_2 : STOP_BITS_1;
info->parity =
(ptermios->c_cflag & PARENB) ? ((ptermios->c_cflag & PARODD) ? ODD_PARITY :
EVEN_PARITY) : NO_PARITY;
switch (ptermios->c_cflag & CSIZE)
{
case CS5:
info->word_length = 5;
break;
case CS6:
info->word_length = 6;
break;
case CS7:
info->word_length = 7;
break;
default:
info->word_length = 8;
break;
}
if (ptermios->c_cflag & CRTSCTS)
{
info->control = SERIAL_DTR_CONTROL | SERIAL_CTS_HANDSHAKE | SERIAL_ERROR_ABORT;
}
else
{
info->control = SERIAL_DTR_CONTROL | SERIAL_ERROR_ABORT;
}
info->xonoff = SERIAL_DSR_SENSITIVITY;
if (ptermios->c_iflag & IXON)
info->xonoff |= SERIAL_XON_HANDSHAKE;
if (ptermios->c_iflag & IXOFF)
info->xonoff |= SERIAL_XOFF_
|
请发表评论