Skip to content

Commit 4942bce

Browse files
committed
Add fuchsia support
This change adds support for the Fuchsia operating system to the nix crate. Fuchsia developers have a use case for nix, particularly its safe interfaces to the recvmsg(2) and sendmsg(2). Adding support requires: * incrementing the libc dependency to 0.2.74 * conditionally not compiling nix functionality which depends on libc functionality that does not exist for Fuchsia
1 parent 96054b6 commit 4942bce

File tree

10 files changed

+194
-95
lines changed

10 files changed

+194
-95
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exclude = [
1717
]
1818

1919
[dependencies]
20-
libc = { version = "0.2.73", features = [ "extra_traits" ] }
20+
libc = { version = "0.2.74", features = [ "extra_traits" ] }
2121
bitflags = "1.1"
2222
cfg-if = "0.1.10"
2323

src/errno.rs

+128-64
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ cfg_if! {
3838
unsafe fn errno_location() -> *mut c_int {
3939
libc::__errno()
4040
}
41-
} else if #[cfg(any(target_os = "linux", target_os = "redox"))] {
41+
} else if #[cfg(any(target_os = "linux", target_os = "redox",
42+
target_os = "fuchsia"))] {
4243
unsafe fn errno_location() -> *mut c_int {
4344
libc::__errno_location()
4445
}
@@ -206,192 +207,254 @@ fn desc(errno: Errno) -> &'static str {
206207
EHOSTDOWN => "Host is down",
207208
EHOSTUNREACH => "No route to host",
208209

209-
#[cfg(any(target_os = "linux", target_os = "android"))]
210+
#[cfg(any(target_os = "linux", target_os = "android",
211+
target_os = "fuchsia"))]
210212
ECHRNG => "Channel number out of range",
211213

212-
#[cfg(any(target_os = "linux", target_os = "android"))]
214+
#[cfg(any(target_os = "linux", target_os = "android",
215+
target_os = "fuchsia"))]
213216
EL2NSYNC => "Level 2 not synchronized",
214217

215-
#[cfg(any(target_os = "linux", target_os = "android"))]
218+
#[cfg(any(target_os = "linux", target_os = "android",
219+
target_os = "fuchsia"))]
216220
EL3HLT => "Level 3 halted",
217221

218-
#[cfg(any(target_os = "linux", target_os = "android"))]
222+
#[cfg(any(target_os = "linux", target_os = "android",
223+
target_os = "fuchsia"))]
219224
EL3RST => "Level 3 reset",
220225

221-
#[cfg(any(target_os = "linux", target_os = "android"))]
226+
#[cfg(any(target_os = "linux", target_os = "android",
227+
target_os = "fuchsia"))]
222228
ELNRNG => "Link number out of range",
223229

224-
#[cfg(any(target_os = "linux", target_os = "android"))]
230+
#[cfg(any(target_os = "linux", target_os = "android",
231+
target_os = "fuchsia"))]
225232
EUNATCH => "Protocol driver not attached",
226233

227-
#[cfg(any(target_os = "linux", target_os = "android"))]
234+
#[cfg(any(target_os = "linux", target_os = "android",
235+
target_os = "fuchsia"))]
228236
ENOCSI => "No CSI structure available",
229237

230-
#[cfg(any(target_os = "linux", target_os = "android"))]
238+
#[cfg(any(target_os = "linux", target_os = "android",
239+
target_os = "fuchsia"))]
231240
EL2HLT => "Level 2 halted",
232241

233-
#[cfg(any(target_os = "linux", target_os = "android"))]
242+
#[cfg(any(target_os = "linux", target_os = "android",
243+
target_os = "fuchsia"))]
234244
EBADE => "Invalid exchange",
235245

236-
#[cfg(any(target_os = "linux", target_os = "android"))]
246+
#[cfg(any(target_os = "linux", target_os = "android",
247+
target_os = "fuchsia"))]
237248
EBADR => "Invalid request descriptor",
238249

239-
#[cfg(any(target_os = "linux", target_os = "android"))]
250+
#[cfg(any(target_os = "linux", target_os = "android",
251+
target_os = "fuchsia"))]
240252
EXFULL => "Exchange full",
241253

242-
#[cfg(any(target_os = "linux", target_os = "android"))]
254+
#[cfg(any(target_os = "linux", target_os = "android",
255+
target_os = "fuchsia"))]
243256
ENOANO => "No anode",
244257

245-
#[cfg(any(target_os = "linux", target_os = "android"))]
258+
#[cfg(any(target_os = "linux", target_os = "android",
259+
target_os = "fuchsia"))]
246260
EBADRQC => "Invalid request code",
247261

