This is io.c in view mode; [Download] [Up]
#import <stdio.h> #import <libc.h> void checkStatus( int fd ); int openPort( char *deviceName, int bps) { int fd; long ldisc; struct sgttyb mode; #ifdef DEBUG fprintf(stderr,"Opening <%s> at %d bps.\n", deviceName, bps); #endif if ((fd = open(deviceName, O_RDWR)) < 0) { #ifdef DEBUG fprintf(stderr,"Could not open Port <%s>.\n" "Errno = 0x%X\n",deviceName,errno); #endif perror("open"); return -1; } #ifdef DEBUG checkStatus( fd); #endif ldisc = NTTYDISC; ioctl(fd, TIOCSETD, &ldisc); /* Set "New" line discipline */ ioctl(fd, TIOCGETP, &mode); mode.sg_ispeed = mode.sg_ospeed = bps; mode.sg_flags |= RAW; mode.sg_flags &= ~ECHO; // No echoing mode.sg_flags &= ~CBREAK; // No half cocked mode mode.sg_flags &= ~CRMOD; // No remapping of CR key mode.sg_flags &= ~TANDEM; // No XON/XOFF ioctl(fd, TIOCSETP, &mode); #ifdef DEBUG checkStatus( fd); #endif return fd; } int closePort( int fd) { fprintf(stderr,"Closing Port %d.\n", fd); if ( close(fd) < 0) { fprintf(stderr, "Could not close Port, fd = %XH\n" "errno = %d\n",fd ,errno); perror("close"); return -1; } return 0; } void checkStatus( int fd ) { long int ldisc; struct sgttyb mode; fprintf(stderr,"\n\n================\n"); ioctl(fd, TIOCGETD, &ldisc); switch( ldisc ) { case OTTYDISC: fprintf(stderr, "Old tty disc in effect.\n"); break; case NTTYDISC: fprintf(stderr, "New tty disc in effect.\n"); break; case NETLDISC: fprintf(stderr, "Netl disc in effect.\n"); break; default: fprintf(stderr, "Unknown tty disc in effect.\n"); break; } ioctl(fd, TIOCGETP, &mode); fprintf(stderr, "Input speed = %d\n", mode.sg_ispeed); fprintf(stderr, "Output speed = %d\n", mode.sg_ospeed); fprintf(stderr, "Erase char = %d\n", mode.sg_erase); fprintf(stderr, "Kill char = %d\n", mode.sg_kill); fprintf(stderr, "\nLocal mode word = %08Xh\n", mode.sg_flags); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.