From 29b1ceab3ee715e7919f443d41858dbc89923a06 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Wed, 4 May 2016 18:24:28 +0100 Subject: [PATCH] Added strnlen function to all platforms. strnlen is used to find the length of a C string that may be lacking a terminal NUL character. Whilst it is possible to implement the equivalent functionality in rust code, it is cleaner, simpler and removes the need for duplication of tricky functionality to get right. It also makes it easier to port C code snippets to rust. Note that strnlen is not part of POSIX or C99. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 2593e3ba6bc00..2886e159daa2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,6 +232,7 @@ extern { 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 strlen(cs: *const c_char) -> size_t; + pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "strerror$UNIX2003")] pub fn strerror(n: c_int) -> *mut c_char;