248-
#[cfg(any(target_os = "linux", target_os = "android"))]
262+
#[cfg(any(target_os = "linux", target_os = "android",
263+
target_os = "fuchsia"))]
249264
EBADSLT => "Invalid slot",
250265

251-
#[cfg(any(target_os = "linux", target_os = "android"))]
266+
#[cfg(any(target_os = "linux", target_os = "android",
267+
target_os = "fuchsia"))]
252268
EBFONT => "Bad font file format",
253269

254-
#[cfg(any(target_os = "linux", target_os = "android"))]
270+
#[cfg(any(target_os = "linux", target_os = "android",
271+
target_os = "fuchsia"))]
255272
ENOSTR => "Device not a stream",
256273

257-
#[cfg(any(target_os = "linux", target_os = "android"))]
274+
#[cfg(any(target_os = "linux", target_os = "android",
275+
target_os = "fuchsia"))]
258276
ENODATA => "No data available",
259277

260-
#[cfg(any(target_os = "linux", target_os = "android"))]
278+
#[cfg(any(target_os = "linux", target_os = "android",
279+
target_os = "fuchsia"))]
261280
ETIME => "Timer expired",
262281

263-
#[cfg(any(target_os = "linux", target_os = "android"))]
282+
#[cfg(any(target_os = "linux", target_os = "android",
283+
target_os = "fuchsia"))]
264284
ENOSR => "Out of streams resources",
265285

266-
#[cfg(any(target_os = "linux", target_os = "android"))]
286+
#[cfg(any(target_os = "linux", target_os = "android",
287+
target_os = "fuchsia"))]
267288
ENONET => "Machine is not on the network",
268289

269-
#[cfg(any(target_os = "linux", target_os = "android"))]
290+
#[cfg(any(target_os = "linux", target_os = "android",
291+
target_os = "fuchsia"))]
270292
ENOPKG => "Package not installed",
271293

272-
#[cfg(any(target_os = "linux", target_os = "android"))]
294+
#[cfg(any(target_os = "linux", target_os = "android",
295+
target_os = "fuchsia"))]
273296
EREMOTE => "Object is remote",
274297

275-
#[cfg(any(target_os = "linux", target_os = "android"))]
298+
#[cfg(any(target_os = "linux", target_os = "android",
299+
target_os = "fuchsia"))]
276300
ENOLINK => "Link has been severed",
277301

278-
#[cfg(any(target_os = "linux", target_os = "android"))]
302+
#[cfg(any(target_os = "linux", target_os = "android",
303+
target_os = "fuchsia"))]
279304
EADV => "Advertise error",
280305

281-
#[cfg(any(target_os = "linux", target_os = "android"))]
306+
#[cfg(any(target_os = "linux", target_os = "android",
307+
target_os = "fuchsia"))]
282308
ESRMNT => "Srmount error",
283309

284-
#[cfg(any(target_os = "linux", target_os = "android"))]
310+
#[cfg(any(target_os = "linux", target_os = "android",
311+
target_os = "fuchsia"))]
285312
ECOMM => "Communication error on send",
286313

287-
#[cfg(any(target_os = "linux", target_os = "android"))]
314+
#[cfg(any(target_os = "linux", target_os = "android",
315+
target_os = "fuchsia"))]
288316
EPROTO => "Protocol error",
289317

290-
#[cfg(any(target_os = "linux", target_os = "android"))]
318+
#[cfg(any(target_os = "linux", target_os = "android",
319+
target_os = "fuchsia"))]
291320
EMULTIHOP => "Multihop attempted",
292321

293-
#[cfg(any(target_os = "linux", target_os = "android"))]
322+
#[cfg(any(target_os = "linux", target_os = "android",
323+
target_os = "fuchsia"))]
294324
EDOTDOT => "RFS specific error",
295325

296-
#[cfg(any(target_os = "linux", target_os = "android"))]
326+
#[cfg(any(target_os = "linux", target_os = "android",
327+
target_os = "fuchsia"))]
297328
EBADMSG => "Not a data message",
298329

299-
#[cfg(any(target_os = "linux", target_os = "android"))]
330+
#[cfg(any(target_os = "linux", target_os = "android",
331+
target_os = "fuchsia"))]
300332
EOVERFLOW => "Value too large for defined data type",
301333

302-
#[cfg(any(target_os = "linux", target_os = "android"))]
334+
#[cfg(any(target_os = "linux", target_os = "android",
335+
target_os = "fuchsia"))]
303336
ENOTUNIQ => "Name not unique on network",
304337

