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...
This commit is contained in:
bors 2018-11-27 01:51:49 +00:00
commit aee584c3c0
8 changed files with 55 additions and 12 deletions

View file

@ -7,6 +7,7 @@ set -ex
run() { run() {
echo "Building docker container for target ${1}" echo "Building docker container for target ${1}"
# use -f so we can use ci/ as build context # use -f so we can use ci/ as build context
docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/ docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/
mkdir -p target mkdir -p target

View file

@ -26,6 +26,8 @@ fn main() {
let openbsd = target.contains("openbsd"); let openbsd = target.contains("openbsd");
let rumprun = target.contains("rumprun"); let rumprun = target.contains("rumprun");
let solaris = target.contains("solaris"); let solaris = target.contains("solaris");
let cloudabi = target.contains("cloudabi");
let redox = target.contains("redox");
let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly; let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
let mut cfg = ctest::TestGenerator::new(); let mut cfg = ctest::TestGenerator::new();
@ -42,6 +44,8 @@ fn main() {
cfg.define("_XOPEN_SOURCE", Some("700")); cfg.define("_XOPEN_SOURCE", Some("700"));
cfg.define("__EXTENSIONS__", None); cfg.define("__EXTENSIONS__", None);
cfg.define("_LCONV_C99", 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 // 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| { cfg.type_name(move |ty, is_struct, is_union| {
match ty { match ty {
// Just pass all these through, no need for a "struct" prefix // Just pass all these through, no need for a "struct" prefix

View file

@ -185,6 +185,8 @@ extern {
pub fn atexit(cb: extern fn()) -> c_int; pub fn atexit(cb: extern fn()) -> c_int;
pub fn system(s: *const c_char) -> c_int; pub fn system(s: *const c_char) -> c_int;
pub fn getenv(s: *const c_char) -> *mut c_char; 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 strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
pub fn strncpy(dst: *mut c_char, src: *const 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 strdup(cs: *const c_char) -> *mut c_char;
pub fn strpbrk(cs: *const c_char, ct: *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 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 strlen(cs: *const c_char) -> size_t;
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
pub fn strerror(n: c_int) -> *mut c_char; pub fn strerror(n: c_int) -> *mut c_char;

View file

@ -231,6 +231,10 @@ extern {
pub fn strdup(cs: *const c_char) -> *mut c_char; 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 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 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 strlen(cs: *const c_char) -> size_t;
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
pub fn strerror(n: c_int) -> *mut c_char; pub fn strerror(n: c_int) -> *mut c_char;

View file

@ -476,6 +476,9 @@ extern {
pub fn strdup(cs: *const c_char) -> *mut c_char; 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 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 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 strlen(cs: *const c_char) -> size_t;
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
#[cfg_attr( #[cfg_attr(
@ -1108,6 +1111,10 @@ extern {
pub fn posix_openpt(flags: ::c_int) -> ::c_int; pub fn posix_openpt(flags: ::c_int) -> ::c_int;
pub fn ptsname(fd: ::c_int) -> *mut ::c_char; pub fn ptsname(fd: ::c_int) -> *mut ::c_char;
pub fn unlockpt(fd: ::c_int) -> ::c_int; 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! { cfg_if! {

8
src/windows/gnu.rs Normal file
View file

@ -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;
}

View file

@ -111,18 +111,6 @@ pub const BUFSIZ: ::c_uint = 512;
pub const FOPEN_MAX: ::c_uint = 20; pub const FOPEN_MAX: ::c_uint = 20;
pub const FILENAME_MAX: ::c_uint = 260; 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_RDONLY: ::c_int = 0;
pub const O_WRONLY: ::c_int = 1; pub const O_WRONLY: ::c_int = 1;
pub const O_RDWR: ::c_int = 2; 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
}
}

10
src/windows/msvc.rs Normal file
View file

@ -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;
}