MCPcopy Create free account
hub / github.com/PowerShell/DSC / parse_multi_string

Function parse_multi_string

resources/windows_service/src/service.rs:39–61  ·  view source on GitHub ↗

Parse a double-null-terminated multi-string into individual strings. # Safety The pointer must point to a valid double-null-terminated buffer, or be null.

(ptr: PWSTR)

Source from the content-addressed store, hash-verified

37///
38/// The pointer must point to a valid double-null-terminated buffer, or be null.
39unsafe fn parse_multi_string(ptr: PWSTR) -> Vec<String> {
40 if ptr.is_null() {
41 return Vec::new();
42 }
43 let mut result = Vec::new();
44 let mut current = ptr.0;
45 unsafe {
46 loop {
47 if *current == 0 {
48 break;
49 }
50 let pcwstr = PCWSTR(current);
51 match pcwstr.to_string() {
52 Ok(s) => {
53 current = current.add(s.encode_utf16().count() + 1);
54 result.push(s);
55 }
56 Err(_) => break,
57 }
58 }
59 }
60 result
61}
62
63/// RAII wrapper for `SC_HANDLE` that calls `CloseServiceHandle` on drop.
64struct ScHandle(SC_HANDLE);

Callers 1

read_service_stateFunction · 0.85

Calls 1

newFunction · 0.50

Tested by

no test coverage detected