Skip to content

Commit 073cc85

Browse files
jsgfcarllerche
authored andcommitted
netbsd support
1 parent 55134d8 commit 073cc85

File tree

11 files changed

+351
-52
lines changed

11 files changed

+351
-52
lines changed

src/errno.rs

Lines changed: 244 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ unsafe fn errno_location() -> *mut c_int {
2828
__dfly_error()
2929
}
3030

31-
#[cfg(target_os = "openbsd")]
31+
#[cfg(any(target_os = "openbsd", target_os = "netbsd"))]
3232
unsafe fn errno_location() -> *mut c_int {
3333
extern { fn __errno() -> *mut c_int; }
3434
__errno()
@@ -280,7 +280,7 @@ fn desc(errno: Errno) -> &'static str {
280280
#[cfg(any(target_os = "linux", target_os = "android"))]
281281
EUSERS => "Too many users",
282282

283-
#[cfg(any(target_os = "linux", target_os = "android"))]
283+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
284284
EOPNOTSUPP => "Operation not supported on transport endpoint",
285285

286286
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -352,22 +352,22 @@ fn desc(errno: Errno) -> &'static str {
352352
#[cfg(target_os = "freebsd")]
353353
ECAPMODE => "Not permitted in capability mode",
354354

355-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
355+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
356356
ENEEDAUTH => "Need authenticator",
357357

358-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
358+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
359359
EOVERFLOW => "Value too large to be stored in data type",
360360

361-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios"))]
361+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "netbsd"))]
362362
EILSEQ => "Illegal byte sequence",
363363

364-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
364+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
365365
ENOATTR => "Attribute not found",
366366

367-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios"))]
367+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "netbsd"))]
368368
EBADMSG => "Bad message",
369369

370-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios"))]
370+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "netbsd"))]
371371
EPROTO => "Protocol error",
372372

373373
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
@@ -376,46 +376,46 @@ fn desc(errno: Errno) -> &'static str {
376376
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))]
377377
EOWNERDEAD => "Previous owner died",
378378

379-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
379+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
380380
ENOTSUP => "Operation not supported",
381381

382-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
382+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
383383
EPROCLIM => "Too many processes",
384384

385-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
385+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
386386
EUSERS => "Too many users",
387387

388-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
388+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
389389
EDQUOT => "Disc quota exceeded",
390390

391-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
391+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
392392
ESTALE => "Stale NFS file handle",
393393

394-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
394+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
395395
EREMOTE => "Too many levels of remote in path",
396396

397-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
397+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
398398
EBADRPC => "RPC struct is bad",
399399

400-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
400+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
401401
ERPCMISMATCH => "RPC version wrong",
402402

403-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
403+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
404404
EPROGUNAVAIL => "RPC prog. not avail",
405405

406-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
406+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
407407
EPROGMISMATCH => "Program version wrong",
408408

409-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
409+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
410410
EPROCUNAVAIL => "Bad procedure for program",
411411

412-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
412+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
413413
EFTYPE => "Inappropriate file type or format",
414414

415-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
415+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
416416
EAUTH => "Authentication error",
417417

418-
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd"))]
418+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
419419
ECANCELED => "Operation canceled",
420420

421421
#[cfg(any(target_os = "macos", target_os = "ios"))]
@@ -436,22 +436,22 @@ fn desc(errno: Errno) -> &'static str {
436436
#[cfg(any(target_os = "macos", target_os = "ios"))]
437437
EBADMACHO => "Malformed Macho file",
438438

439-
#[cfg(any(target_os = "macos", target_os = "ios"))]
439+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
440440
EMULTIHOP => "Reserved",
441441

442-
#[cfg(any(target_os = "macos", target_os = "ios"))]
442+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
443443
ENODATA => "No message available on STREAM",
444444

445-
#[cfg(any(target_os = "macos", target_os = "ios"))]
445+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
446446
ENOLINK => "Reserved",
447447

448-
#[cfg(any(target_os = "macos", target_os = "ios"))]
448+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
449449
ENOSR => "No STREAM resources",
450450

451-
#[cfg(any(target_os = "macos", target_os = "ios"))]
451+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
452452
ENOSTR => "Not a STREAM",
453453

454-
#[cfg(any(target_os = "macos", target_os = "ios"))]
454+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
455455
ETIME => "STREAM ioctl timeout",
456456

