Skip to content

Commit 8bb5292

Browse files
committed
---
yaml --- r: 80883 b: refs/heads/try c: daf4974 h: refs/heads/master i: 80881: 4b30bb1 80879: 833ae12 v: v3
1 parent 38d2246 commit 8bb5292

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
5-
refs/heads/try: b49fc4cf4eb7299a08d83ed8880d1002ecef9257
5+
refs/heads/try: daf497462844a55678e12545114bcc75d5ce8ebc
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/os.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,7 @@ pub fn env() -> ~[(~str,~str)] {
196196
if (ch as uint == 0) {
197197
fail!("os::env() failure getting env string from OS: %s", os::last_os_error());
198198
}
199-
let mut curr_ptr: uint = ch as uint;
200-
let mut result = ~[];
201-
while(*(curr_ptr as *libc::c_char) != 0 as libc::c_char) {
202-
let env_pair = str::raw::from_c_str(
203-
curr_ptr as *libc::c_char);
204-
result.push(env_pair);
205-
curr_ptr +=
206-
libc::strlen(curr_ptr as *libc::c_char) as uint
207-
+ 1;
208-
}
199+
result = unsafe { str::raw::from_c_multistring(ch as *libc::c_char) };
209200
FreeEnvironmentStringsA(ch);
210201
result
211202
}

branches/try/src/libstd/str.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,25 @@ pub mod raw {
10911091
vec::raw::set_len(as_owned_vec(s), new_len)
10921092
}
10931093

1094+
/// Parses a C "multistring", eg windows env values or
1095+
/// the req->ptr result in a uv_fs_readdir() call
1096+
#[inline]
1097+
pub unsafe fn from_c_multistring(c: *libc::c_char) -> ~[~str] {
1098+
#[fixed_stack_segment]; #[inline(never)];
1099+
1100+
let mut curr_ptr: uint = c as uint;
1101+
let mut result = ~[];
1102+
while(*(curr_ptr as *libc::c_char) != 0 as libc::c_char) {
1103+
let env_pair = from_c_str(
1104+
curr_ptr as *libc::c_char);
1105+
result.push(env_pair);
1106+
curr_ptr +=
1107+
libc::strlen(curr_ptr as *libc::c_char) as uint
1108+
+ 1;
1109+
}
1110+
result
1111+
}
1112+
10941113
/// Sets the length of a string
10951114
///
10961115
/// This will explicitly set the size of the string, without actually
@@ -1106,6 +1125,24 @@ pub mod raw {
11061125
}
11071126
}
11081127
1128+
#[test]
1129+
fn test_str_multistring_parsing() {
1130+
unsafe {
1131+
let input = bytes!("zero", "\x00", "one", "\x00", "\x00");
1132+
let ptr = vec::raw::to_ptr(input);
1133+
let mut result = from_c_multistring(ptr as *libc::c_char);
1134+
assert!(result.len() == 2);
1135+
let mut ctr = 0;
1136+
for x in result.iter() {
1137+
match ctr {
1138+
0 => assert_eq!(x, &~"zero"),
1139+
1 => assert_eq!(x, &~"one"),
1140+
_ => fail!("shouldn't happen!")
1141+
}
1142+
ctr += 1;
1143+
}
1144+
}
1145+
}
11091146
}
11101147
11111148
/*

0 commit comments

Comments
 (0)