305-
#[cfg(any(target_os = "linux", target_os = "android"))]
338+
#[cfg(any(target_os = "linux", target_os = "android",
339+
target_os = "fuchsia"))]
306340
EBADFD => "File descriptor in bad state",
307341

308-
#[cfg(any(target_os = "linux", target_os = "android"))]
342+
#[cfg(any(target_os = "linux", target_os = "android",
343+
target_os = "fuchsia"))]
309344
EREMCHG => "Remote address changed",
310345

311-
#[cfg(any(target_os = "linux", target_os = "android"))]
346+
#[cfg(any(target_os = "linux", target_os = "android",
347+
target_os = "fuchsia"))]
312348
ELIBACC => "Can not access a needed shared library",
313349

314-
#[cfg(any(target_os = "linux", target_os = "android"))]
350+
#[cfg(any(target_os = "linux", target_os = "android",
351+
target_os = "fuchsia"))]
315352
ELIBBAD => "Accessing a corrupted shared library",
316353

317-
#[cfg(any(target_os = "linux", target_os = "android"))]
354+
#[cfg(any(target_os = "linux", target_os = "android",
355+
target_os = "fuchsia"))]
318356
ELIBSCN => ".lib section in a.out corrupted",
319357

320-
#[cfg(any(target_os = "linux", target_os = "android"))]
358+
#[cfg(any(target_os = "linux", target_os = "android",
359+
target_os = "fuchsia"))]
321360
ELIBMAX => "Attempting to link in too many shared libraries",
322361

323-
#[cfg(any(target_os = "linux", target_os = "android"))]
362+
#[cfg(any(target_os = "linux", target_os = "android",
363+
target_os = "fuchsia"))]
324364
ELIBEXEC => "Cannot exec a shared library directly",
325365

326-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
366+
#[cfg(any(target_os = "linux", target_os = "android",
367+
target_os = "fuchsia", target_os = "openbsd"))]
327368
EILSEQ => "Illegal byte sequence",
328369

329-
#[cfg(any(target_os = "linux", target_os = "android"))]
370+
#[cfg(any(target_os = "linux", target_os = "android",
371+
target_os = "fuchsia"))]
330372
ERESTART => "Interrupted system call should be restarted",
331373

332-
#[cfg(any(target_os = "linux", target_os = "android"))]
374+
#[cfg(any(target_os = "linux", target_os = "android",
375+
target_os = "fuchsia"))]
333376
ESTRPIPE => "Streams pipe error",
334377

335-
#[cfg(any(target_os = "linux", target_os = "android"))]
378+
#[cfg(any(target_os = "linux", target_os = "android",
379+
target_os = "fuchsia"))]
336380
EUSERS => "Too many users",
337381

338382
#[cfg(any(target_os = "linux", target_os = "android",
339-
target_os = "netbsd", target_os = "redox"))]
383+
target_os = "fuchsia", target_os = "netbsd",
384+
target_os = "redox"))]
340385
EOPNOTSUPP => "Operation not supported on transport endpoint",
341386

342-
#[cfg(any(target_os = "linux", target_os = "android"))]
387+
#[cfg(any(target_os = "linux", target_os = "android",
388+
target_os = "fuchsia"))]
343389
ESTALE => "Stale file handle",
344390

345-
#[cfg(any(target_os = "linux", target_os = "android"))]
391+
#[cfg(any(target_os = "linux", target_os = "android",
392+
target_os = "fuchsia"))]
346393
EUCLEAN => "Structure needs cleaning",
347394

348-
#[cfg(any(target_os = "linux", target_os = "android"))]
395+
#[cfg(any(target_os = "linux", target_os = "android",
396+
target_os = "fuchsia"))]
349397
ENOTNAM => "Not a XENIX named type file",
350398

351-
#[cfg(any(target_os = "linux", target_os = "android"))]
399+
#[cfg(any(target_os = "linux", target_os = "android",
400+
target_os = "fuchsia"))]
352401
ENAVAIL => "No XENIX semaphores available",
353402

354-
#[cfg(any(target_os = "linux", target_os = "android"))]
403+
#[cfg(any(target_os = "linux", target_os = "android",
404+
target_os = "fuchsia"))]
355405
EISNAM => "Is a named type file",
356406

357-
#[cfg(any(target_os = "linux", target_os = "android"))]
407+
#[cfg(any(target_os = "linux", target_os = "android",
408+
target_os = "fuchsia"))]
358409
EREMOTEIO => "Remote I/O error",
359410

