static int findpty(char **slave) { int master; static fstring line; DIR *dirp; const char *dpname; #if defined(HAVE_GRANTPT) /* Try to open /dev/ptmx. If that fails, fall through to old method. */ if ((master = sys_open("/dev/ptmx", O_RDWR, 0)) >= 0) { grantpt(master); unlockpt(master); *slave = (char *)ptsname(master); if (*slave == NULL) { DEBUG(0, ("findpty: Unable to create master/slave pty pair.\n")); /* Stop fd leak on error. */ close(master); return -1; } else { DEBUG(10, ("findpty: Allocated slave pty %s\n", *slave)); return (master); } } #endif /* HAVE_GRANTPT */ fstrcpy(line, "/dev/ptyXX"); dirp = opendir("/dev"); if (!dirp) return (-1); while ((dpname = readdirname(dirp)) != NULL) { if (strncmp(dpname, "pty", 3) == 0 && strlen(dpname) == 5) { DEBUG(3, ("pty: try to open %s, line was %s\n", dpname, line)); line[8] = dpname[3]; line[9] = dpname[4]; if ((master = sys_open(line, O_RDWR, 0)) >= 0) { DEBUG(3, ("pty: opened %s\n", line)); line[5] = 't'; *slave = line; closedir(dirp); return (master); } } } closedir(dirp); return (-1); }
char *dos_readdirname(DIR *p) { char *dname = readdirname(p); if (!dname) return(NULL); unix_to_dos(dname, True); return(dname); }
static int findpty(char **slave) { int master = -1; char *line = NULL; DIR *dirp = NULL; const char *dpname; *slave = NULL; #if defined(HAVE_GRANTPT) #if defined(HAVE_POSIX_OPENPT) master = posix_openpt(O_RDWR|O_NOCTTY); #else /* Try to open /dev/ptmx. If that fails, fall through to old method. */ master = open("/dev/ptmx", O_RDWR, 0); #endif if (master >= 0) { grantpt(master); unlockpt(master); line = (char *)ptsname(master); if (line) { *slave = SMB_STRDUP(line); } if (*slave == NULL) { DEBUG(0, ("findpty: Unable to create master/slave pty pair.\n")); /* Stop fd leak on error. */ close(master); return -1; } else { DEBUG(10, ("findpty: Allocated slave pty %s\n", *slave)); return (master); } } #endif /* HAVE_GRANTPT */ line = SMB_STRDUP("/dev/ptyXX"); if (!line) { return (-1); } dirp = opendir("/dev"); if (!dirp) { SAFE_FREE(line); return (-1); } while ((dpname = readdirname(dirp)) != NULL) { if (strncmp(dpname, "pty", 3) == 0 && strlen(dpname) == 5) { DEBUG(3, ("pty: try to open %s, line was %s\n", dpname, line)); line[8] = dpname[3]; line[9] = dpname[4]; if ((master = open(line, O_RDWR, 0)) >= 0) { DEBUG(3, ("pty: opened %s\n", line)); line[5] = 't'; *slave = line; closedir(dirp); return (master); } } } closedir(dirp); SAFE_FREE(line); return (-1); }