Skip to content

Commit ac75250

Browse files
committed
Auto merge of rust-lang#277 - lemonrock:strnlen, r=alexcrichton
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. In my case, it's needed for dealing with the result of `gethostname`. Note that strnlen is not part of POSIX or C99, but is present on all major platforms.
2 parents 39f03ea + 29b1cea commit ac75250

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ extern {
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;
234234
pub fn strlen(cs: *const c_char) -> size_t;
235+
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
235236
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
236237
link_name = "strerror$UNIX2003")]
237238
pub fn strerror(n: c_int) -> *mut c_char;

0 commit comments

Comments
 (0)