Skip to content

Commit

Permalink
Get compiling on Rust 1.0 beta
Browse files Browse the repository at this point in the history
Initially support this by assuming the lowest common denominator. The long
term solution is to improve the build system to allow pulling in more specific
features that are available on the target system.
  • Loading branch information
carllerche committed Apr 7, 2015
1 parent e5ae756 commit 9e93533
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 108 deletions.
3 changes: 3 additions & 0 deletions nix-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ authors = ["Carl Lerche <me@carllerche.com>"]
homepage = "https://github.com/carllerche/nix-rust"
build = "build.rs"
license = "MIT"

[dependencies]
libc = "*"
2 changes: 0 additions & 2 deletions nix-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(libc)]

extern crate libc;

use std::ffi::CString;
Expand Down
265 changes: 263 additions & 2 deletions src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use libc::c_int;
use std::num::from_i32;

pub use self::consts::*;
pub use self::consts::Errno::*;
Expand Down Expand Up @@ -57,12 +56,16 @@ macro_rules! impl_errno {
pub fn desc(self) -> &'static str {
super::desc(self)
}

pub fn from_i32(err: i32) -> Errno {
from_i32(err)
}
}
}
}

fn last() -> Errno {
from_i32(errno()).unwrap_or(UnknownErrno)
Errno::from_i32(errno())
}

