#include #include #include #include #include #include #ifndef O_NOCTTY #define O_NOCTTY 0 #endif extern const char *__progname; static int ttyfd; static void usage(void) { fprintf(stderr,"Usage: %s [tty] 0|1 (uses stdout if no tty specified)\n",__progname); exit(1); } int main(int, char **); int main(int ac, char **av) { int ioc; const char *arg; const char *iocname; switch (ac) { default: usage(); break; case 2: ttyfd = 1; arg = av[1]; break; case 3: ttyfd = open(av[1],O_RDWR|O_NDELAY|O_NOCTTY,0); if (ttyfd < 0) { fprintf(stderr,"%s: %s: %s\n",__progname,av[1],strerror(errno)); exit(1); } arg = av[2]; break; } if (!strcmp(arg,"0")) { ioc = TIOCCDTR; iocname = "TIOCCDTR"; } else if (!strcmp(arg,"1")) { ioc = TIOCSDTR; iocname = "TIOCSDTR"; } else { usage(); } if (ioctl(ttyfd,ioc,0) < 0) { fprintf(stderr,"%s: %s: %s\n",__progname,iocname,strerror(errno)); exit(1); } exit(0); }