diff options
author | Fritz Elfert <felfert@to.com> | 2002-02-14 06:22:48 +0000 |
---|---|---|
committer | Fritz Elfert <felfert@to.com> | 2002-02-14 06:22:48 +0000 |
commit | 5ec639c55a86f62d9ac6439fc146d4854ca56856 (patch) | |
tree | 473d87a15dfbd4485d228d1729b1469923681df5 /ncpd/mp_serial.c | |
parent | 1e2cead07bb1e106fecace944765ec33cd351dcb (diff) | |
download | plptools-5ec639c55a86f62d9ac6439fc146d4854ca56856.tar.gz plptools-5ec639c55a86f62d9ac6439fc146d4854ca56856.tar.bz2 plptools-5ec639c55a86f62d9ac6439fc146d4854ca56856.zip |
- re indented
Diffstat (limited to 'ncpd/mp_serial.c')
-rw-r--r-- | ncpd/mp_serial.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/ncpd/mp_serial.c b/ncpd/mp_serial.c index cf6ff68..155dea1 100644 --- a/ncpd/mp_serial.c +++ b/ncpd/mp_serial.c @@ -67,128 +67,128 @@ int init_serial(const char *dev, int speed, int debug) { - int fd, baud, clocal; - int uid, euid; - struct termios ti; + int fd, baud, clocal; + int uid, euid; + struct termios ti; #ifdef hpux - struct termiox tx; + struct termiox tx; #endif - static struct baud { - int speed, baud; - } btable[] = { - { 9600, B9600 }, + static struct baud { + int speed, baud; + } btable[] = { + { 9600, B9600 }, #ifdef B19200 - { 19200, B19200 }, + { 19200, B19200 }, #else #ifdef EXTA - { 19200, EXTA }, + { 19200, EXTA }, #endif #endif #ifdef B38400 - { 38400, B38400 }, + { 38400, B38400 }, #else #ifdef EXTB - { 38400, EXTB }, + { 38400, EXTB }, #endif #endif #ifdef B57600 - { 57600, B57600 }, + { 57600, B57600 }, #endif #ifdef B115200 - { 115200, B115200 }, -#endif - { 4800, B4800 }, - { 2400, B2400 }, - { 1200, B1200 }, - { 300, B300 }, - { 75, B75 }, - { 50, B50 }, - { 0, 0 } - }, *bptr; - - if (speed) { - for (bptr = btable; bptr->speed; bptr++) - if (bptr->speed == speed) - break; - if (!bptr->baud) { - fprintf(stderr, "Cannot match selected speed %d\n", speed); - exit(1); - } - baud = bptr->baud; - } else - baud = 0; - - if (debug) - printf("using %s...\n", dev); - euid = geteuid(); - uid = getuid(); + { 115200, B115200 }, +#endif + { 4800, B4800 }, + { 2400, B2400 }, + { 1200, B1200 }, + { 300, B300 }, + { 75, B75 }, + { 50, B50 }, + { 0, 0 } + }, *bptr; + + if (speed) { + for (bptr = btable; bptr->speed; bptr++) + if (bptr->speed == speed) + break; + if (!bptr->baud) { + fprintf(stderr, "Cannot match selected speed %d\n", speed); + exit(1); + } + baud = bptr->baud; + } else + baud = 0; + + if (debug) + printf("using %s...\n", dev); + euid = geteuid(); + uid = getuid(); #ifdef hpux #define seteuid(a) setresuid(-1, a, -1) #endif - clocal = CLOCAL; - if (seteuid(uid)) { - perror("seteuid"); - exit(1); - } - if ((fd = open(dev, O_RDWR | O_NDELAY | O_NOCTTY, 0)) < 0) { - perror(dev); - exit(1); - } - if (seteuid(euid)) { - perror("seteuid back"); - exit(1); - } - if (debug) - printf("open done\n"); + clocal = CLOCAL; + if (seteuid(uid)) { + perror("seteuid"); + exit(1); + } + if ((fd = open(dev, O_RDWR | O_NDELAY | O_NOCTTY, 0)) < 0) { + perror(dev); + exit(1); + } + if (seteuid(euid)) { + perror("seteuid back"); + exit(1); + } + if (debug) + printf("open done\n"); #ifdef TIOCEXCL - ioctl(fd, TIOCEXCL, (char *) 0); /* additional open() calls shall fail */ + ioctl(fd, TIOCEXCL, (char *) 0); /* additional open() calls shall fail */ #else - fprintf(stderr, "WARNING: opened %s non-exclusive!\n", dev); + fprintf(stderr, "WARNING: opened %s non-exclusive!\n", dev); #endif - memset(&ti, 0, sizeof(struct termios)); + memset(&ti, 0, sizeof(struct termios)); #if defined(hpux) || defined(_IBMR2) - ti.c_cflag = CS8 | HUPCL | clocal | CREAD; + ti.c_cflag = CS8 | HUPCL | clocal | CREAD; #endif #if defined(sun) || defined(linux) || defined(__sgi) || \ defined(__NetBSD__) || defined(__FreeBSD__) - ti.c_cflag = CS8 | HUPCL | clocal | CRTSCTS | CREAD; - ti.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF; - ti.c_cc[VMIN] = 1; - ti.c_cc[VTIME] = 0; + ti.c_cflag = CS8 | HUPCL | clocal | CRTSCTS | CREAD; + ti.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF; + ti.c_cc[VMIN] = 1; + ti.c_cc[VTIME] = 0; #endif - cfsetispeed(&ti, baud); - cfsetospeed(&ti, baud); + cfsetispeed(&ti, baud); + cfsetospeed(&ti, baud); - if (tcsetattr(fd, TCSADRAIN, &ti) < 0) - perror("tcsetattr TCSADRAIN"); + if (tcsetattr(fd, TCSADRAIN, &ti) < 0) + perror("tcsetattr TCSADRAIN"); #ifdef hpux - bzero(&tx, sizeof(struct termiox)); - tx.x_hflag = RTSXOFF | CTSXON; - if (ioctl(fd, TCSETXW, &tx) < 0) - perror("TCSETXW"); + bzero(&tx, sizeof(struct termiox)); + tx.x_hflag = RTSXOFF | CTSXON; + if (ioctl(fd, TCSETXW, &tx) < 0) + perror("TCSETXW"); #endif #if defined(_IBMR2) - ioctl(fd, TXDELCD, "dtr"); - ioctl(fd, TXDELCD, "xon"); - ioctl(fd, TXADDCD, "rts"); /* That's how AIX does CRTSCTS */ + ioctl(fd, TXDELCD, "dtr"); + ioctl(fd, TXDELCD, "xon"); + ioctl(fd, TXADDCD, "rts"); /* That's how AIX does CRTSCTS */ #endif - return fd; + return fd; } void ser_exit(int fd) { - struct termios ti; - - if (tcgetattr(fd, &ti) < 0) - perror("tcgetattr"); - ti.c_cflag &= ~CRTSCTS; - if (tcsetattr(fd, TCSANOW, &ti) < 0) - perror("tcsetattr"); - (void) close(fd); + struct termios ti; + + if (tcgetattr(fd, &ti) < 0) + perror("tcgetattr"); + ti.c_cflag &= ~CRTSCTS; + if (tcsetattr(fd, TCSANOW, &ti) < 0) + perror("tcsetattr"); + (void) close(fd); } |