Skip to content

Add various strcase* functions and getline #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/cloudabi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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! {
Expand Down
8 changes: 8 additions & 0 deletions src/windows/gnu.rs
Original file line number Diff line number Diff line change
@@ -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;
}
24 changes: 12 additions & 12 deletions src/windows.rs → src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 changes: 10 additions & 0 deletions src/windows/msvc.rs
Original file line number Diff line number Diff line change
@@ -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;
}