360-
#[cfg(any(target_os = "linux", target_os = "android"))]
411+
#[cfg(any(target_os = "linux", target_os = "android",
412+
target_os = "fuchsia"))]
361413
EDQUOT => "Quota exceeded",
362414

363415
#[cfg(any(target_os = "linux", target_os = "android",
364-
target_os = "openbsd", target_os = "dragonfly"))]
416+
target_os = "fuchsia", target_os = "openbsd",
417+
target_os = "dragonfly"))]
365418
ENOMEDIUM => "No medium found",
366419

367-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
420+
#[cfg(any(target_os = "linux", target_os = "android",
421+
target_os = "fuchsia", target_os = "openbsd"))]
368422
EMEDIUMTYPE => "Wrong medium type",
369423

370-
#[cfg(any(target_os = "linux", target_os = "android"))]
424+
#[cfg(any(target_os = "linux", target_os = "android",
425+
target_os = "fuchsia"))]
371426
ECANCELED => "Operation canceled",
372427

373-
#[cfg(any(target_os = "linux", target_os = "android"))]
428+
#[cfg(any(target_os = "linux", target_os = "android",
429+
target_os = "fuchsia"))]
374430
ENOKEY => "Required key not available",
375431

376-
#[cfg(any(target_os = "linux", target_os = "android"))]
432+
#[cfg(any(target_os = "linux", target_os = "android",
433+
target_os = "fuchsia"))]
377434
EKEYEXPIRED => "Key has expired",
378435

379-
#[cfg(any(target_os = "linux", target_os = "android"))]
436+
#[cfg(any(target_os = "linux", target_os = "android",
437+
target_os = "fuchsia"))]
380438
EKEYREVOKED => "Key has been revoked",
381439

382-
#[cfg(any(target_os = "linux", target_os = "android"))]
440+
#[cfg(any(target_os = "linux", target_os = "android",
441+
target_os = "fuchsia"))]
383442
EKEYREJECTED => "Key was rejected by service",
384443

385-
#[cfg(any(target_os = "linux", target_os = "android"))]
444+
#[cfg(any(target_os = "linux", target_os = "android",
445+
target_os = "fuchsia"))]
386446
EOWNERDEAD => "Owner died",
387447

388-
#[cfg(any(target_os = "linux", target_os = "android"))]
448+
#[cfg(any(target_os = "linux", target_os = "android",
449+
target_os = "fuchsia"))]
389450
ENOTRECOVERABLE => "State not recoverable",
390451

391-
#[cfg(all(target_os = "linux", not(target_arch="mips")))]
452+
#[cfg(any(all(target_os = "linux", not(target_arch="mips")),
453+
target_os = "fuchsia"))]
392454
ERFKILL => "Operation not possible due to RF-kill",
393455

394-
#[cfg(all(target_os = "linux", not(target_arch="mips")))]
456+
#[cfg(any(all(target_os = "linux", not(target_arch="mips")),
457+
target_os = "fuchsia"))]
395458
EHWPOISON => "Memory page has hardware error",
396459

397460
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
@@ -585,7 +648,8 @@ fn desc(errno: Errno) -> &'static str {
585648
}
586649
}
587650

588-
#[cfg(any(target_os = "linux", target_os = "android"))]
651+
#[cfg(any(target_os = "linux", target_os = "android",
652+
target_os = "fuchsia"))]
589653
mod consts {
590654
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
591655
#[repr(i32)]

src/features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod os {
9797
#[cfg(any(target_os = "macos", target_os = "freebsd",
9898
target_os = "dragonfly", target_os = "ios",
9999
target_os = "openbsd", target_os = "netbsd",
100-
target_os = "redox"))]
100+
target_os = "redox", target_os = "fuchsia"))]
101101
mod os {
102102
/// Check if the OS supports atomic close-on-exec for sockets
103103
pub fn socket_atomic_cloexec() -> bool {

src/pty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct OpenptyResult {
2929
///
3030
/// This is returned by `forkpty`. Note that this type does *not* implement `Drop`, so the user
3131
/// must manually close the file descriptors.
32+
#[cfg(not(target_os = "fuchsia"))]
3233
#[derive(Clone, Copy, Debug)]
3334
pub struct ForkptyResult {
3435
/// The master port in a virtual pty pair
@@ -302,6 +303,7 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
302303
/// If `winsize` is not `None`, the window size of the slave will be set to
303304
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
304305
/// terminal settings of the slave will be set to the values in `termios`.
306+
#[cfg(not(target_os = "fuchsia"))]
305307
pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>>>(
306308
winsize: T,
307309
termios: U,

0 commit comments

Comments
 (0)