457457
#[cfg(any(target_os = "macos", target_os = "ios"))]
@@ -1655,6 +1655,222 @@ mod consts {
16551655
}
16561656
}
16571657

1658+
#[cfg(target_os = "netbsd")]
1659+
mod consts {
1660+
#[derive(Copy, Debug, Clone, PartialEq)]
1661+
pub enum Errno {
1662+
UnknownErrno = 0,
1663+
EPERM = 1,
1664+
ENOENT = 2,
1665+
ESRCH = 3,
1666+
EINTR = 4,
1667+
EIO = 5,
1668+
ENXIO = 6,
1669+
E2BIG = 7,
1670+
ENOEXEC = 8,
1671+
EBADF = 9,
1672+
ECHILD = 10,
1673+
EDEADLK = 11,
1674+
ENOMEM = 12,
1675+
EACCES = 13,
1676+
EFAULT = 14,
1677+
ENOTBLK = 15,
1678+
EBUSY = 16,
1679+
EEXIST = 17,
1680+
EXDEV = 18,
1681+
ENODEV = 19,
1682+
ENOTDIR = 20,
1683+
EISDIR = 21,
1684+
EINVAL = 22,
1685+
ENFILE = 23,
1686+
EMFILE = 24,
1687+
ENOTTY = 25,
1688+
ETXTBSY = 26,
1689+
EFBIG = 27,
1690+
ENOSPC = 28,
1691+
ESPIPE = 29,
1692+
EROFS = 30,
1693+
EMLINK = 31,
1694+
EPIPE = 32,
1695+
EDOM = 33,
1696+
ERANGE = 34,
1697+
EAGAIN = 35,
1698+
EINPROGRESS = 36,
1699+
EALREADY = 37,
1700+
ENOTSOCK = 38,
1701+
EDESTADDRREQ = 39,
1702+
EMSGSIZE = 40,
1703+
EPROTOTYPE = 41,
1704+
ENOPROTOOPT = 42,
1705+
EPROTONOSUPPORT = 43,
1706+
ESOCKTNOSUPPORT = 44,
1707+
EOPNOTSUPP = 45,
1708+
EPFNOSUPPORT = 46,
1709+
EAFNOSUPPORT = 47,
1710+
EADDRINUSE = 48,
1711+
EADDRNOTAVAIL = 49,
1712+
ENETDOWN = 50,
1713+
ENETUNREACH = 51,
1714+
ENETRESET = 52,
1715+
ECONNABORTED = 53,
1716+
ECONNRESET = 54,
1717+
ENOBUFS = 55,
1718+
EISCONN = 56,
1719+
ENOTCONN = 57,
1720+
ESHUTDOWN = 58,
1721+
ETOOMANYREFS = 59,
1722+
ETIMEDOUT = 60,
1723+
ECONNREFUSED = 61,
1724+
ELOOP = 62,
1725+
ENAMETOOLONG = 63,
1726+
EHOSTDOWN = 64,
1727+
EHOSTUNREACH = 65,
1728+
ENOTEMPTY = 66,
1729+
EPROCLIM = 67,
1730+
EUSERS = 68,
1731+
EDQUOT = 69,
1732+
ESTALE = 70,
1733+
EREMOTE = 71,
1734+
EBADRPC = 72,
1735+
ERPCMISMATCH = 73,
1736+
EPROGUNAVAIL = 74,
1737+
EPROGMISMATCH = 75,
1738+
EPROCUNAVAIL = 76,
1739+
ENOLCK = 77,
1740+
ENOSYS = 78,
1741+
EFTYPE = 79,
1742+
EAUTH = 80,
1743+
ENEEDAUTH = 81,
1744+
EIDRM = 82,
1745+
ENOMSG = 83,
1746+
EOVERFLOW = 84,
1747+
EILSEQ = 85,
1748+
ENOTSUP = 86,
1749+
ECANCELED = 87,
1750+
EBADMSG = 88,
1751+
ENODATA = 89,
1752+
ENOSR = 90,
1753+
ENOSTR = 91,
1754+
ETIME = 92,
1755+
ENOATTR = 93,
1756+
EMULTIHOP = 94,
1757+
ENOLINK = 95,
1758+
EPROTO = 96,
1759+
}
1760+
1761+
impl_errno!(Errno);
1762+
1763+
pub const ELAST: Errno = Errno::ENOTSUP;
1764+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1765+
1766+
pub const EL2NSYNC: Errno = Errno::UnknownErrno;
1767+
1768+
pub fn from_i32(e: i32) -> Errno {
1769+
use self::Errno::*;
1770+
1771+
match e {
1772+
0 => UnknownErrno,
1773+
1 => EPERM,
1774+
2 => ENOENT,
1775+
3 => ESRCH,
1776+
4 => EINTR,
1777+
5 => EIO,
1778+
6 => ENXIO,
1779+
7 => E2BIG,
1780+
8 => ENOEXEC,
1781+
9 => EBADF,
1782+
10 => ECHILD,
1783+
11 => EDEADLK,
1784+
12 => ENOMEM,
1785+
13 => EACCES,
1786+
14 => EFAULT,
1787+
15 => ENOTBLK,
1788+
16 => EBUSY,
1789+
17 => EEXIST,
1790+
18 => EXDEV,
1791+
19 => ENODEV,
1792+
20 => ENOTDIR,
1793+
21 => EISDIR,
1794+
22 => EINVAL,
1795+
23 => ENFILE,
1796+
24 => EMFILE,
1797+
25 => ENOTTY,
1798+
26 => ETXTBSY,
1799+
27 => EFBIG,
1800+
28 => ENOSPC,
1801+
29 => ESPIPE,
1802+
30 => EROFS,
1803+
31 => EMLINK,
1804+
32 => EPIPE,
1805+
33 => EDOM,
1806+
34 => ERANGE,
1807+
35 => EAGAIN,
1808+
36 => EINPROGRESS,
1809+
37 => EALREADY,
1810+
38 => ENOTSOCK,
1811+
39 => EDESTADDRREQ,
1812+
40 => EMSGSIZE,
1813+
41 => EPROTOTYPE,
1814+
42 => ENOPROTOOPT,
1815+
43 => EPROTONOSUPPORT,
1816+
44 => ESOCKTNOSUPPORT,
1817+
45 => EOPNOTSUPP,
1818+
46 => EPFNOSUPPORT,
1819+
47 => EAFNOSUPPORT,
1820+
48 => EADDRINUSE,
1821+
49 => EADDRNOTAVAIL,
1822+
50 => ENETDOWN,
1823+
51 => ENETUNREACH,
1824+
52 => ENETRESET,
1825+
53 => ECONNABORTED,
1826+
54 => ECONNRESET,
1827+
55 => ENOBUFS,
1828+
56 => EISCONN,
1829+
57 => ENOTCONN,
1830+
58 => ESHUTDOWN,
1831+
59 => ETOOMANYREFS,
1832+
60 => ETIMEDOUT,
1833+
61 => ECONNREFUSED,
1834+
62 => ELOOP,
1835+
63 => ENAMETOOLONG,
1836+
64 => EHOSTDOWN,
1837+
65 => EHOSTUNREACH,
1838+
66 => ENOTEMPTY,
1839+
67 => EPROCLIM,
1840+
68 => EUSERS,
1841+
69 => EDQUOT,
1842+
70 => ESTALE,
1843+
71 => EREMOTE,
1844+
72 => EBADRPC,
1845+
73 => ERPCMISMATCH,
1846+
74 => EPROGUNAVAIL,
1847+
75 => EPROGMISMATCH,
1848+
76 => EPROCUNAVAIL,
1849+
77 => ENOLCK,
1850+
78 => ENOSYS,
1851+
79 => EFTYPE,
1852+
80 => EAUTH,
1853+
81 => ENEEDAUTH,
1854+
82 => EIDRM,
1855+
83 => ENOMSG,
1856+
84 => EOVERFLOW,
1857+
85 => EILSEQ,
1858+
86 => ENOTSUP,
1859+
87 => ECANCELED,
1860+
88 => EBADMSG,
1861+
89 => ENODATA,
1862+
90 => ENOSR,
1863+
91 => ENOSTR,
1864+
92 => ETIME,
1865+
93 => ENOATTR,
1866+
94 => EMULTIHOP,
1867+
95 => ENOLINK,
1868+
96 => EPROTO,
1869+
_ => UnknownErrno,
1870+
}
1871+
}
1872+
}
1873+
16581874

16591875
#[cfg(test)]
16601876
mod test {

0 commit comments

Comments
 (0)