Skip to content

Commit aee584c

Browse files
committed
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...
2 parents d4b45f5 + 0942070 commit aee584c

File tree

8 files changed

+55
-12
lines changed

8 files changed

+55
-12
lines changed

ci/run-docker.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -ex
77

88
run() {
99
echo "Building docker container for target ${1}"
10+
1011
# use -f so we can use ci/ as build context
1112
docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/
1213
mkdir -p target

libc-test/build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fn main() {
2626
let openbsd = target.contains("openbsd");
2727
let rumprun = target.contains("rumprun");
2828
let solaris = target.contains("solaris");
29+
let cloudabi = target.contains("cloudabi");
30+
let redox = target.contains("redox");
2931
let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
3032
let mut cfg = ctest::TestGenerator::new();
3133

@@ -42,6 +44,8 @@ fn main() {
4244
cfg.define("_XOPEN_SOURCE", Some("700"));
4345
cfg.define("__EXTENSIONS__", None);
4446
cfg.define("_LCONV_C99", None);
47+
} else if freebsd {
48+
cfg.define("_WITH_GETLINE", None);
4549
}
4650

4751
// Android doesn't actually have in_port_t but it's much easier if we
@@ -351,6 +355,10 @@ fn main() {
351355
}
352356
}
353357

358+
if cloudabi || redox {
359+
cfg.header("strings.h");
360+
}
361+
354362
cfg.type_name(move |ty, is_struct, is_union| {
355363
match ty {
356364
// Just pass all these through, no need for a "struct" prefix

src/cloudabi/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ extern {
185185
pub fn atexit(cb: extern fn()) -> c_int;
186186
pub fn system(s: *const c_char) -> c_int;
187187
pub fn getenv(s: *const c_char) -> *mut c_char;
188+
pub fn getline (lineptr: *mut *mut c_char, n: *mut size_t,
189+
stream: *mut FILE) -> ssize_t;
188190

189191
pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
190192
pub fn strncpy(dst: *mut c_char, src: *const c_char,
@@ -201,6 +203,9 @@ extern {
201203
pub fn strdup(cs: *const c_char) -> *mut c_char;
202204
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
203205
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
206+
pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
207+
pub fn strncasecmp(s1: *const c_char, s2: *const c_char,
208+
n: size_t) -> c_int;
204209
pub fn strlen(cs: *const c_char) -> size_t;
205210
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
206211
pub fn strerror(n: c_int) -> *mut c_char;

src/redox/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ extern {
231231
pub fn strdup(cs: *const c_char) -> *mut c_char;
232232
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
233233
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
234+
pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
235+
pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
236+
pub fn strncasecmp(s1: *const c_char, s2: *const c_char,
237+
n: size_t) -> c_int;
234238
pub fn strlen(cs: *const c_char) -> size_t;
235239
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
236240
pub fn strerror(n: c_int) -> *mut c_char;

src/unix/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ extern {
476476
pub fn strdup(cs: *const c_char) -> *mut c_char;
477477
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
478478
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
479+
pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
480+
pub fn strncasecmp(s1: *const c_char, s2: *const c_char,
481+
n: size_t) -> c_int;
479482
pub fn strlen(cs: *const c_char) -> size_t;
480483
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
481484
#[cfg_attr(
@@ -1108,6 +1111,10 @@ extern {
11081111
pub fn posix_openpt(flags: ::c_int) -> ::c_int;
11091112
pub fn ptsname(fd: ::c_int) -> *mut ::c_char;
11101113
pub fn unlockpt(fd: ::c_int) -> ::c_int;
1114+
1115+
pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
1116+
pub fn getline (lineptr: *mut *mut c_char, n: *mut size_t,
1117+
stream: *mut FILE) -> ssize_t;
11111118
}
11121119

11131120
cfg_if! {

src/windows/gnu.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub const L_tmpnam: ::c_uint = 14;
2+
pub const TMP_MAX: ::c_uint = 0x7fff;
3+
4+
extern {
5+
pub fn strcasecmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int;
6+
pub fn strncasecmp(s1: *const ::c_char, s2: *const ::c_char,
7+
n: ::size_t) -> ::c_int;
8+
}

src/windows.rs renamed to src/windows/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,6 @@ pub const BUFSIZ: ::c_uint = 512;
111111
pub const FOPEN_MAX: ::c_uint = 20;
112112
pub const FILENAME_MAX: ::c_uint = 260;
113113

114-
cfg_if! {
115-
if #[cfg(all(target_env = "gnu"))] {
116-
pub const L_tmpnam: ::c_uint = 14;
117-
pub const TMP_MAX: ::c_uint = 0x7fff;
118-
} else if #[cfg(all(target_env = "msvc"))] {
119-
pub const L_tmpnam: ::c_uint = 260;
120-
pub const TMP_MAX: ::c_uint = 0x7fff_ffff;
121-
} else {
122-
// Unknown target_env
123-
}
124-
}
125-
126114
pub const O_RDONLY: ::c_int = 0;
127115
pub const O_WRONLY: ::c_int = 1;
128116
pub const O_RDWR: ::c_int = 2;
@@ -398,3 +386,15 @@ cfg_if! {
398386
}
399387
}
400388
}
389+
390+
cfg_if! {
391+
if #[cfg(all(target_env = "gnu"))] {
392+
mod gnu;
393+
pub use self::gnu::*;
394+
} else if #[cfg(all(target_env = "msvc"))] {
395+
mod msvc;
396+
pub use self::msvc::*;
397+
} else {
398+
// Unknown target_env
399+
}
400+
}

src/windows/msvc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub const L_tmpnam: ::c_uint = 260;
2+
pub const TMP_MAX: ::c_uint = 0x7fff_ffff;
3+
4+
extern {
5+
#[link_name = "_stricmp"]
6+
pub fn stricmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int;
7+
#[link_name = "_strnicmp"]
8+
pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char,
9+
n: ::size_t) -> ::c_int;
10+
}

0 commit comments

Comments
 (0)