Commit b3bc9c0
committed
termios: use fcntl(F_GETPATH) for ttyname on Apple platforms
macOS's ttyname_r works by walking /dev and calling stat on each entry
to find one whose device and inode numbers match the given fd. This
directory scan can take several seconds on a typical macOS system,
causing significant latency for any Rust program that calls ttyname.
On Apple platforms, use fcntl(F_GETPATH) instead. This is a
Darwin-specific API that asks the kernel to fill a buffer with the
filesystem path for any open file descriptor in a single kernel call,
making it dramatically faster than the /dev scan.
The linux_raw backend already uses an analogous approach for the same
reason, reading the path from /proc/self/fd/<fd> instead of calling
ttyname_r. This change brings the libc backend on Apple targets to
parity with that design.
The existing fs::getpath function in the libc backend already uses
fcntl(F_GETPATH) for the same purpose on Apple targets, so this is
consistent with established patterns in the codebase.1 parent c4caf5c commit b3bc9c0
1 file changed
+32
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
524 | 556 | | |
525 | 557 | | |
526 | 558 | | |
| |||
0 commit comments