fn desc(errno: Errno) -> &'static str {
Expand Down Expand Up @@ -582,6 +585,149 @@ mod consts {

pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
pub const EDEADLOCK: Errno = Errno::EDEADLK;

pub fn from_i32(e: i32) -> Errno {
use self::Errno::*;

match e {
0 => UnknownErrno,
1 => EPERM,
2 => ENOENT,
3 => ESRCH,
4 => EINTR,
5 => EIO,
6 => ENXIO,
7 => E2BIG,
8 => ENOEXEC,
9 => EBADF,
10 => ECHILD,
11 => EAGAIN,
12 => ENOMEM,
13 => EACCES,
14 => EFAULT,
15 => ENOTBLK,
16 => EBUSY,
17 => EEXIST,
18 => EXDEV,
19 => ENODEV,
20 => ENOTDIR,
21 => EISDIR,
22 => EINVAL,
23 => ENFILE,
24 => EMFILE,
25 => ENOTTY,
26 => ETXTBSY,
27 => EFBIG,
28 => ENOSPC,
29 => ESPIPE,
30 => EROFS,
31 => EMLINK,
32 => EPIPE,
33 => EDOM,
34 => ERANGE,
35 => EDEADLK,
36 => ENAMETOOLONG,
37 => ENOLCK,
38 => ENOSYS,
39 => ENOTEMPTY,
40 => ELOOP,
42 => ENOMSG,
43 => EIDRM,
44 => ECHRNG,
45 => EL2NSYNC,
46 => EL3HLT,
47 => EL3RST,
48 => ELNRNG,
49 => EUNATCH,
50 => ENOCSI,
51 => EL2HLT,
52 => EBADE,
53 => EBADR,
54 => EXFULL,
55 => ENOANO,
56 => EBADRQC,
57 => EBADSLT,
59 => EBFONT,
60 => ENOSTR,
61 => ENODATA,
62 => ETIME,
63 => ENOSR,
64 => ENONET,
65 => ENOPKG,
66 => EREMOTE,
67 => ENOLINK,
68 => EADV,
69 => ESRMNT,
70 => ECOMM,
71 => EPROTO,
72 => EMULTIHOP,
73 => EDOTDOT,
74 => EBADMSG,
75 => EOVERFLOW,
76 => ENOTUNIQ,
77 => EBADFD,
78 => EREMCHG,
79 => ELIBACC,
80 => ELIBBAD,
81 => ELIBSCN,
82 => ELIBMAX,
83 => ELIBEXEC,
84 => EILSEQ,
85 => ERESTART,
86 => ESTRPIPE,
87 => EUSERS,
88 => ENOTSOCK,
89 => EDESTADDRREQ,
90 => EMSGSIZE,
91 => EPROTOTYPE,
92 => ENOPROTOOPT,
93 => EPROTONOSUPPORT,
94 => ESOCKTNOSUPPORT,
95 => EOPNOTSUPP,
96 => EPFNOSUPPORT,
97 => EAFNOSUPPORT,
98 => EADDRINUSE,
99 => EADDRNOTAVAIL,
100 => ENETDOWN,
101 => ENETUNREACH,
102 => ENETRESET,
103 => ECONNABORTED,
104 => ECONNRESET,
105 => ENOBUFS,
106 => EISCONN,
107 => ENOTCONN,
108 => ESHUTDOWN,
109 => ETOOMANYREFS,
110 => ETIMEDOUT,
111 => ECONNREFUSED,
112 => EHOSTDOWN,
113 => EHOSTUNREACH,
114 => EALREADY,
115 => EINPROGRESS,
116 => ESTALE,
117 => EUCLEAN,
118 => ENOTNAM,
119 => ENAVAIL,
120 => EISNAM,
121 => EREMOTEIO,
122 => EDQUOT,
123 => ENOMEDIUM,
124 => EMEDIUMTYPE,
125 => ECANCELED,
126 => ENOKEY,
127 => EKEYEXPIRED,
128 => EKEYREVOKED,
129 => EKEYREJECTED,
130 => EOWNERDEAD,
131 => ENOTRECOVERABLE,

#[cfg(not(target_os = "android"))]
132 => ERFKILL,
#[cfg(not(target_os = "android"))]
133 => EHWPOISON,
_ => UnknownErrno,
}
}
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
Expand Down Expand Up @@ -704,6 +850,121 @@ mod consts {
pub const EDEADLOCK: Errno = Errno::EDEADLK;

pub const EL2NSYNC: Errno = Errno::UnknownErrno;

pub fn from_i32(e: i32) -> Errno {
use self::Errno::*;

match e {
0 => UnknownErrno,
1 => EPERM,
2 => ENOENT,
3 => ESRCH,
4 => EINTR,
5 => EIO,
6 => ENXIO,
7 => E2BIG,
8 => ENOEXEC,
9 => EBADF,
10 => ECHILD,
11 => EDEADLK,
12 => ENOMEM,
13 => EACCES,
14 => EFAULT,
15 => ENOTBLK,
16 => EBUSY,
17 => EEXIST,
18 => EXDEV,
19 => ENODEV,
20 => ENOTDIR,
21 => EISDIR,
22 => EINVAL,
23 => ENFILE,
24 => EMFILE,
25 => ENOTTY,
26 => ETXTBSY,
27 => EFBIG,
28 => ENOSPC,
29 => ESPIPE,
30 => EROFS,
31 => EMLINK,
32 => EPIPE,
33 => EDOM,
34 => ERANGE,
35 => EAGAIN,
36 => EINPROGRESS,
37 => EALREADY,
38 => ENOTSOCK,
39 => EDESTADDRREQ,
40 => EMSGSIZE,
41 => EPROTOTYPE,
42 => ENOPROTOOPT,
43 => EPROTONOSUPPORT,
44 => ESOCKTNOSUPPORT,
45 => ENOTSUP,
46 => EPFNOSUPPORT,
47 => EAFNOSUPPORT,
48 => EADDRINUSE,
49 => EADDRNOTAVAIL,
50 => ENETDOWN,
51 => ENETUNREACH,
52 => ENETRESET,
53 => ECONNABORTED,
54 => ECONNRESET,
55 => ENOBUFS,
56 => EISCONN,
57 => ENOTCONN,
58 => ESHUTDOWN,
59 => ETOOMANYREFS,
60 => ETIMEDOUT,
61 => ECONNREFUSED,
62 => ELOOP,
63 => ENAMETOOLONG,
64 => EHOSTDOWN,
65 => EHOSTUNREACH,
66 => ENOTEMPTY,
67 => EPROCLIM,
68 => EUSERS,
69 => EDQUOT,
70 => ESTALE,
71 => EREMOTE,
72 => EBADRPC,
73 => ERPCMISMATCH,
74 => EPROGUNAVAIL,
75 => EPROGMISMATCH,
76 => EPROCUNAVAIL,
77 => ENOLCK,
78 => ENOSYS,
79 => EFTYPE,
80 => EAUTH,
81 => ENEEDAUTH,
82 => EPWROFF,
83 => EDEVERR,
84 => EOVERFLOW,
85 => EBADEXEC,
86 => EBADARCH,
87 => ESHLIBVERS,
88 => EBADMACHO,
89 => ECANCELED,
90 => EIDRM,
91 => ENOMSG,
92 => EILSEQ,
93 => ENOATTR,
94 => EBADMSG,
95 => EMULTIHOP,
96 => ENODATA,
97 => ENOLINK,
98 => ENOSR,
99 => ENOSTR,
100 => EPROTO,
101 => ETIME,
102 => EOPNOTSUPP,
103 => ENOPOLICY,
104 => ENOTRECOVERABLE,
105 => EOWNERDEAD,
106 => EQFULL,
_ => UnknownErrno,
}
}
}

#[cfg(test)]
Expand Down
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
//! Modules are structured according to the C header file that they would be
//! defined in.
#![crate_name = "nix"]

#![feature(collections, core, linkage, std_misc)]
#![allow(non_camel_case_types)]

#[macro_use]
extern crate bitflags;

extern crate libc;
extern crate core;

#[cfg(test)]
extern crate nix_test as nixtest;
Expand Down Expand Up @@ -46,10 +43,8 @@ pub mod unistd;
*
*/

use std::result;
use std::ffi::AsOsStr;
use std::{ptr, result};
use std::path::{Path, PathBuf};
use std::slice::bytes;

pub type Result<T> = result::Result<T, Error>;

Expand Down Expand Up @@ -91,10 +86,14 @@ impl NixPath for [u8] {
return Err(Error::InvalidPath);
}

match self.position_elem(&0) {
match self.iter().position(|b| *b == 0) {
Some(_) => Err(Error::InvalidPath),
None => {
bytes::copy_memory(self, &mut buf);
unsafe {
// TODO: Replace with bytes::copy_memory. rust-lang/rust#24028
ptr::copy_nonoverlapping(self.as_ptr(), buf.as_mut_ptr(), self.len());
}

Ok(f(<OsStr as OsStrExt>::from_bytes(&buf[..self.len()])))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;

extern {
#[linkage = "extern_weak"]
// #[linkage = "extern_weak"]
static eventfd: *const ();
}

Expand Down
5 changes: 3 additions & 2 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ pub mod epoll;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod event;

#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod eventfd;
// Dont' support eventfd for now
// #[cfg(any(target_os = "linux", target_os = "android"))]
// pub mod eventfd;

#[cfg(not(target_os = "ios"))]
pub mod ioctl;
Expand Down
2 changes: 1 addition & 1 deletion src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use libc;
use errno::Errno;
use core::mem;
use std::mem;
use {Error, Result};

pub use libc::consts::os::posix88::{
Expand Down
Loading

0 comments on commit 9e93533

Please sign in to comment.