/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include int main() { int master, master2; int gotpty = 0; char *line; struct stat statbuf; char c; int i; /* search a free pty */ for (c = 'p'; !gotpty && c <= 's'; c++) { line = strdup("/dev/ptyXX"); line[sizeof("/dev/pty")-1] = c; line[sizeof("/dev/ptyp")-1] = '0'; if (stat(line, &statbuf) < 0) break; for (i = 0; i < 16; i++) { line[sizeof("/dev/ptyp")-1] = "0123456789abcdef"[i]; master = open(line, O_RDWR); if (master > 0) { gotpty = 1; break; } else perror(line); } } if (!gotpty) { fprintf(stderr, "all ptys in use"); exit(1); } if((master2 = dup(master)) < 0) { perror("dup"); exit(1); } close(master); if(open(line, O_RDWR) < 0) { int the_errno = errno; perror("multipy opening a pty master results in"); printf("%d\n", the_errno); exit(0); } fprintf(stderr, "pty masters may be multiply opened\n"); exit(2); }