| | 290 | #else /* __HAIKU__ */ |
| | 291 | /* |
| | 292 | * Get a pseudo-tty. We do this by cycling through files in the |
| | 293 | * directory. The operating system will not allow us to open a master |
| | 294 | * which is already in use, so we simply go until the open succeeds. |
| | 295 | */ |
| | 296 | char ttyName[B_PATH_NAME_LENGTH]; |
| | 297 | int master = -1; |
| | 298 | DIR *dir = opendir("/dev/pt/"); |
| | 299 | if (dir != NULL) { |
| | 300 | struct dirent *dirEntry; |
| | 301 | while ((dirEntry = readdir(dir)) != NULL) { |
| | 302 | // skip '.' and '..' |
| | 303 | if (dirEntry->d_name[0] == '.') |
| | 304 | continue; |
| | 305 | |
| | 306 | char ptyName[B_PATH_NAME_LENGTH]; |
| | 307 | snprintf(ptyName, sizeof(ptyName), "/dev/pt/%s", dirEntry->d_name); |
| | 308 | |
| | 309 | master = open(ptyName, O_RDWR); |
| | 310 | if (master >= 0) { |
| | 311 | // Set the tty that corresponds to the pty we found |
| | 312 | snprintf(ttyName, sizeof(ttyName), "/dev/tt/%s", dirEntry->d_name); |
| | 313 | break; |
| | 314 | } else { |
| | 315 | // B_BUSY is a normal case |
| | 316 | if (errno != B_BUSY) |
| | 317 | fprintf(stderr, "could not open %s: %s\n", ptyName, strerror(errno)); |
| | 318 | } |
| | 319 | } |
| | 320 | closedir(dir); |
| | 321 | } |
| | 322 | #endif /* __HAIKU__ */ |