sun_path budget
Compose a Unix domain socket path and see whether it fits under the AF_UNIX sun_path limit. 108 bytes on Linux, 104 on macOS/BSD. One byte over and bind() returns EINVAL.
Empty path. Budget is 108 bytes.
Per-segment breakdown
| # | Segment | Bytes | Cumulative |
|---|---|---|---|
| No segments yet. | |||
Presets
About
The kernel struct sockaddr_un reserves a fixed-size character array for the path. Linux and Solaris give you 108 bytes including the optional null terminator; macOS, FreeBSD, NetBSD, and OpenBSD give you 104. Compose a path one byte longer than that and bind(2) returns EINVAL from the kernel before your code ever touches the filesystem.
Whether you need the null terminator depends on the implementation. Portable code null-terminates, so the safe usable budget is budget minus one. The dashed tick on the bar marks that boundary.
Composition matters more than your single application's path. A tempdir prefix plus a tool-specific subdirectory plus a per-pid socket name plus an IPC suffix can run past 108 bytes before you write a single line of socket code. pnpm issue #12222 is the worked example that motivated this tool.
Byte length is measured in UTF-8. Multi-byte characters (Unicode in paths) count for more than their visual width. The kernel sees bytes, not codepoints.