diff options
author | bors <bors@rust-lang.org> | 2018-11-27 01:51:49 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2018-11-27 01:51:49 +0000 |
commit | aee584c3c045da388e625365e79d6a9894e1774f (patch) | |
tree | dd955bc73d19a327818343744bc36414d5b204ed | |
parent | d4b45f51ea751d9685a956b9c011698359e4cc06 (diff) | |
parent | 0942070c31eccdafebf91e5323a01ea6cf79cf4f (diff) | |
download | rust-libc-aee584c3c045da388e625365e79d6a9894e1774f.tar.gz |
Auto merge of #1130 - palfrey:strcase-various, r=alexcrichton
Add various strcase* functions and getline
Adds
* `strcasestr`
* `strcasecmp`
* `strncasecmp`
* `getline`
I *think* they're semi-universal, but shall see what CI pops up...
-rwxr-xr-x | ci/run-docker.sh | 1 | ||||
-rw-r--r-- | libc-test/build.rs | 8 | ||||
-rw-r--r-- | src/cloudabi/mod.rs | 5 | ||||
-rw-r--r-- | src/redox/mod.rs | 4 | ||||
-rw-r--r-- | src/unix/mod.rs | 7 | ||||
-rw-r--r-- | src/windows/gnu.rs | 8 | ||||
-rw-r--r-- | src/windows/mod.rs (renamed from src/windows.rs) | 24 | ||||
-rw-r--r-- | src/windows/msvc.rs | 10 |
8 files changed, 55 insertions, 12 deletions
diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 4247827f67..c656f5904d 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -7,6 +7,7 @@ set -ex run() { echo "Building docker container for target ${1}" + # use -f so we can use ci/ as build context docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/ mkdir -p target diff --git a/libc-test/build.rs b/libc-test/build.rs index ca0b7a2e00..66cef4a2d2 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -26,6 +26,8 @@ fn main() { let openbsd = target.contains("openbsd"); let rumprun = target.contains("rumprun"); let solaris = target.contains("solaris"); + let cloudabi = target.contains("cloudabi"); + let redox = target.contains("redox"); let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly; let mut cfg = ctest::TestGenerator::new(); @@ -42,6 +44,8 @@ fn main() { cfg.define("_XOPEN_SOURCE", Some("700")); cfg.define("__EXTENSIONS__", None); cfg.define("_LCONV_C99", None); + } else if freebsd { + cfg.define("_WITH_GETLINE", None); } // Android doesn't actually have in_port_t but it's much easier if we @@ -351,6 +355,10 @@ fn main() { } } + if cloudabi || redox { + cfg.header("strings.h"); + } + cfg.type_name(move |ty, is_struct, is_union| { match ty { // Just pass all these through, no need for a "struct" prefix diff --git a/src/cloudabi/mod.rs b/src/cloudabi/mod.rs index f72eeb4d24..02b7974ff4 100644 --- a/src/cloudabi/mod.rs +++ b/src/cloudabi/mod.rs @@ -185,6 +185,8 @@ extern { pub fn atexit(cb: extern fn()) -> c_int; pub fn system(s: *const c_char) -> c_int; pub fn getenv(s: *const c_char) -> *mut c_char; + pub fn getline (lineptr: *mut *mut c_char, n: *mut size_t, + stream: *mut FILE) -> ssize_t; pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; pub fn strncpy(dst: *mut c_char, src: *const c_char, @@ -201,6 +203,9 @@ extern { pub fn strdup(cs: *const c_char) -> *mut c_char; pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; + pub fn strncasecmp(s1: *const c_char, s2: *const c_char, + n: size_t) -> c_int; pub fn strlen(cs: *const c_char) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; pub fn strerror(n: c_int) -> *mut c_char; diff --git a/src/redox/mod.rs b/src/redox/mod.rs index 9870fa6dca..9f68632a0f 100644 --- a/src/redox/mod.rs +++ b/src/redox/mod.rs @@ -231,6 +231,10 @@ extern { pub fn strdup(cs: *const c_char) -> *mut c_char; pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; + pub fn strncasecmp(s1: *const c_char, s2: *const c_char, + n: size_t) -> c_int; pub fn strlen(cs: *const c_char) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; pub fn strerror(n: c_int) -> *mut c_char; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b920189703..ff9e1954bb 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -476,6 +476,9 @@ extern { pub fn strdup(cs: *const c_char) -> *mut c_char; pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; + pub fn strncasecmp(s1: *const c_char, s2: *const c_char, + n: size_t) -> c_int; pub fn strlen(cs: *const c_char) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; #[cfg_attr( @@ -1108,6 +1111,10 @@ extern { pub fn posix_openpt(flags: ::c_int) -> ::c_int; pub fn ptsname(fd: ::c_int) -> *mut ::c_char; pub fn unlockpt(fd: ::c_int) -> ::c_int; + + pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + pub fn getline (lineptr: *mut *mut c_char, n: *mut size_t, + stream: *mut FILE) -> ssize_t; } cfg_if! { diff --git a/src/windows/gnu.rs b/src/windows/gnu.rs new file mode 100644 index 0000000000..a67af15a8f --- /dev/null +++ b/src/windows/gnu.rs @@ -0,0 +1,8 @@ +pub const L_tmpnam: ::c_uint = 14; +pub const TMP_MAX: ::c_uint = 0x7fff; + +extern { + pub fn strcasecmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int; + pub fn strncasecmp(s1: *const ::c_char, s2: *const ::c_char, + n: ::size_t) -> ::c_int; +} diff --git a/src/windows.rs b/src/windows/mod.rs index 9ed89925ce..f46eb362d8 100644 --- a/src/windows.rs +++ b/src/windows/mod.rs @@ -111,18 +111,6 @@ pub const BUFSIZ: ::c_uint = 512; pub const FOPEN_MAX: ::c_uint = 20; pub const FILENAME_MAX: ::c_uint = 260; -cfg_if! { - if #[cfg(all(target_env = "gnu"))] { - pub const L_tmpnam: ::c_uint = 14; - pub const TMP_MAX: ::c_uint = 0x7fff; - } else if #[cfg(all(target_env = "msvc"))] { - pub const L_tmpnam: ::c_uint = 260; - pub const TMP_MAX: ::c_uint = 0x7fff_ffff; - } else { - // Unknown target_env - } -} - pub const O_RDONLY: ::c_int = 0; pub const O_WRONLY: ::c_int = 1; pub const O_RDWR: ::c_int = 2; @@ -398,3 +386,15 @@ cfg_if! { } } } + +cfg_if! { + if #[cfg(all(target_env = "gnu"))] { + mod gnu; + pub use self::gnu::*; + } else if #[cfg(all(target_env = "msvc"))] { + mod msvc; + pub use self::msvc::*; + } else { + // Unknown target_env + } +}
\ No newline at end of file diff --git a/src/windows/msvc.rs b/src/windows/msvc.rs new file mode 100644 index 0000000000..9e2a9b9e5d --- /dev/null +++ b/src/windows/msvc.rs @@ -0,0 +1,10 @@ +pub const L_tmpnam: ::c_uint = 260; +pub const TMP_MAX: ::c_uint = 0x7fff_ffff; + +extern { + #[link_name = "_stricmp"] + pub fn stricmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int; + #[link_name = "_strnicmp"] + pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char, + n: ::size_t) -> ::c_int; +}
\ No newline at end of file |